╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
177 }); 178 } 179 180 var self = View{ .box = box, .data = data, .tab_ids = tab_ids }; 181 // open on the tab named by the current route 182 self.getFocus().child_id = self.tab_ids.keys()[ 183 switch (session.data.current_page) { 184 .repo_commits => 1, 185 .repo_settings => 2, 186 .repo_auth => 3, 187 else => 0, 188 } 189 ]; 190 return self; 191 } 192 193 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 194 self.box.deinit(allocator); 195 self.tab_ids.deinit(allocator); 196 } 197 198 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 199 self.clearGrid(); 200 // only the selected tab shows its border 201 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 202 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 203 .text_box => |*x| x, 204 .auth_tab => |*at| &at.text_box, 205 else => null, 206 }; 207 if (tb) |t| { 208 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 209 } 210 } 211 try self.box.build(allocator, constraint, root_focus); 212 } 213 214 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 215 _ = allocator; 216 const current_tab = self.currentTabIndex() orelse return; 217 var new_tab = current_tab; 218 switch (key) { 219 .arrow_left => new_tab -|= 1, 220 .arrow_right => if (new_tab + 1 < self.tab_ids.count()) { 221 new_tab += 1; 222 }, 223 else => {}, 224 } 225 if (new_tab != current_tab) { 226 try root_focus.setFocus(self.tab_ids.keys()[new_tab]); 227 } 228 } 229 230 pub fn clearGrid(self: *View) void { 231 self.box.clearGrid(); 232 } 233 234 pub fn getGrid(self: View) ?Grid { 235 return self.box.getGrid(); 236 } 237 238 pub fn getFocus(self: *View) *Focus { 239 return self.box.getFocus(); 240 } 241 242 pub fn getSelectedIndex(self: View) ?usize { 243 return self.currentTabIndex(); 244 } 245 246 fn currentTabIndex(self: View) ?usize { 247 const child_id = self.box.focus.child_id orelse return null; 248 return self.tab_ids.getIndex(child_id); 249 } 250 }; 251