╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
214 break :blk &auth_tab.text_box; 215 }, 216 else => null, 217 }; 218 if (text_box) |tab| ui.widget.markSelected(tab, selected_tab == id); 219 tabs_width += if (child.min_size) |min_size| min_size.width orelse 0 else 0; 220 } 221 222 const viewport_width = constraint.max_size.width orelse constraint.min_size.width; 223 const content_width = if (viewport_width) |width| width -| 2 else null; 224 const back_width: usize = if (back_visible) ui.widget.back_button_width else 0; 225 const wrap = if (content_width) |width| self.first_group_width + back_width + tabs_width > width else false; 226 box.options.direction = if (wrap) .vert else .horiz; 227 tabs_child.min_size = if (wrap) .{ .width = content_width, .height = null } else null; 228 (box.children.getPtr(self.gap_id) orelse unreachable).hidden = !wrap; 229 230 var scroll_constraint = constraint; 231 scroll_constraint.min_size.width = viewport_width; 232 try self.scroll.build(allocator, scroll_constraint, root_focus); 233 } 234 235 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 236 _ = allocator; 237 const current_tab = self.currentTabIndex() orelse return; 238 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 239 const tab_id = self.tab_ids.keys()[new_tab]; 240 root_focus.setFocus(tab_id); 241 const tabs_child = self.tabsChild(); 242 const tabs_rect = tabs_child.rect orelse return; 243 const tab = tabs_child.widget.box.children.get(tab_id) orelse return; 244 var rect = tab.rect orelse return; 245 rect.x += tabs_rect.x; 246 rect.y += tabs_rect.y; 247 self.scroll.scrollToRect(rect); 248 } 249 } 250 251 pub fn clearGrid(self: *View) void { 252 self.scroll.clearGrid(); 253 } 254 255 pub fn getGrid(self: View) ?Grid { 256 return self.scroll.getGrid(); 257 } 258 259 pub fn getFocus(self: *View) *Focus { 260 return self.scroll.getFocus(); 261 } 262 263 pub fn getSelectedIndex(self: View) ?usize { 264 return self.currentTabIndex(); 265 } 266 267 fn currentTabIndex(self: View) ?usize { 268 if (self.scroll.child.box.focus.child_id != self.tabs_id) return null; 269 const child_id = self.tabsChild().widget.box.focus.child_id orelse return null; 270 return self.tab_ids.getIndex(child_id); 271 } 272 273 fn tabsChild(self: *const View) *wgt.Box(ui.Widget).Child { 274 return self.scroll.child.box.children.getPtr(self.tabs_id) orelse unreachable; 275 } 276 }; 277