use accesskit::NodeId;
#[derive(Debug, Clone, PartialEq)]
pub struct FocusRing {
pub color: [u8; 4],
pub width: f32,
pub offset: f32,
pub radius: f32,
}
impl Default for FocusRing {
fn default() -> Self {
Self {
color: [0, 120, 215, 255],
width: 2.0,
offset: 2.0,
radius: 3.0,
}
}
}
impl FocusRing {
pub fn ring_rect(&self, x: f32, y: f32, width: f32, height: f32) -> (f32, f32, f32, f32) {
let grow = self.offset + self.width / 2.0;
(x - grow, y - grow, width + grow * 2.0, height + grow * 2.0)
}
pub fn is_visible(&self) -> bool {
self.width > 0.0 && self.color[3] > 0
}
}
pub struct FocusIndicator {
focused_node: Option<NodeId>,
ring: FocusRing,
}
impl Default for FocusIndicator {
fn default() -> Self {
Self::new()
}
}
impl FocusIndicator {
pub fn new() -> Self {
Self {
focused_node: None,
ring: FocusRing::default(),
}
}
pub fn set_focus(&mut self, id: Option<NodeId>) {
self.focused_node = id;
}
pub fn focused_node(&self) -> Option<NodeId> {
self.focused_node
}
pub fn ring(&self) -> &FocusRing {
&self.ring
}
pub fn with_ring(mut self, ring: FocusRing) -> Self {
self.ring = ring;
self
}
}