╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
236 try box.children.put(allocator, auth_tab.getFocus().id, .{ 237 .widget = .{ .auth_tab = auth_tab }, 238 .rect = null, 239 .min_size = .{ .width = auth_tab.minWidth(), .height = null }, 240 }); 241 } 242 243 // quit tab 244 if (session.is_terminal) { 245 var text_box = try wgt.TextBox(ui.Widget).init(allocator, ui.Quit.tab_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 246 errdefer text_box.deinit(allocator); 247 text_box.getFocus().focusable = true; 248 text_box.getFocus().kind = .{ .custom = ui.Quit.tab_kind }; 249 try tab_ids.put(allocator, text_box.getFocus().id, {}); 250 try box.children.put(allocator, text_box.getFocus().id, .{ 251 .widget = .{ .text_box = text_box }, 252 .rect = null, 253 // the label is a single column; +2 for the border 254 .min_size = .{ .width = 1 + 2, .height = null }, 255 }); 256 } 257 258 var self = View{ .box = box, .data = data, .tab_ids = tab_ids }; 259 self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0]; 260 return self; 261 } 262 263 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 264 self.box.deinit(allocator); 265 self.tab_ids.deinit(allocator); 266 } 267 268 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 269 self.clearGrid(); 270 // only the selected tab shows its border 271 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 272 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 273 .text_box => |*x| x, 274 .auth_tab => |*at| blk: { 275 // the label tracks login state per frame, so the width must too 276 child.min_size = .{ .width = at.minWidth(), .height = null }; 277 break :blk &at.text_box; 278 }, 279 else => null, 280 }; 281 if (tb) |t| { 282 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 283 } 284 } 285 try self.box.build(allocator, constraint, root_focus); 286 } 287 288 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 289 _ = allocator; 290 const current_tab = self.currentTabIndex() orelse return; 291 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 292 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 293 } 294 } 295 296 pub fn clearGrid(self: *View) void { 297 self.box.clearGrid(); 298 } 299 300 pub fn getGrid(self: View) ?Grid { 301 return self.box.getGrid(); 302 } 303 304 pub fn getFocus(self: *View) *Focus { 305 return self.box.getFocus(); 306 } 307 308 pub fn getSelectedIndex(self: View) ?usize { 309 return self.currentTabIndex(); 310 } 311 312 fn currentTabIndex(self: View) ?usize { 313 const child_id = self.box.focus.child_id orelse return null; 314 return self.tab_ids.getIndex(child_id); 315 } 316 }; 317