Skip to main content

freya_core/accessibility/
focusable.rs

1/// Whether an element can receive keyboard focus.
2///
3/// Converts from a `bool`, where `true` is [`Focusable::Enabled`].
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Default, Clone, PartialEq, Eq)]
6pub enum Focusable {
7    /// Focusability is not specified, the platform decides. This is the default.
8    #[default]
9    Unknown,
10    /// The element cannot be focused.
11    Disabled,
12    /// The element can be focused.
13    Enabled,
14}
15
16impl From<bool> for Focusable {
17    fn from(value: bool) -> Self {
18        if value {
19            Focusable::Enabled
20        } else {
21            Focusable::Disabled
22        }
23    }
24}
25
26impl Focusable {
27    pub fn is_unknown(&self) -> bool {
28        matches!(self, Self::Unknown)
29    }
30
31    pub fn is_enabled(&self) -> bool {
32        matches!(self, Self::Enabled)
33    }
34}