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