╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ input.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
21 22 /// how many rows a navigation key press moves the selection (negative is up), 23 /// or null if the key doesn't move the selection. `count` is the row count, 24 /// so home/end jump past either end and get clamped by the caller. 25 pub fn rowDelta(key: Key, count: isize) ?isize { 26 switch (key) { 27 .arrow_up => return -1, 28 .arrow_down => return 1, 29 .page_up => return -10, 30 .page_down => return 10, 31 .home => return -count, 32 .end => return count, 33 .mouse => |mouse| switch (mouse.action) { 34 .scroll => |dir| return if (dir == .up) -1 else 1, 35 else => {}, 36 }, 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 } 64