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