Replies: 2 comments 3 replies
-
Do you have a demo project somewhere I can play around with? It is so much easier to find problems when you can actually see the effects. I understood that you have a set of "button data" in a model and then create a set of buttons from that. You propagate a field of that button data up to the root element and pass it to rust in a callback. Rust will then replace the matching line in the model with new data, incl. the field you passed up. That same field is also used to influence the color of the button somehow. I do not understand how that is done though. The problem is that while the field changes, the color does not update?
Removing/re-adding the row will create a fresh Button, while changing the data in an existing field should just cause the data to be updated in the existing button. So this looks a bit like you are changing the binding after the fact, maybe from the rust side or from code around the callout to rust? What exactly do you do there? |
Beta Was this translation helpful? Give feedback.
-
Yes, that's what I did in the "Data-Item change" buttons there. The issue with that solution that I can't do that from within the PushButton code, only from its container who has access and is aware of the button-data. So I can't have state related functionality inside the button and the container has to cooperate with that. I think there are cases where this is painful, need the container implement logic that should be inside the controls. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, In my app I have a set of buttons generated base on a rust
VecModel
ofButtonData struct
, as follows:The
state
property drives the color of the button.The button also triggers a callback event which is propogated up to the MainWindow and is handled by rust code.
I've built the callback so that rust can return
button_state
, and the button modifies its own state property based on the return value of the callback as follows (from the button's code).This is working. However it also causes problems later on.
If I later modify the a button's ButtonData in the
VecModel
from rust (usingset_row_data
), after the callback changed it's state property, the button's state property arriving from rust doesn't affect the button's color. Other properties, such as button's text, are being altered as expected. It's as if that property got 'disconnected' from the struct data.The only way I could find to fix that is to remove the button from the
VecModel
and immediately add a replacement back again, and then it appear to have 'refreshed' the button properties connection to the button (probably because that caused for removal and addition of buttons, maybe full rebuild of all buttons).Even creating a new button object in rust and setting the row data to the newly created button struct wasn't enough.
So I wanted to ask:
And another related behavior:
I tried changing the struct state field from slint by changing the top piece of code to change the struct data based on the event return value (instead of in the button):
That worked, but it had another side effect.
Prior to this change, in rust, inside the callback handler, I used
set_row_data
to the change the text, and it worked.Now, with this added that change of text didn't take effect, as if altering the button-data here forced using the old button-data.
Beta Was this translation helpful? Give feedback.
All reactions