╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Discussions.zig ──────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
327 328 fn addTab(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), tab_ids: *std.AutoArrayHashMapUnmanaged(usize, void), label: []const u8, link: []const u8) !void { 329 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 330 errdefer text_box.deinit(allocator); 331 text_box.getFocus().focusable = true; 332 text_box.getFocus().kind = .{ .custom = link }; 333 try tab_ids.put(allocator, text_box.getFocus().id, {}); 334 try box.children.put(allocator, text_box.getFocus().id, .{ 335 .widget = .{ .text_box = text_box }, 336 .rect = null, 337 .min_size = .{ .width = label.len + 2, .height = null }, 338 }); 339 } 340 341 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 342 self.box.deinit(allocator); 343 self.tab_ids.deinit(allocator); 344 } 345 346 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 347 self.clearGrid(); 348 // only the selected tab shows its border 349 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 350 switch (child.widget) { 351 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 352 else => {}, 353 } 354 } 355 try self.box.build(allocator, constraint, root_focus); 356 } 357 358 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 359 _ = allocator; 360 const current_tab = self.currentTabIndex() orelse return; 361 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 362 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 363 } 364 } 365 366 pub fn clearGrid(self: *Header) void { 367 self.box.clearGrid(); 368 } 369 370 pub fn getGrid(self: Header) ?Grid { 371 return self.box.getGrid(); 372 } 373 374 pub fn getFocus(self: *Header) *Focus { 375 return self.box.getFocus(); 376 } 377 378 pub fn getSelectedIndex(self: Header) ?usize { 379 return self.currentTabIndex(); 380 } 381 382 fn currentTabIndex(self: Header) ?usize { 383 const child_id = self.box.focus.child_id orelse return null; 384 return self.tab_ids.getIndex(child_id); 385 } 386 }; 387