╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
147 try tab_ids.put(allocator, text_box.getFocus().id, {}); 148 try box.children.put(allocator, text_box.getFocus().id, .{ 149 .widget = .{ .text_box = text_box }, 150 .rect = null, 151 // the label is a single column; +2 for the border 152 .min_size = .{ .width = 1 + 2, .height = null }, 153 }); 154 } 155 156 var self = View{ .box = box, .data = data, .tab_ids = tab_ids }; 157 self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0]; 158 return self; 159 } 160 161 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 162 self.box.deinit(allocator); 163 self.tab_ids.deinit(allocator); 164 } 165 166 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 167 self.clearGrid(); 168 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 169 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 170 .text_box => |*x| x, 171 .auth_tab => |*at| blk: { 172 // the label tracks login state per frame, so the width must too 173 child.min_size = .{ .width = at.minWidth(), .height = null }; 174 break :blk &at.text_box; 175 }, 176 else => null, 177 }; 178 if (tb) |t| { 179 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 180 } 181 } 182 try self.box.build(allocator, constraint, root_focus); 183 } 184 185 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 186 _ = allocator; 187 const current_tab = self.currentTabIndex() orelse return; 188 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 189 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 190 } 191 } 192 193 pub fn clearGrid(self: *View) void { 194 self.box.clearGrid(); 195 } 196 197 pub fn getGrid(self: View) ?Grid { 198 return self.box.getGrid(); 199 } 200 201 pub fn getFocus(self: *View) *Focus { 202 return self.box.getFocus(); 203 } 204 205 pub fn getSelectedIndex(self: View) ?usize { 206 return self.currentTabIndex(); 207 } 208 209 fn currentTabIndex(self: View) ?usize { 210 const child_id = self.box.focus.child_id orelse return null; 211 return self.tab_ids.getIndex(child_id); 212 } 213 }; 214