╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
451 const back_width: usize = if (back_visible) ui.widget.back_button_width else 0; 452 const wrap = if (content_width) |width| self.first_group_width + back_width + tabs_width > width else false; 453 box.options.direction = if (wrap) .vert else .horiz; 454 tabs_child.min_size = if (wrap) .{ .width = content_width, .height = null } else null; 455 (box.children.getPtr(self.gap_id) orelse unreachable).hidden = !wrap; 456 457 var scroll_constraint = constraint; 458 scroll_constraint.min_size.width = viewport_width; 459 try self.scroll.build(allocator, scroll_constraint, root_focus); 460 } 461 462 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 463 _ = allocator; 464 const current_tab = self.currentTabIndex() orelse return; 465 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 466 const tab_id = self.tab_ids.keys()[new_tab]; 467 root_focus.setFocus(tab_id); 468 const tabs_child = self.tabsChild(); 469 const tabs_rect = tabs_child.rect orelse return; 470 const tab = tabs_child.widget.box.children.get(tab_id) orelse return; 471 var rect = tab.rect orelse return; 472 rect.x += tabs_rect.x; 473 rect.y += tabs_rect.y; 474 self.scroll.scrollToRect(rect); 475 } 476 } 477 478 pub fn clearGrid(self: *View) void { 479 self.scroll.clearGrid(); 480 } 481 482 pub fn getGrid(self: View) ?Grid { 483 return self.scroll.getGrid(); 484 } 485 486 pub fn getFocus(self: *View) *Focus { 487 return self.scroll.getFocus(); 488 } 489 490 pub fn getSelectedIndex(self: View) ?usize { 491 return self.currentTabIndex(); 492 } 493 494 fn currentTabIndex(self: View) ?usize { 495 if (self.scroll.child.box.focus.child_id != self.tabs_id) return null; 496 const child_id = self.tabsChild().widget.box.focus.child_id orelse return null; 497 return self.tab_ids.getIndex(child_id); 498 } 499 500 fn tabsChild(self: *const View) *wgt.Box(ui.Widget).Child { 501 return self.scroll.child.box.children.getPtr(self.tabs_id) orelse unreachable; 502 } 503 }; 504