2025-08-23 05:15:57 +02:00
|
|
|
//! Find and query widgets in your applications.
|
|
|
|
|
pub use iced_selector::Selector;
|
|
|
|
|
|
|
|
|
|
pub use iced_selector::target::{Bounded, Match, Target, Text};
|
|
|
|
|
|
2025-08-27 10:54:53 +02:00
|
|
|
use crate::core::Rectangle;
|
|
|
|
|
|
2025-08-23 05:15:57 +02:00
|
|
|
use crate::Task;
|
|
|
|
|
use crate::core::widget;
|
|
|
|
|
use crate::task;
|
|
|
|
|
|
|
|
|
|
/// Finds a widget by the given [`widget::Id`].
|
|
|
|
|
pub fn find_by_id(id: impl Into<widget::Id>) -> Task<Option<Match>> {
|
|
|
|
|
task::widget(id.into().find())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Finds a widget that contains the given text.
|
|
|
|
|
pub fn find_by_text(text: impl Into<String>) -> Task<Option<Text>> {
|
|
|
|
|
task::widget(Selector::find(text.into()))
|
|
|
|
|
}
|
2025-08-27 10:54:53 +02:00
|
|
|
|
|
|
|
|
/// Finds the visible bounds of the first [`Selector`] target.
|
|
|
|
|
pub fn visible_bounds<S>(selector: S) -> Task<Option<Rectangle>>
|
|
|
|
|
where
|
|
|
|
|
S: Selector + Send + 'static,
|
|
|
|
|
S::Output: Bounded + Clone + Send + 'static,
|
|
|
|
|
{
|
|
|
|
|
task::widget(selector.find())
|
|
|
|
|
.map(|target| target.as_ref().and_then(Bounded::visible_bounds))
|
|
|
|
|
}
|