╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
148 if (session.is_terminal) { 149 var text_box = try wgt.TextBox.init(allocator, ui.Quit.tab_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 150 errdefer text_box.deinit(allocator); 151 text_box.getFocus().focusable = true; 152 text_box.getFocus().kind = .{ .custom = ui.Quit.tab_kind }; 153 try tab_ids.put(allocator, text_box.getFocus().id, {}); 154 try box.children.put(allocator, text_box.getFocus().id, .{ 155 .widget = .{ .text_box = text_box }, 156 .rect = null, 157 // the label is a single column; +2 for the border 158 .min_size = .{ .width = 1 + 2, .height = null }, 159 }); 160 } 161 162 var self = View{ 163 .scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = box }, .{ .direction = .horiz, .show_bar = false, .web_native = !session.is_terminal }), 164 .tab_ids = tab_ids, 165 }; 166 self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0]; 167 return self; 168 } 169 170 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 171 self.scroll.deinit(allocator); 172 self.tab_ids.deinit(allocator); 173 } 174 175 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 176 self.clearGrid(); 177 const box = &self.scroll.child.box; 178 for (box.children.keys(), box.children.values()) |id, *child| { 179 const tb: ?*wgt.TextBox = switch (child.widget) { 180 .text_box => |*x| x, 181 .auth_tab => |*at| blk: { 182 // the label tracks login state per frame, so the width must too 183 child.min_size = .{ .width = at.minWidth(), .height = null }; 184 break :blk &at.text_box; 185 }, 186 else => null, 187 }; 188 if (tb) |t| { 189 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 190 } 191 } 192 var scroll_constraint = constraint; 193 scroll_constraint.min_size.width = constraint.max_size.width orelse constraint.min_size.width; 194 try self.scroll.build(allocator, scroll_constraint, root_focus); 195 } 196 197 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 198 _ = allocator; 199 const current_tab = self.currentTabIndex() orelse return; 200 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 201 const tab_id = self.tab_ids.keys()[new_tab]; 202 root_focus.setFocus(tab_id); 203 const tab = self.scroll.child.box.children.get(tab_id) orelse return; 204 if (tab.rect) |rect| self.scroll.scrollToRect(rect); 205 } 206 } 207 208 pub fn clearGrid(self: *View) void { 209 self.scroll.clearGrid(); 210 } 211 212 pub fn getGrid(self: View) ?Grid { 213 return self.scroll.getGrid(); 214 } 215 216 pub fn getFocus(self: *View) *Focus { 217 return self.scroll.getFocus(); 218 } 219 220 pub fn getSelectedIndex(self: View) ?usize { 221 return self.currentTabIndex(); 222 } 223 224 fn currentTabIndex(self: View) ?usize { 225 const child_id = self.scroll.child.box.focus.child_id orelse return null; 226 return self.tab_ids.getIndex(child_id); 227 } 228 }; 229