iced_runtime/widget/
selector.rs

1//! Find and query widgets in your applications.
2pub use iced_selector::{Bounded, Candidate, Selector, Target, Text};
3
4use crate::core::Rectangle;
5
6use crate::Task;
7use crate::core::widget;
8use crate::task;
9
10/// Finds a widget by the given [`widget::Id`].
11pub fn find_by_id(id: impl Into<widget::Id>) -> Task<Option<Target>> {
12    task::widget(id.into().find())
13}
14
15/// Finds a widget that contains the given text.
16pub fn find_by_text(text: impl Into<String>) -> Task<Option<Text>> {
17    task::widget(Selector::find(text.into()))
18}
19
20/// Finds the visible bounds of the first [`Selector`] target.
21pub fn delineate<S>(selector: S) -> Task<Option<Rectangle>>
22where
23    S: Selector + Send + 'static,
24    S::Output: Bounded + Clone + Send + 'static,
25{
26    task::widget(selector.find())
27        .map(|target| target.as_ref().and_then(Bounded::visible_bounds))
28}