╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
165 return self; 166 } 167 168 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 169 self.scroll.deinit(allocator); 170 self.tab_ids.deinit(allocator); 171 } 172 173 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 174 self.clearGrid(); 175 // only the selected tab shows its border 176 const box = &self.scroll.child.box; 177 for (box.children.keys(), box.children.values()) |id, *child| { 178 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 179 .text_box => |*x| x, 180 .auth_tab => |*at| blk: { 181 // the label tracks login state per frame, so the width must too 182 child.min_size = .{ .width = at.minWidth(), .height = null }; 183 break :blk &at.text_box; 184 }, 185 else => null, 186 }; 187 if (tb) |t| { 188 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 189 } 190 } 191 var scroll_constraint = constraint; 192 scroll_constraint.min_size.width = constraint.max_size.width orelse constraint.min_size.width; 193 try self.scroll.build(allocator, scroll_constraint, root_focus); 194 } 195 196 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 197 _ = allocator; 198 const current_tab = self.currentTabIndex() orelse return; 199 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 200 const tab_id = self.tab_ids.keys()[new_tab]; 201 root_focus.setFocus(tab_id); 202 const tab = self.scroll.child.box.children.get(tab_id) orelse return; 203 if (tab.rect) |rect| self.scroll.scrollToRect(rect); 204 } 205 } 206 207 pub fn clearGrid(self: *View) void { 208 self.scroll.clearGrid(); 209 } 210 211 pub fn getGrid(self: View) ?Grid { 212 return self.scroll.getGrid(); 213 } 214 215 pub fn getFocus(self: *View) *Focus { 216 return self.scroll.getFocus(); 217 } 218 219 pub fn getSelectedIndex(self: View) ?usize { 220 return self.currentTabIndex(); 221 } 222 223 fn currentTabIndex(self: View) ?usize { 224 const child_id = self.scroll.child.box.focus.child_id orelse return null; 225 return self.tab_ids.getIndex(child_id); 226 } 227 }; 228