╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
188 // the label is a single column; +2 for the border 189 .min_size = .{ .width = 1 + 2, .height = null }, 190 }); 191 } 192 193 var self = View{ 194 .scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = box }, .{ .direction = .horiz, .show_bar = false, .web_native = !session.is_terminal }), 195 .tab_ids = tab_ids, 196 .session = session, 197 }; 198 self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0]; 199 return self; 200 } 201 202 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 203 self.scroll.deinit(allocator); 204 self.tab_ids.deinit(allocator); 205 } 206 207 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 208 self.clearGrid(); 209 // only the selected tab shows its border 210 const box = &self.scroll.child.box; 211 ui.widget.setBackButtonVisible(box, self.session.back == .available); 212 for (box.children.keys(), box.children.values()) |id, *child| { 213 const tb: ?*wgt.TextBox = switch (child.widget) { 214 .text_box => |*x| x, 215 .auth_tab => |*at| blk: { 216 // the label tracks login state per frame, so the width must too 217 child.min_size = .{ .width = at.minWidth(), .height = null }; 218 break :blk &at.text_box; 219 }, 220 else => null, 221 }; 222 if (tb) |t| { 223 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 224 } 225 } 226 var scroll_constraint = constraint; 227 scroll_constraint.min_size.width = constraint.max_size.width orelse constraint.min_size.width; 228 try self.scroll.build(allocator, scroll_constraint, root_focus); 229 } 230 231 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 232 _ = allocator; 233 const current_tab = self.currentTabIndex() orelse return; 234 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 235 const tab_id = self.tab_ids.keys()[new_tab]; 236 root_focus.setFocus(tab_id); 237 const tab = self.scroll.child.box.children.get(tab_id) orelse return; 238 if (tab.rect) |rect| self.scroll.scrollToRect(rect); 239 } 240 } 241 242 pub fn clearGrid(self: *View) void { 243 self.scroll.clearGrid(); 244 } 245 246 pub fn getGrid(self: View) ?Grid { 247 return self.scroll.getGrid(); 248 } 249 250 pub fn getFocus(self: *View) *Focus { 251 return self.scroll.getFocus(); 252 } 253 254 pub fn getSelectedIndex(self: View) ?usize { 255 return self.currentTabIndex(); 256 } 257 258 fn currentTabIndex(self: View) ?usize { 259 const child_id = self.scroll.child.box.focus.child_id orelse return null; 260 return self.tab_ids.getIndex(child_id); 261 } 262 }; 263