Try to find text targets in tester::recorder
This commit is contained in:
parent
81d1eda7fe
commit
1923d1db1e
5 changed files with 245 additions and 59 deletions
|
|
@ -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>,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue