#![allow(clippy::module_name_repetitions)]
use ftui_core::geometry::Rect;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum A11yRole {
Window,
Dialog,
Button,
TextInput,
Label,
List,
ListItem,
Table,
TableRow,
TableCell,
Checkbox,
RadioButton,
ProgressBar,
Slider,
Tab,
TabPanel,
Menu,
MenuItem,
Toolbar,
ScrollBar,
Separator,
Group,
Presentation,
}
impl A11yRole {
#[inline]
pub const fn is_interactive(&self) -> bool {
matches!(
self,
Self::Button
| Self::TextInput
| Self::Checkbox
| Self::RadioButton
| Self::Slider
| Self::Tab
| Self::MenuItem
)
}
}
impl std::fmt::Display for A11yRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = match self {
Self::Window => "window",
Self::Dialog => "dialog",
Self::Button => "button",
Self::TextInput => "textInput",
Self::Label => "label",
Self::List => "list",
Self::ListItem => "listItem",
Self::Table => "table",
Self::TableRow => "tableRow",
Self::TableCell => "tableCell",
Self::Checkbox => "checkbox",
Self::RadioButton => "radioButton",
Self::ProgressBar => "progressBar",
Self::Slider => "slider",
Self::Tab => "tab",
Self::TabPanel => "tabPanel",
Self::Menu => "menu",
Self::MenuItem => "menuItem",
Self::Toolbar => "toolbar",
Self::ScrollBar => "scrollBar",
Self::Separator => "separator",
Self::Group => "group",
Self::Presentation => "presentation",
};
f.write_str(name)
}
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct A11yState {
pub focused: bool,
pub disabled: bool,
pub checked: Option<bool>,
pub expanded: Option<bool>,
pub selected: bool,
pub readonly: bool,
pub required: bool,
pub busy: bool,
pub value_now: Option<f64>,
pub value_min: Option<f64>,
pub value_max: Option<f64>,
pub value_text: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LiveRegion {
Polite,
Assertive,
}
impl std::fmt::Display for LiveRegion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Polite => f.write_str("polite"),
Self::Assertive => f.write_str("assertive"),
}
}
}
#[derive(Debug, Clone)]
pub struct A11yNodeInfo {
pub id: u64,
pub role: A11yRole,
pub name: Option<String>,
pub description: Option<String>,
pub bounds: Rect,
pub children: Vec<u64>,
pub parent: Option<u64>,
pub shortcut: Option<String>,
pub state: A11yState,
pub live_region: Option<LiveRegion>,
}
impl A11yNodeInfo {
#[inline]
pub fn new(id: u64, role: A11yRole, bounds: Rect) -> Self {
Self {
id,
role,
name: None,
description: None,
bounds,
children: Vec::new(),
parent: None,
shortcut: None,
state: A11yState::default(),
live_region: None,
}
}
#[inline]
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
#[inline]
pub fn with_description(mut self, desc: impl Into<String>) -> Self {
self.description = Some(desc.into());
self
}
#[inline]
pub fn with_shortcut(mut self, shortcut: impl Into<String>) -> Self {
self.shortcut = Some(shortcut.into());
self
}
#[inline]
pub fn with_live_region(mut self, live: LiveRegion) -> Self {
self.live_region = Some(live);
self
}
#[inline]
pub fn with_children(mut self, children: Vec<u64>) -> Self {
self.children = children;
self
}
#[inline]
pub fn with_parent(mut self, parent: u64) -> Self {
self.parent = Some(parent);
self
}
#[inline]
pub fn with_state(mut self, state: A11yState) -> Self {
self.state = state;
self
}
}