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