-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
operation::focusable::is_focused
& text_input::is_focused
#2812
Conversation
…used state of a `focusable` by ID. Add `is_focused` function that produces a `Task` to get the focused state of a `text_input` by ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Looking good! Just a couple nits.
_bounds: Rectangle, | ||
operate_on_children: &mut dyn FnMut(&mut dyn Operation<bool>), | ||
) { | ||
operate_on_children(self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably stop traversing the widget tree if self.is_focused
is already Some
:
operate_on_children(self); | |
if self.is_focused.is_some() { | |
return; | |
} | |
operate_on_children(self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion! Makes sense to me. Outside the scope of this PR probably, but would it make sense to similarly stop traversing once a result is found for find_focused
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, both nits should apply there as well.
if let Some(is_focused) = &self.is_focused { | ||
Outcome::Some(*is_focused) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since bool
is copy, we can avoid the dereference:
if let Some(is_focused) = &self.is_focused { | |
Outcome::Some(*is_focused) | |
if let Some(is_focused) = self.is_focused { | |
Outcome::Some(is_focused) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe even something functional like:
self.is_focused.map_or(Outcome::None, Outcome::Some)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Thanks!
This PR consists of two additions:
is_focused
function that produces anOperation
that looks for afocusable
widget by ID, and produces abool
that stores whether the widget is focused or not. This function was modeled after the existingfind_focused
, and for my purposes was a means to implement the second addition.is_focused
function that produces aTask
that looks for atext_input
widget by ID, and produces abool
with whether the widget is focused or not.Originally I tried to use the
find_focused
Operation
fortext_input::is_focused
, but I couldn't figure out how to make it work as desired when there is no currently focused widget (andfind_focused
producesOutcome::None
).