#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct FocusId(u64);
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct FocusHandle {
pub id: FocusId,
}
#[derive(Default)]
pub struct FocusState {
next_id: u64,
focused: Option<FocusId>,
path: Vec<FocusId>,
}
impl FocusState {
pub fn new_handle(&mut self) -> FocusHandle {
self.next_id += 1;
FocusHandle { id: FocusId(self.next_id) }
}
pub fn focus(&mut self, handle: &FocusHandle) {
self.focused = Some(handle.id);
}
pub fn blur(&mut self) {
self.focused = None;
}
pub fn focused(&self) -> Option<FocusId> {
self.focused
}
pub fn is_focused(&self, handle: &FocusHandle) -> bool {
self.focused == Some(handle.id)
}
pub fn contains_focus(&self, handle: &FocusHandle) -> bool {
self.path.contains(&handle.id)
}
pub fn set_path(&mut self, path: Vec<FocusId>) {
self.path = path;
}
}