slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

SpinBox: value property sometimes fails to propagate to internal `TextInput` #3053

Closed nununoisy closed 5 months ago

nununoisy commented 1 year ago

When binding a SpinBox's value to a property, then updating the property from outside of the SpinBox, the internal TextInput's value is not updated in certain circumstances. I've experimented with the issue a bunch and I believe that the issue manifests when the value is updated from within the SpinBox, though I'm unsure if there are any other triggers.

Here are the steps I've found to reproduce the issue (you can follow along with this SlintPad MRE):

  1. Create a SpinBox with a binding to an integer property and some way for that property to be updated, either from another component or from native code.
  2. Try updating the value externally (click one of the 3 buttons on the MRE) and notice that the value changes as expected.
  3. Update the value using the SpinBox, either by editing the text input or by clicking one of the stepper buttons.
  4. Try updating the value externally and notice that the value no longer updates.
  5. Click a stepper button and notice that the SpinBox acts as though its value is what it had been externally updated to. This shows that the value within the SpinBox is indeed changing, but the TextInput is not receiving the new value.

I can reproduce this on the Qt backend (Qt 6, rust MSVC 1.70 stable, Windows 10 22H2 & Qt 5, rust GNU 1.70 stable, Debian 11 on WSL2) and the web backend (SlintPad).

Looking through the implementation for the Fluent-styled SpinBox, it seems that the issue stems from the way that the TextInput's text prop is updated. Whenever the value is updated from within the SpinBox, update-text() is called to update the TextInput to match. However, when this is done, it seems as though some link between root.value and i-text-input.text is removed; perhaps i-text-input.text is set to a constant equivalent to whatever root.value was at the time?

I unfortunately don't know enough about Slint to suggest a good fix for this. My instinct would be to publicize the update-value(int) function but it would be rather weird for one singular standard component to require value updates to be performed through a function.

FloVanGH commented 1 year ago

I have a fix for this issue but from my perspective it make sense to merge #3096 first.

FloVanGH commented 1 year ago

PR #3101 should fixes the issue for material and fluent SpinBox. For the native SpinBox more work needs to been done, because it lacks an TextInput element in the moment. That will be done next.

qarmin commented 11 months ago

I still can reproduce problem with fluent spinbox - code

https://github.com/slint-ui/slint/assets/41945903/bcfe5f2e-db4c-43f6-b4e4-627c95d8225e

FloVanGH commented 9 months ago

needs #112

JuliDi commented 7 months ago

Is there any workaround for forcing an update on the UI until #112 is implemented? I would like to have a "Reset" button for a SpinBox, but the number in the SpinBox is not updated.