summaryrefslogtreecommitdiffstats
path: root/test/src/selector.rs
blob: 7b8dcb7e6b9327b2a58f2066f101d12765ee0dcf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! Select widgets of a user interface.
use crate::core::text;
use crate::core::widget;

/// A selector describes a strategy to find a certain widget in a user interface.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Selector {
    /// Find the widget with the given [`widget::Id`].
    Id(widget::Id),
    /// Find the widget containing the given [`text::Fragment`].
    Text(text::Fragment<'static>),
}

impl From<widget::Id> for Selector {
    fn from(id: widget::Id) -> Self {
        Self::Id(id)
    }
}

impl From<&'static str> for Selector {
    fn from(id: &'static str) -> Self {
        Self::Id(widget::Id::new(id))
    }
}

/// Creates [`Selector`] that finds the widget containing the given text fragment.
pub fn text(fragment: impl text::IntoFragment<'static>) -> Selector {
    Selector::Text(fragment.into_fragment())
}