use monospace_core::Offset;
use rat_widget::menu::MenubarState;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Focus {
Bar,
Region,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct Keyboard {
leaf: Focus,
}
impl Keyboard {
fn region() -> Self {
Self {
leaf: Focus::Region,
}
}
fn leaf(self) -> Focus {
self.leaf
}
fn is_bar(self) -> bool {
self.leaf == Focus::Bar
}
fn move_to_bar(&mut self) -> bool {
let moved = self.leaf != Focus::Bar;
self.leaf = Focus::Bar;
moved
}
fn move_to_region(&mut self) -> bool {
let moved = self.leaf != Focus::Region;
self.leaf = Focus::Region;
moved
}
fn move_to(&mut self, target: Target) -> bool {
match target {
Target::Bar => self.move_to_bar(),
Target::Border | Target::Interior(_) => self.move_to_region(),
Target::Nothing => false,
}
}
}
pub(crate) struct Chrome {
menu: MenubarState,
keyboard: Keyboard,
}
impl Chrome {
pub(crate) fn new() -> Self {
Self {
menu: MenubarState::default(),
keyboard: Keyboard::region(),
}
}
pub(crate) fn menu(&self) -> &MenubarState {
&self.menu
}
pub(crate) fn menu_mut(&mut self) -> &mut MenubarState {
&mut self.menu
}
pub(crate) fn popup_active(&self) -> bool {
self.menu.popup_active()
}
pub(crate) fn close_popup(&mut self) {
self.menu.set_popup_active(false);
}
pub(crate) fn move_to_bar(&mut self) -> bool {
self.keyboard.move_to_bar()
}
pub(crate) fn move_to_region(&mut self) -> bool {
self.keyboard.move_to_region()
}
pub(crate) fn leaf(&self) -> Focus {
self.keyboard.leaf()
}
pub(crate) fn is_bar(&self) -> bool {
self.keyboard.is_bar()
}
pub(crate) fn move_to(&mut self, target: Target) -> bool {
self.keyboard.move_to(target)
}
pub(crate) fn close(&mut self) {
self.close_popup();
self.keyboard.move_to_region();
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Target {
Bar,
Border,
Interior(Offset),
Nothing,
}