runtime: Handle widget operations in program::State helper#1913
runtime: Handle widget operations in program::State helper#1913hecrj merged 3 commits intoiced-rs:masterfrom
program::State helper#1913Conversation
|
There was a problem hiding this comment.
I think it'd make more sense to introduce an operate method to State. Did you consider this approach?
The current approach here doesn't properly leverage type-safety. The actions are filtered, but the user will still have to match on Action::Widget anyways.
dd34591 to
4b831a9
Compare
Thanks for the feedback. I did, but felt like the slim api of I changed the PR to add an Is this more to your liking? |
hecrj
left a comment
There was a problem hiding this comment.
Yup! That's better!
Thank you 🙇
This handles widget operations in the
State-helper. As far as I am aware the shell/window-integrations all use theUserInterface-type directly, while theState-helper was initially conceived for foreign integrations, like the previously existingintegration_openglandintegration_wgpuexamples.It seems like it hasn't gotten a lot of attention recently, although it is quite convenient for smaller integrations. (I am using this type in
cosmic-compto render parts of the shell with iced.)Given
Stateis mostly a convenience type around theUserInterfacebuilding block and hides that behind it's api, so there is no way to callUserInterface::operatefrom the outside. Additionally it returnsCommands created by the Widget-Tree unprocessed.Any
Actions::Widget-variants derived from theseCommands containingOperations are thus never processed by the internalUserInterfaceand cannot be passed in from the outside.This PR fixes this short-coming and thus makes the
State-helper more useful for integrations. I opted to handle this inside the helper, given that the only sensible thing to do with aCommandis to convert it intoActions anyway (from my limited understanding). Additionally this keeps theStateapi quite simple (as was intended?).As such
State::updatenow filtersActions for widget operations and sends those back into theUserInterfacebefore returning the rest in a similar vain to the commands previously.I know I have skipped reaching out or opening an RFC, but I have no problem with this PR being rejected, if another way to solve this is preferred. It was a relatively small and easy change and quick to prototype.
I hope to get some discussion on how to best fix this limitation started. I am happy to solve this a different, e.g. if it would be preferred to add a
operate-function to theState-type instead or make it possible to access the internalCache/UserInterface.Alternatively
Statecould be dropped if not deemed useful enough any more, but for strongly advocate for keeping it for simpler integrations. It is a pretty nice api apart from this limitation. :)