╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
427 child.min_size = .{ .width = at.minWidth(), .height = null }; 428 break :blk &at.text_box; 429 }, 430 else => null, 431 }; 432 if (tb) |t| ui.widget.markSelected(t, selected_tab == id); 433 tabs_width += if (child.min_size) |min_size| min_size.width orelse 0 else 0; 434 } 435 436 const viewport_width = constraint.max_size.width orelse constraint.min_size.width; 437 // the outer box's hidden border occupies two columns. keep the title 438 // and tabs together if they fit; otherwise tab strip on its own row. 439 const content_width = if (viewport_width) |width| width -| 2 else null; 440 const back_width: usize = if (back_visible) ui.widget.back_button_width else 0; 441 const wrap = if (content_width) |width| self.first_group_width + back_width + tabs_width > width else false; 442 box.options.direction = if (wrap) .vert else .horiz; 443 tabs_child.min_size = if (wrap) .{ .width = content_width, .height = null } else null; 444 (box.children.getPtr(self.gap_id) orelse unreachable).hidden = !wrap; 445 446 var scroll_constraint = constraint; 447 scroll_constraint.min_size.width = viewport_width; 448 try self.scroll.build(allocator, scroll_constraint, root_focus); 449 } 450 451 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 452 _ = allocator; 453 const current_tab = self.currentTabIndex() orelse return; 454 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 455 const tab_id = self.tab_ids.keys()[new_tab]; 456 root_focus.setFocus(tab_id); 457 const tabs_child = self.tabsChild(); 458 const tabs_rect = tabs_child.rect orelse return; 459 const tab = tabs_child.widget.box.children.get(tab_id) orelse return; 460 var rect = tab.rect orelse return; 461 rect.x += tabs_rect.x; 462 rect.y += tabs_rect.y; 463 self.scroll.scrollToRect(rect); 464 } 465 } 466 467 pub fn clearGrid(self: *View) void { 468 self.scroll.clearGrid(); 469 } 470 471 pub fn getGrid(self: View) ?Grid { 472 return self.scroll.getGrid(); 473 } 474 475 pub fn getFocus(self: *View) *Focus { 476 return self.scroll.getFocus(); 477 } 478 479 pub fn getSelectedIndex(self: View) ?usize { 480 return self.currentTabIndex(); 481 } 482 483 fn currentTabIndex(self: View) ?usize { 484 if (self.scroll.child.box.focus.child_id != self.tabs_id) return null; 485 const child_id = self.tabsChild().widget.box.focus.child_id orelse return null; 486 return self.tab_ids.getIndex(child_id); 487 } 488 489 fn tabsChild(self: *const View) *wgt.Box(ui.Widget).Child { 490 return self.scroll.child.box.children.getPtr(self.tabs_id) orelse unreachable; 491 } 492 }; 493