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