Try to find text targets in tester::recorder

This commit is contained in:
Héctor Ramón Jiménez 2025-08-23 06:37:02 +02:00
parent 81d1eda7fe
commit 1923d1db1e
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
5 changed files with 245 additions and 59 deletions

View file

@ -8,6 +8,7 @@ mod find;
pub use find::{Find, FindAll};
pub use target::Target;
use crate::core::Point;
use crate::core::widget::Id;
pub trait Selector {
@ -116,6 +117,21 @@ impl Selector for Id {
}
}
impl Selector for Point {
type Output = target::Match;
fn select(&mut self, target: Target<'_>) -> Option<Self::Output> {
target
.visible_bounds()
.is_some_and(|visible_bounds| visible_bounds.contains(*self))
.then(|| target::Match::from_target(target))
}
fn description(&self) -> String {
format!("bounds contains {:?}", self)
}
}
impl<F, T> Selector for F
where
F: FnMut(Target<'_>) -> Option<T>,

View file

@ -68,6 +68,17 @@ impl<'a> Target<'a> {
| Target::Custom { bounds, .. } => *bounds,
}
}
pub fn visible_bounds(&self) -> Option<Rectangle> {
match self {
Target::Container { visible_bounds, .. }
| Target::Focusable { visible_bounds, .. }
| Target::Scrollable { visible_bounds, .. }
| Target::TextInput { visible_bounds, .. }
| Target::Text { visible_bounds, .. }
| Target::Custom { visible_bounds, .. } => *visible_bounds,
}
}
}
#[derive(Debug, Clone, PartialEq)]
@ -93,6 +104,7 @@ pub enum Match {
id: Option<Id>,
bounds: Rectangle,
visible_bounds: Option<Rectangle>,
content: String,
},
Text {
id: Option<Id>,
@ -147,11 +159,12 @@ impl Match {
id,
bounds,
visible_bounds,
..
state,
} => Self::TextInput {
id: id.cloned(),
bounds,
visible_bounds,
content: state.text().to_owned(),
},
Target::Text {
id,