╭ changed ───────╮ │src/ui/input.zig│ ╰────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────────────────────────╮ │1 const xit = @import("xit"); │ │2 const xitui = xit.xitui; │ │3 const Key = xitui.input.Key; │ │4 +const Mouse = xitui.input.Mouse; │ │5 +const Focus = xitui.focus.Focus; │ │6 │ │7 /// the vertical direction of a navigation key press, including mouse scroll│ │8 pub const Direction = enum { up, down, none }; │ ╰───────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │37 else => {}, │ │38 } │ │39 return null; │ │40 +} │ │41 + │ │42 +/// whether `mouse` is a left press inside the rect of `focus_id`'s focus entry│ │43 +pub fn leftClickOn(root_focus: *Focus, focus_id: usize, mouse: Mouse) bool { │ │44 + if (mouse.action != .press or mouse.action.press != .left) return false; │ │45 + const entry = root_focus.children.get(focus_id) orelse return false; │ │46 + const r = entry.rect; │ │47 + return mouse.x >= r.x and mouse.y >= r.y and │ │48 + mouse.x < r.x + r.size.width and mouse.y < r.y + r.size.height; │ │49 } │ │50 │ │51 +/// the tab index after a left/right arrow press, clamped to the ends, │ │52 +/// or null when the key doesn't move the selection │ │53 +pub fn moveTab(key: Key, current_tab: usize, tab_count: usize) ?usize { │ │54 + var new_tab = current_tab; │ │55 + switch (key) { │ │56 + .arrow_left => new_tab -|= 1, │ │57 + .arrow_right => if (new_tab + 1 < tab_count) { │ │58 + new_tab += 1; │ │59 + }, │ │60 + else => {}, │ │61 + } │ │62 + return if (new_tab != current_tab) new_tab else null; │ │63 +} │ ╰───────────────────────────────────────────────────────────────────────────────────╯