╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
262 const half_count = (grid.size.height / 3) / 2; 263 index = @min(index + half_count, children.count() - 1); 264 } 265 } 266 }, 267 .mouse => |mouse| switch (mouse.action) { 268 .scroll => |dir| switch (dir) { 269 .up => index -|= 1, 270 .down => if (index + 1 < children.count()) { 271 index += 1; 272 }, 273 }, 274 else => {}, 275 }, 276 else => {}, 277 } 278 279 if (index != current_index) { 280 try root_focus.setFocus(children.keys()[index]); 281 self.updateScroll(index); 282 } 283 } 284 } 285 } 286 287 pub fn clearGrid(self: *SelectableList) void { 288 self.scroll.clearGrid(); 289 } 290 291 pub fn getGrid(self: SelectableList) ?Grid { 292 return self.scroll.getGrid(); 293 } 294 295 pub fn getFocus(self: *SelectableList) *Focus { 296 return self.scroll.getFocus(); 297 } 298 299 pub fn getSelectedIndex(self: SelectableList) ?usize { 300 if (self.scroll.child.box.focus.child_id) |child_id| { 301 const children = &self.scroll.child.box.children; 302 return children.getIndex(child_id); 303 } else { 304 return null; 305 } 306 } 307 308 fn updateScroll(self: *SelectableList, index: usize) void { 309 const inner_box = &self.scroll.child.box; 310 if (inner_box.children.values()[index].rect) |rect| { 311 self.scroll.scrollToRect(rect); 312 } 313 } 314 }; 315