Implement is_focused selector and unify selector API
This commit is contained in:
parent
645643bfd6
commit
1ae3b5e96a
3 changed files with 48 additions and 24 deletions
|
|
@ -146,3 +146,28 @@ where
|
|||
pub fn id(id: impl Into<widget::Id>) -> impl Selector<Output = Target> {
|
||||
id.into()
|
||||
}
|
||||
|
||||
/// Returns a [`Selector`] that matches widgets that are currently focused.
|
||||
pub fn is_focused() -> impl Selector<Output = Target> {
|
||||
struct IsFocused;
|
||||
|
||||
impl Selector for IsFocused {
|
||||
type Output = Target;
|
||||
|
||||
fn select(&mut self, candidate: Candidate<'_>) -> Option<Self::Output> {
|
||||
if let Candidate::Focusable { state, .. } = candidate
|
||||
&& state.is_focused()
|
||||
{
|
||||
Some(Target::from(candidate))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn description(&self) -> String {
|
||||
"is focused".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
IsFocused
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue