╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
204 .tabs_id = tabs_id, 205 .gap_id = gap_id, 206 .first_group_width = first_group_width, 207 .session = session, 208 }; 209 } 210 211 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 212 self.scroll.deinit(allocator); 213 self.tab_ids.deinit(allocator); 214 } 215 216 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 217 self.clearGrid(); 218 const box = &self.scroll.child.box; 219 const back_visible = self.session.back == .available; 220 ui.widget.setBackButtonVisible(box, back_visible); 221 const tabs_child = self.tabsChild(); 222 const tabs_box = &tabs_child.widget.box; 223 224 const selected_tab = tabs_box.getFocus().child_id; 225 var tabs_width: usize = 0; 226 for (tabs_box.children.keys(), tabs_box.children.values()) |id, *child| { 227 const text_box: ?*wgt.TextBox = switch (child.widget) { 228 .text_box => |*value| value, 229 else => null, 230 }; 231 if (text_box) |tab| ui.widget.markSelected(tab, selected_tab == id); 232 tabs_width += if (child.min_size) |min_size| min_size.width orelse 0 else 0; 233 } 234 235 const viewport_width = constraint.max_size.width orelse constraint.min_size.width; 236 const content_width = if (viewport_width) |width| width -| 2 else null; 237 const back_width: usize = if (back_visible) ui.widget.back_button_width else 0; 238 const wrap = if (content_width) |width| self.first_group_width + back_width + tabs_width > width else false; 239 box.options.direction = if (wrap) .vert else .horiz; 240 tabs_child.min_size = if (wrap) .{ .width = content_width, .height = null } else null; 241 (box.children.getPtr(self.gap_id) orelse unreachable).hidden = !wrap; 242 243 var scroll_constraint = constraint; 244 scroll_constraint.min_size.width = viewport_width; 245 try self.scroll.build(allocator, scroll_constraint, root_focus); 246 } 247 248 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 249 _ = allocator; 250 const current_tab = self.currentTabIndex() orelse return; 251 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 252 const tab_id = self.tab_ids.keys()[new_tab]; 253 root_focus.setFocus(tab_id); 254 const tabs_child = self.tabsChild(); 255 const tabs_rect = tabs_child.rect orelse return; 256 const tab = tabs_child.widget.box.children.get(tab_id) orelse return; 257 var rect = tab.rect orelse return; 258 rect.x += tabs_rect.x; 259 rect.y += tabs_rect.y; 260 self.scroll.scrollToRect(rect); 261 } 262 } 263 264 pub fn clearGrid(self: *View) void { 265 self.scroll.clearGrid(); 266 } 267 268 pub fn getGrid(self: View) ?Grid { 269 return self.scroll.getGrid(); 270 } 271 272 pub fn getFocus(self: *View) *Focus { 273 return self.scroll.getFocus(); 274 } 275 276 pub fn getSelectedIndex(self: View) ?usize { 277 return self.currentTabIndex(); 278 } 279 280 fn currentTabIndex(self: View) ?usize { 281 if (self.scroll.child.box.focus.child_id != self.tabs_id) return null; 282 const child_id = self.tabsChild().widget.box.focus.child_id orelse return null; 283 return self.tab_ids.getIndex(child_id); 284 } 285 286 fn tabsChild(self: *const View) *wgt.Box(ui.Widget).Child { 287 return self.scroll.child.box.children.getPtr(self.tabs_id) orelse unreachable; 288 } 289 }; 290