Fix crash from overflowing values given to NumberInput widgets (#1377)

* Added hints for brush tool size

* Added hints for brush tool size

* Solved the user being able to crash the editor by overflowing NumberInputs
This commit is contained in:
Omar Magdy
2023-08-11 12:26:37 -07:00
committed by Keavon Chambers
parent 1c11ebcc4e
commit fd338c945f
16 changed files with 47 additions and 4 deletions
@@ -183,7 +183,7 @@ impl<F: Fn(&MessageDiscriminant) -> Vec<KeysGroup>> MessageHandler<LayoutMessage
panic!("Invalid string found when updating `NumberInput`")
}
},
_ => panic!("Invalid type found when updating `NumberInput`"),
_ => {} // If it's some other type we could just ignore it and leave the value as is
},
Widget::OptionalInput(optional_input) => {
let update_value = value.as_bool().expect("OptionalInput update was not of type: bool");
@@ -273,7 +273,6 @@ impl NumberInput {
pub fn max(mut self, val: f64) -> Self {
self.max = Some(val);
self.range_max = Some(val);
self.mode = NumberInputMode::Range;
self
}
pub fn mode_range(mut self) -> Self {
@@ -289,7 +288,7 @@ impl NumberInput {
self
}
pub fn percentage(self) -> Self {
self.min(0.).max(100.).unit("%").display_decimal_places(2)
self.min(0.).max(100.).mode_range().unit("%").display_decimal_places(2)
}
}