Skip to main content

repose_core/
semantics.rs

1/// High‑level semantic role of a view, similar to ARIA roles.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum Role {
4    Text,
5    Button,
6    Tab,
7    TextField,
8    Container,
9    Checkbox,
10    RadioButton,
11    Switch,
12    Slider,
13    ProgressBar,
14}
15
16/// Semantics attached to a `View`, used to build the accessibility tree.
17#[derive(Clone, Debug)]
18pub struct Semantics {
19    /// Primary role of this node (what kind of thing it is).
20    pub role: Role,
21    /// Human‑readable label for screen readers. For buttons, this is the
22    /// “name” that is announced.
23    pub label: Option<String>,
24    /// Whether this node is currently focused.
25    pub focused: bool,
26    /// Whether this node is actionable; disabled nodes remain in the tree
27    /// but are marked not enabled.
28    pub enabled: bool,
29    /// Marks this node as a collection of horizontally or vertically stacked
30    /// selectable elements (ex: Tabs, RadioButtons).
31    pub selectable_group: bool,
32    // pub value: Option<String>,
33    // pub checked: Option<bool>,
34}
35
36impl Semantics {
37    pub fn new(role: Role) -> Self {
38        Self {
39            role,
40            label: None,
41            focused: false,
42            enabled: true,
43            selectable_group: false,
44            // value: None,
45            // checked: None,
46        }
47    }
48    pub fn with_label(mut self, label: impl Into<String>) -> Self {
49        self.label = Some(label.into());
50        self
51    }
52    pub fn with_selectable_group(mut self) -> Self {
53        self.selectable_group = true;
54        self
55    }
56}