ComboRow does not use selection binding #28
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: aparoksha/adwaita-swift#28
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Describe the bug
Hello there, thank you very much for putting this library together. It has rekindled my interest in GTK development (gtk-rs is pretty rough, and I refuse to use dynamic languages so not many other options out there…) and made me start learning Swift, which is truly a great language, too bad Linux support is not on par with macOS, but it seems to be getting better and better.
Now for the issue itself. It seems like ComboRow does not use the selection binding as such the first item in the list is the one that is always selected. To be clear, using the combo row correctly changes and updates the selection binding but upon revisiting a menu the selection although correct is not used and the ComboRow just pre-selects the top item. I tried using both
selection
binding and theselected
function to force set the correct item, but it does not make any difference.Using different starting values for other widgets such as SpinRow and SwitchRow correctly uses the binding.
For example (samples from your FormDemo):
Note the selection value is correct, so the subtitle is set to "World"
I am not sure if this is expected behaviour but if not there is something wrong with ComboRows. If this is indeed expected behaviour are there any workarounds for the ComboRow to remember its selection?
Thank you for your support!
PS: I have some other questions/issues, but I will open separate issue/discussion for them ;)
To Reproduce
selection
state variable to change the ComboRow's initial value from Hello to WorldExpected behavior
The ComboRow should correctly pre-select the value indicated by the selection binding and not the top item from the value list. For example if I have a ComboRow with values 1,2,3,4,5, and I select value 4, I want value 4 to be pre-selected with a checkmark when I close and revisit the view holding the ComboRow.
Additional context
Edit1: Upon further testing, seems like even the widgets that use the correct starting value do not remember their new value on consecutive visits. For example if I create a SpinRow inside a menu, set its initial value to 3 and open the menu then its value is 3 but changing it will not be reflected if I close and re-open the menu, its value will be set to its initial 3.
Maybe is because I try to use the widgets inside separate dialogs like menus, preferences and not the main window? Not sure.
Edit2: I tried sending the
value
to the menu holding the SpinRow as a @Binding (instead of directly using @State in the menu) and then it correctly remembers its value upon consecutive visits. The issue still persists with ComboRows. Using a similar approach the ComboRow never remembers its value and always pre-selects the top item.The bug is caused by
ComboRow
initializing the selection before the choices (I'll fix that).Currently, only apps and views support state. I'll expand this to menus.
Thanks for the detailed writing!
What do you mean by a menu in this context?
Anyways, yes,
State
only saves state from the creation of the view until it is "destroyed". Depending on what you mean by the menu, it does redraw the UI when navigating. State that should be saved even though a view is destroyed and recreated should be saved in its parent view.Sorry for not being clearer, I meant exactly what you have described in the comment above. Basically a child view that uses @State which gets destroyed when exited, so things like menus, extra dialogs etc. I figured out that to maintain the state then I need to move it to the parent view so no worries.
Thank you for confirming the bug and taking the time to fix it! 🙏
So the
ComboRow
bug is fixed, I'll now add support for state in menus.Hello @david-swift I can confirm that the ComboRow bug is now fixed, thanks for that!
I am not sure if the new commit caused a regression, but now I am having issues with ListBox selection. Setting an initial selection value is causing a crush. Weird thing is that if the initial view being presented is the one containing the ListBox then it works as expected but if you are navigating from a different view then it crushes.
To reproduce:
Now if you restart the app it will work as expected since ListDemo will be the first view that will be active.
Maybe it is something on my end, so I will keep looking into it.
@lambdaclan Thanks for reporting! I fixed this in
c07b071
.Hello @david-swift, thank you very much for looking into the issue and fixing it, I can now continue working on my app ;)