╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
125 .min_size = .{ .width = 1 + 2, .height = null }, 126 }); 127 } 128 129 var self = View{ .box = box, .data = data, .tab_ids = tab_ids }; 130 self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0]; 131 return self; 132 } 133 134 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 135 self.box.deinit(allocator); 136 self.tab_ids.deinit(allocator); 137 } 138 139 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 140 self.clearGrid(); 141 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 142 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 143 .text_box => |*x| x, 144 .auth_tab => |*at| &at.text_box, 145 else => null, 146 }; 147 if (tb) |t| { 148 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 149 } 150 } 151 try self.box.build(allocator, constraint, root_focus); 152 } 153 154 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 155 _ = allocator; 156 const current_tab = self.currentTabIndex() orelse return; 157 var new_tab = current_tab; 158 switch (key) { 159 .arrow_left => new_tab -|= 1, 160 .arrow_right => if (new_tab + 1 < self.tab_ids.count()) { 161 new_tab += 1; 162 }, 163 else => {}, 164 } 165 if (new_tab != current_tab) { 166 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 167 } 168 } 169 170 pub fn clearGrid(self: *View) void { 171 self.box.clearGrid(); 172 } 173 174 pub fn getGrid(self: View) ?Grid { 175 return self.box.getGrid(); 176 } 177 178 pub fn getFocus(self: *View) *Focus { 179 return self.box.getFocus(); 180 } 181 182 pub fn getSelectedIndex(self: View) ?usize { 183 return self.currentTabIndex(); 184 } 185 186 fn currentTabIndex(self: View) ?usize { 187 const child_id = self.box.focus.child_id orelse return null; 188 return self.tab_ids.getIndex(child_id); 189 } 190 }; 191