╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
152 if (current_tag == .fork_auth) selected_tab = auth_tab.getFocus().id; 153 try tabs_box.children.put(allocator, auth_tab.getFocus().id, .{ .widget = .{ .auth_tab = auth_tab }, .rect = null, .min_size = .{ .width = auth_tab.minWidth(), .height = null } }); 154 } 155 156 if (session.is_terminal) { 157 var quit = try wgt.TextBox.init(allocator, ui.Quit.tab_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 158 errdefer quit.deinit(allocator); 159 quit.getFocus().mode = .all; 160 quit.getFocus().kind = .{ .custom = ui.Quit.tab_kind }; 161 try tab_ids.put(allocator, quit.getFocus().id, {}); 162 try tabs_box.children.put(allocator, quit.getFocus().id, .{ .widget = .{ .text_box = quit }, .rect = null, .min_size = .{ .width = 3, .height = null } }); 163 } 164 165 tabs_box.getFocus().child_id = selected_tab orelse tab_ids.keys()[0]; 166 const title_id = title_box.getFocus().id; 167 const tabs_id = tabs_box.getFocus().id; 168 try box.children.put(allocator, title_id, .{ .widget = .{ .box = title_box }, .rect = null, .min_size = null }); 169 title_box_owned = true; 170 try box.children.put(allocator, tabs_id, .{ .widget = .{ .box = tabs_box }, .rect = null, .min_size = null }); 171 tabs_box_owned = true; 172 box.getFocus().child_id = tabs_id; 173 174 return .{ 175 .scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = box }, .{ .direction = .horiz, .show_bar = false, .web_native = !session.is_terminal }), 176 .tab_ids = tab_ids, 177 .tabs_id = tabs_id, 178 .first_group_width = first_group_width, 179 .session = session, 180 }; 181 } 182 183 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 184 self.scroll.deinit(allocator); 185 self.tab_ids.deinit(allocator); 186 } 187 188 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 189 self.clearGrid(); 190 const box = &self.scroll.child.box; 191 const back_visible = self.session.back == .available; 192 ui.widget.setBackButtonVisible(box, back_visible); 193 const tabs_child = self.tabsChild(); 194 const tabs_box = &tabs_child.widget.box; 195 196 const selected_tab = if (box.getFocus().child_id == self.tabs_id) tabs_box.getFocus().child_id else null; 197 var tabs_width: usize = 0; 198 for (tabs_box.children.keys(), tabs_box.children.values()) |id, *child| { 199 const text_box: ?*wgt.TextBox = switch (child.widget) { 200 .text_box => |*value| value, 201 .auth_tab => |*auth_tab| blk: { 202 child.min_size = .{ .width = auth_tab.minWidth(), .height = null }; 203 break :blk &auth_tab.text_box; 204 }, 205 else => null, 206 }; 207 if (text_box) |tab| tab.options.border_style = if (selected_tab == id) .single else .hidden; 208 tabs_width += if (child.min_size) |min_size| min_size.width orelse 0 else 0; 209 } 210 211 const viewport_width = constraint.max_size.width orelse constraint.min_size.width; 212 const content_width = if (viewport_width) |width| width -| 2 else null; 213 const back_width: usize = if (back_visible) ui.widget.back_button_width else 0; 214 const wrap = if (content_width) |width| self.first_group_width + back_width + tabs_width > width else false; 215 box.options.direction = if (wrap) .vert else .horiz; 216 tabs_child.min_size = if (wrap) .{ .width = content_width, .height = null } else null; 217 218 var scroll_constraint = constraint; 219 scroll_constraint.min_size.width = viewport_width; 220 try self.scroll.build(allocator, scroll_constraint, root_focus); 221 } 222 223 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 224 _ = allocator; 225 const current_tab = self.currentTabIndex() orelse return; 226 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 227 const tab_id = self.tab_ids.keys()[new_tab]; 228 root_focus.setFocus(tab_id); 229 const tabs_child = self.tabsChild(); 230 const tabs_rect = tabs_child.rect orelse return; 231 const tab = tabs_child.widget.box.children.get(tab_id) orelse return; 232 var rect = tab.rect orelse return; 233 rect.x += tabs_rect.x; 234 rect.y += tabs_rect.y; 235 self.scroll.scrollToRect(rect); 236 } 237 } 238 239 pub fn clearGrid(self: *View) void { 240 self.scroll.clearGrid(); 241 } 242 243 pub fn getGrid(self: View) ?Grid { 244 return self.scroll.getGrid(); 245 } 246 247 pub fn getFocus(self: *View) *Focus { 248 return self.scroll.getFocus(); 249 } 250 251 pub fn getSelectedIndex(self: View) ?usize { 252 return self.currentTabIndex(); 253 } 254 255 fn currentTabIndex(self: View) ?usize { 256 if (self.scroll.child.box.focus.child_id != self.tabs_id) return null; 257 const child_id = self.tabsChild().widget.box.focus.child_id orelse return null; 258 return self.tab_ids.getIndex(child_id); 259 } 260 261 fn tabsChild(self: *const View) *wgt.Box(ui.Widget).Child { 262 return self.scroll.child.box.children.getPtr(self.tabs_id) orelse unreachable; 263 } 264 }; 265