╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
155 self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0]; 156 return self; 157 } 158 159 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 160 self.box.deinit(allocator); 161 self.tab_ids.deinit(allocator); 162 } 163 164 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 165 self.clearGrid(); 166 // only the selected tab shows its border 167 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 168 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 169 .text_box => |*x| x, 170 .auth_tab => |*at| &at.text_box, 171 else => null, 172 }; 173 if (tb) |t| { 174 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 175 } 176 } 177 try self.box.build(allocator, constraint, root_focus); 178 } 179 180 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 181 _ = allocator; 182 const current_tab = self.currentTabIndex() orelse return; 183 var new_tab = current_tab; 184 switch (key) { 185 .arrow_left => new_tab -|= 1, 186 .arrow_right => if (new_tab + 1 < self.tab_ids.count()) { 187 new_tab += 1; 188 }, 189 else => {}, 190 } 191 if (new_tab != current_tab) { 192 try root_focus.setFocus(self.tab_ids.keys()[new_tab]); 193 } 194 } 195 196 pub fn clearGrid(self: *View) void { 197 self.box.clearGrid(); 198 } 199 200 pub fn getGrid(self: View) ?Grid { 201 return self.box.getGrid(); 202 } 203 204 pub fn getFocus(self: *View) *Focus { 205 return self.box.getFocus(); 206 } 207 208 pub fn getSelectedIndex(self: View) ?usize { 209 return self.currentTabIndex(); 210 } 211 212 fn currentTabIndex(self: View) ?usize { 213 const child_id = self.box.focus.child_id orelse return null; 214 return self.tab_ids.getIndex(child_id); 215 } 216 }; 217