╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
222 self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0]; 223 return self; 224 } 225 226 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 227 self.box.deinit(allocator); 228 self.tab_ids.deinit(allocator); 229 } 230 231 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 232 self.clearGrid(); 233 // only the selected tab shows its border 234 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 235 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 236 .text_box => |*x| x, 237 .auth_tab => |*at| &at.text_box, 238 else => null, 239 }; 240 if (tb) |t| { 241 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 242 } 243 } 244 try self.box.build(allocator, constraint, root_focus); 245 } 246 247 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 248 _ = allocator; 249 const current_tab = self.currentTabIndex() orelse return; 250 var new_tab = current_tab; 251 switch (key) { 252 .arrow_left => new_tab -|= 1, 253 .arrow_right => if (new_tab + 1 < self.tab_ids.count()) { 254 new_tab += 1; 255 }, 256 else => {}, 257 } 258 if (new_tab != current_tab) { 259 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 260 } 261 } 262 263 pub fn clearGrid(self: *View) void { 264 self.box.clearGrid(); 265 } 266 267 pub fn getGrid(self: View) ?Grid { 268 return self.box.getGrid(); 269 } 270 271 pub fn getFocus(self: *View) *Focus { 272 return self.box.getFocus(); 273 } 274 275 pub fn getSelectedIndex(self: View) ?usize { 276 return self.currentTabIndex(); 277 } 278 279 fn currentTabIndex(self: View) ?usize { 280 const child_id = self.box.focus.child_id orelse return null; 281 return self.tab_ids.getIndex(child_id); 282 } 283 }; 284