runtime: Handle widget operations in program::State
helper
#1913
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_opengl
andintegration_wgpu
examples.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-comp
to render parts of the shell with iced.)Given
State
is mostly a convenience type around theUserInterface
building block and hides that behind it's api, so there is no way to callUserInterface::operate
from the outside. Additionally it returnsCommand
s created by the Widget-Tree unprocessed.Any
Actions::Widget
-variants derived from theseCommand
s containingOperation
s are thus never processed by the internalUserInterface
and 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 aCommand
is to convert it intoAction
s anyway (from my limited understanding). Additionally this keeps theState
api quite simple (as was intended?).As such
State::update
now filtersAction
s for widget operations and sends those back into theUserInterface
before 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
State
could 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. :)