pick_list
s all take in an optional selected
, but after selecting an option, there is no way to revert it back to None
in the list. Is this intended? And if so, is this always the behavior, or can I make it so that it is selectable?
None
selected variant of pick list means that there is no selected variant and it’s a bit odd to pick the variant which removes any selection, IMO.
But in your case, I think, you have some various options
- If you use enum as a variant you may add the
None
variant into it and your pick_list always will have selected variant - You may separate “variant” and “message”: add some variant representing
None
and map it into message which removes value while updating - Do it outside the
PickList
by some button or something that sends message which clears PickList state when handling
My use case is that I have a gui for editing some json files, where a field can be one of several strings or null. So being able to select the None option is very useful because then it requires no extra work to make serde serialize as null. So I just wanted to check I wasn’t missing something before trying to work around it. Thanks
Hi,
You can basically copy iced’s pick_list widget and adapt it so it support None option.
I had a similar need which I’m linking it to you in case you have 0 no idea how to do it. I don’t remember if it’s the version that had a bug on the hover of last item or not tho.
On this repo you can find an example for iced 0.13 (I’m not 100% sure it’s bug free, I don’t remember if I fixed it before migrating on iced git on my local):
https://gitlab.com/mytdragon/gamelibrary_rs/-/blob/5e95208c27d472d2c20262ec8bb8541d9cf4917c/iced/src/widget/pick_list.rs
https://gitlab.com/mytdragon/gamelibrary_rs/-/blob/5e95208c27d472d2c20262ec8bb8541d9cf4917c/iced/src/widget/overlay/menu.rs
You will find the version for iced git (not last rev tho) on the main branch.
Note that it also contains a pick list that support multiple selection state (like included or excluded selection) if someone come across this post and need something like that.
I believe sweeten has such a widget.