1mod keyboard;
2mod pointer;
3mod tooltip;
4
5use crate::controls::{intersect, scroll_thumb};
6use crate::*;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum Key {
11 Tab,
13 BackTab,
15 Enter,
17 Escape,
19 Space,
21 Left,
23 Right,
25 Up,
27 Down,
29 Home,
31 End,
33 PageUp,
35 PageDown,
37 Backspace,
39 Delete,
41 Character(char),
43}
44
45impl Ui {
46 pub fn focused(&self) -> Option<NodeId> {
48 self.focus
49 }
50 pub fn pointer(&self) -> (i32, i32) {
52 self.pointer
53 }
54 pub fn pointer_over_interactive(&self) -> bool {
56 self.hot.is_some_and(|id| self.interactive(id))
57 }
58 pub fn cursor_index(&self, id: NodeId, x: i32, y: i32) -> i32 {
61 let n = &self.nodes[id];
62 let mut cursor = n.cursor;
63 for &c in &n.children {
64 let child = &self.nodes[c];
65 if child.visible() && child.contains(x, y) {
66 cursor = self.cursor_index(c, x, y);
67 }
68 }
69 cursor
70 }
71
72 pub fn text_edit_focused(&self) -> bool {
74 self.focus
75 .is_some_and(|id| matches!(&self.nodes[id].kind, Kind::Control(Control::Edit(_))))
76 }
77 pub fn drain_events(&mut self) -> Vec<Event> {
80 std::mem::take(&mut self.pending)
81 }
82 pub fn set_shortcut(&mut self, id: NodeId, key: u32) {
85 self.nodes[id].shortcut = Some(key);
86 }
87 pub fn clear_input(&mut self) {
90 self.focus = None;
91 self.hot = None;
92 self.pressed = None;
93 self.pointer_down = false;
94 self.pending.clear();
95 self.input_root = None;
96 self.tooltip_instance = None;
97 }
98}
99
100fn contains(r: [i32; 4], x: i32, y: i32) -> bool {
101 x >= r[0] && x < r[2] && y >= r[1] && y < r[3]
102}
103
104pub(crate) fn event_node(e: Event) -> NodeId {
105 match e {
106 Event::Clicked(n)
107 | Event::Selected(n, _)
108 | Event::Changed(n)
109 | Event::Submitted(n)
110 | Event::Link(n, _) => n,
111 }
112}
113
114pub mod tooltip_controller {
117 pub const HOT_KEY: u32 = 0x5dd8_3c93;
119 pub const TITLE_DESC: u32 = 0x33e6_1003;
121 pub const BUILD_REQUIREMENT: u32 = 0xc3fe_f549;
123}