╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
951 try tab_ids.put(allocator, text_box.getFocus().id, {}); 952 try box.children.put(allocator, text_box.getFocus().id, .{ 953 .widget = .{ .text_box = text_box }, 954 .rect = null, 955 .min_size = .{ .width = label.len + 2, .height = null }, 956 }); 957 } 958 959 var self = Header{ .box = box, .tab_ids = tab_ids }; 960 // the tab matching the page's view is selected initially. 961 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 962 return self; 963 } 964 965 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 966 self.box.deinit(allocator); 967 self.tab_ids.deinit(allocator); 968 } 969 970 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 971 self.clearGrid(); 972 // only the selected tab shows its border 973 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 974 switch (child.widget) { 975 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 976 else => {}, 977 } 978 } 979 try self.box.build(allocator, constraint, root_focus); 980 } 981 982 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 983 _ = allocator; 984 const current_tab = self.currentTabIndex() orelse return; 985 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 986 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 987 } 988 } 989 990 pub fn clearGrid(self: *Header) void { 991 self.box.clearGrid(); 992 } 993 994 pub fn getGrid(self: Header) ?Grid { 995 return self.box.getGrid(); 996 } 997 998 pub fn getFocus(self: *Header) *Focus { 999 return self.box.getFocus(); 1000 } 1001 1002 pub fn getSelectedIndex(self: Header) ?usize { 1003 return self.currentTabIndex(); 1004 } 1005 1006 fn currentTabIndex(self: Header) ?usize { 1007 const child_id = self.box.focus.child_id orelse return null; 1008 return self.tab_ids.getIndex(child_id); 1009 } 1010 }; 1011