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