FyroxEngine / Fyrox

3D and 2D game engine written in Rust
https://fyrox.rs
MIT License
7.48k stars 339 forks source link

Preventing TextBox and NumericUpDown from sending change messages when they have not really changed. #639

Closed b-guild closed 2 months ago

b-guild commented 2 months ago

Tabbing through an inspector should not cause the inspected object to change. To prevent this, I have created TextCommitMode::Changed which causes a record to be kept of the previous value of the field and refuses to acknowledge any editing to the field unless the result is different from the previous value.

I have modified the String property editor and ImmutableString property editor to use the new commit mode. I have also modified NumericUpDown to use the new commit mode, and modified the way that NumericUpDown parses its text to ensure that if the parsed value of the text does not change, then no change is acknowledged. This means that changing the number of 0s after the decimal point can never accidentally trigger an unwanted change in the value.

NumericUpDown was manually handling Enter-presses and Unfocus-messages rather than using the Text-message from the TextBox in order to detect changes in the text. This undermined the point of setting a TextCommitMode, so I changed NumericUpDown so that it allows its TextBox to decide when it has changed, and checks that the message has not been handled in order to avoid responding to changes that it sends to the TextBox.

I made it so that pressing Enter in a TextBox does not cause it to become unfocused. That would be awkward when using tab navigation.