╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2746 try addTab(allocator, &box, &tab_ids, label, link); 2747 } 2748 2749 var self = Header{ .box = box, .tab_ids = tab_ids }; 2750 // the tab matching the page's view is selected initially. 2751 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 2752 return self; 2753 } 2754 2755 fn addTab(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), tab_ids: *std.AutoArrayHashMapUnmanaged(usize, void), label: []const u8, link: []const u8) !void { 2756 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 2757 errdefer text_box.deinit(allocator); 2758 text_box.getFocus().focusable = true; 2759 text_box.getFocus().kind = .{ .custom = link }; 2760 try tab_ids.put(allocator, text_box.getFocus().id, {}); 2761 try box.children.put(allocator, text_box.getFocus().id, .{ 2762 .widget = .{ .text_box = text_box }, 2763 .rect = null, 2764 .min_size = .{ .width = label.len + 2, .height = null }, 2765 }); 2766 } 2767 2768 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 2769 self.box.deinit(allocator); 2770 self.tab_ids.deinit(allocator); 2771 } 2772 2773 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2774 self.clearGrid(); 2775 // only the selected tab shows its border 2776 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 2777 switch (child.widget) { 2778 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 2779 else => {}, 2780 } 2781 } 2782 try self.box.build(allocator, constraint, root_focus); 2783 } 2784 2785 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2786 _ = allocator; 2787 const current_tab = self.currentTabIndex() orelse return; 2788 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 2789 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 2790 } 2791 } 2792 2793 pub fn clearGrid(self: *Header) void { 2794 self.box.clearGrid(); 2795 } 2796 2797 pub fn getGrid(self: Header) ?Grid { 2798 return self.box.getGrid(); 2799 } 2800 2801 pub fn getFocus(self: *Header) *Focus { 2802 return self.box.getFocus(); 2803 } 2804 2805 pub fn getSelectedIndex(self: Header) ?usize { 2806 return self.currentTabIndex(); 2807 } 2808 2809 fn currentTabIndex(self: Header) ?usize { 2810 const child_id = self.box.focus.child_id orelse return null; 2811 return self.tab_ids.getIndex(child_id); 2812 } 2813 }; 2814