╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
168 }; 169 } 170 171 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 172 self.scroll.deinit(allocator); 173 self.tab_ids.deinit(allocator); 174 } 175 176 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 177 self.clearGrid(); 178 const box = &self.scroll.child.box; 179 const tabs_child = self.tabsChild(); 180 const tabs_box = &tabs_child.widget.box; 181 182 const selected_tab = if (box.getFocus().child_id == self.tabs_id) tabs_box.getFocus().child_id else null; 183 var tabs_width: usize = 0; 184 for (tabs_box.children.keys(), tabs_box.children.values()) |id, *child| { 185 const text_box: ?*wgt.TextBox = switch (child.widget) { 186 .text_box => |*value| value, 187 .auth_tab => |*auth_tab| blk: { 188 child.min_size = .{ .width = auth_tab.minWidth(), .height = null }; 189 break :blk &auth_tab.text_box; 190 }, 191 else => null, 192 }; 193 if (text_box) |tab| tab.options.border_style = if (selected_tab == id) .single else .hidden; 194 tabs_width += if (child.min_size) |min_size| min_size.width orelse 0 else 0; 195 } 196 197 const viewport_width = constraint.max_size.width orelse constraint.min_size.width; 198 const content_width = if (viewport_width) |width| width -| 2 else null; 199 const wrap = if (content_width) |width| self.first_group_width + tabs_width > width else false; 200 box.options.direction = if (wrap) .vert else .horiz; 201 tabs_child.min_size = if (wrap) .{ .width = content_width, .height = null } else null; 202 203 var scroll_constraint = constraint; 204 scroll_constraint.min_size.width = viewport_width; 205 try self.scroll.build(allocator, scroll_constraint, root_focus); 206 } 207 208 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 209 _ = allocator; 210 const current_tab = self.currentTabIndex() orelse return; 211 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 212 const tab_id = self.tab_ids.keys()[new_tab]; 213 root_focus.setFocus(tab_id); 214 const tabs_child = self.tabsChild(); 215 const tabs_rect = tabs_child.rect orelse return; 216 const tab = tabs_child.widget.box.children.get(tab_id) orelse return; 217 var rect = tab.rect orelse return; 218 rect.x += tabs_rect.x; 219 rect.y += tabs_rect.y; 220 self.scroll.scrollToRect(rect); 221 } 222 } 223 224 pub fn clearGrid(self: *View) void { 225 self.scroll.clearGrid(); 226 } 227 228 pub fn getGrid(self: View) ?Grid { 229 return self.scroll.getGrid(); 230 } 231 232 pub fn getFocus(self: *View) *Focus { 233 return self.scroll.getFocus(); 234 } 235 236 pub fn getSelectedIndex(self: View) ?usize { 237 return self.currentTabIndex(); 238 } 239 240 fn currentTabIndex(self: View) ?usize { 241 if (self.scroll.child.box.focus.child_id != self.tabs_id) return null; 242 const child_id = self.tabsChild().widget.box.focus.child_id orelse return null; 243 return self.tab_ids.getIndex(child_id); 244 } 245 246 fn tabsChild(self: *const View) *wgt.Box(ui.Widget).Child { 247 return self.scroll.child.box.children.getPtr(self.tabs_id) orelse unreachable; 248 } 249 }; 250