Add id helper to selector module

This commit is contained in:
Héctor Ramón Jiménez 2025-09-11 06:24:13 +02:00
parent bc9951f84f
commit c70ce5af89
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 9 additions and 4 deletions

View file

@ -9,7 +9,7 @@ pub use find::{Find, FindAll};
pub use target::Target;
use crate::core::Point;
use crate::core::widget::Id;
use crate::core::widget;
pub trait Selector {
type Output;
@ -79,7 +79,7 @@ impl Selector for String {
}
}
impl Selector for Id {
impl Selector for widget::Id {
type Output = target::Match;
fn select(&mut self, target: Target<'_>) -> Option<Self::Output> {
@ -124,3 +124,8 @@ where
format!("custom selector: {}", std::any::type_name_of_val(self))
}
}
/// Creates a new [`Selector`] that matches widgets with the given [`widget::Id`].
pub fn id(id: impl Into<widget::Id>) -> impl Selector<Output = target::Match> {
id.into()
}