use crate::geometry::Point;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MouseButton {
Left,
Right,
Middle,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WindowOp {
Minimize,
ToggleMaximize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum CursorShape {
#[default]
Arrow,
Hand,
Text,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum PointerKind {
Down,
Up,
Move,
Enter,
Leave,
Wheel(i32),
}
#[derive(Debug, Clone, Copy)]
pub struct PointerEvent {
pub kind: PointerKind,
pub pos: Point,
pub button: MouseButton,
pub click_count: u8,
}
impl PointerEvent {
pub fn single(kind: PointerKind, pos: Point, button: MouseButton) -> Self {
Self { kind, pos, button, click_count: 1 }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Key {
Tab,
Enter,
Escape,
Backspace,
Delete,
Space,
Left,
Right,
Up,
Down,
Home,
End,
Char(char),
Other(u32),
}
#[derive(Debug, Clone, Copy)]
pub struct KeyEvent {
pub key: Key,
pub pressed: bool,
pub shift: bool,
pub ctrl: bool,
}
#[derive(Debug, Clone, Copy)]
pub enum Event {
Pointer(PointerEvent),
Key(KeyEvent),
}
#[derive(Clone)]
pub enum MenuAction {
SendKey(KeyEvent),
Run(std::rc::Rc<dyn Fn()>),
}
#[derive(Clone)]
pub struct MenuItem {
pub label: String,
pub action: MenuAction,
pub enabled: bool,
pub checked: bool,
}
impl MenuItem {
pub fn key(label: impl Into<String>, key: KeyEvent, enabled: bool) -> Self {
Self { label: label.into(), action: MenuAction::SendKey(key), enabled, checked: false }
}
pub fn run(label: impl Into<String>, f: impl Fn() + 'static, checked: bool) -> Self {
Self {
label: label.into(),
action: MenuAction::Run(std::rc::Rc::new(f)),
enabled: true,
checked,
}
}
}
#[derive(Clone)]
pub struct MenuRequest {
pub pos: Point,
pub items: Vec<MenuItem>,
pub min_width: i32,
}