use std::any::Any;
pub trait Companion: Send + Sync + 'static {
fn type_name(&self) -> &'static str;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}
#[derive(Clone, Debug, Default)]
pub struct FocusableCompanion {
pub state: FocusState,
pub tab_index: i32,
}
impl Companion for FocusableCompanion {
fn type_name(&self) -> &'static str {
"FocusableCompanion"
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
impl FocusableCompanion {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Clone, Debug, Default)]
pub struct A11yCompanion {
pub role: String,
pub label: String,
pub description: String,
pub disabled: bool,
}
impl Companion for A11yCompanion {
fn type_name(&self) -> &'static str {
"A11yCompanion"
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
impl A11yCompanion {
pub fn new() -> Self {
Self::default()
}
pub fn with_role(mut self, role: &str) -> Self {
self.role = role.to_string();
self
}
pub fn with_label(mut self, label: &str) -> Self {
self.label = label.to_string();
self
}
pub fn with_description(mut self, description: &str) -> Self {
self.description = description.to_string();
self
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum FocusState {
#[default]
Unfocused,
Focused,
FocusVisible,
}