╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
922 text_box.getFocus().focusable = true; 923 text_box.getFocus().kind = .{ .custom = link }; 924 try tab_ids.put(allocator, text_box.getFocus().id, {}); 925 try box.children.put(allocator, text_box.getFocus().id, .{ 926 .widget = .{ .text_box = text_box }, 927 .rect = null, 928 .min_size = .{ .width = label.len + 2, .height = null }, 929 }); 930 } 931 932 // tags tab, labeled with the active tag filter 933 { 934 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 935 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.urlAlloc(session.page_arena)}); 936 const label = if (data.tag.len == 0) "tags" else blk: { 937 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 938 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 939 }; 940 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 941 errdefer text_box.deinit(allocator); 942 text_box.getFocus().focusable = true; 943 text_box.getFocus().kind = .{ .custom = tags_link }; 944 try tab_ids.put(allocator, text_box.getFocus().id, {}); 945 try box.children.put(allocator, text_box.getFocus().id, .{ 946 .widget = .{ .text_box = text_box }, 947 .rect = null, 948 .min_size = .{ .width = label.len + 2, .height = null }, 949 }); 950 } 951 952 var self = Header{ .box = box, .tab_ids = tab_ids }; 953 // the tab matching the page's view is selected initially. 954 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 955 return self; 956 } 957 958 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 959 self.box.deinit(allocator); 960 self.tab_ids.deinit(allocator); 961 } 962 963 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 964 self.clearGrid(); 965 // only the selected tab shows its border 966 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 967 switch (child.widget) { 968 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 969 else => {}, 970 } 971 } 972 try self.box.build(allocator, constraint, root_focus); 973 } 974 975 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 976 _ = allocator; 977 const current_tab = self.currentTabIndex() orelse return; 978 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 979 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 980 } 981 } 982 983 pub fn clearGrid(self: *Header) void { 984 self.box.clearGrid(); 985 } 986 987 pub fn getGrid(self: Header) ?Grid { 988 return self.box.getGrid(); 989 } 990 991 pub fn getFocus(self: *Header) *Focus { 992 return self.box.getFocus(); 993 } 994 995 pub fn getSelectedIndex(self: Header) ?usize { 996 return self.currentTabIndex(); 997 } 998 999 fn currentTabIndex(self: Header) ?usize { 1000 const child_id = self.box.focus.child_id orelse return null; 1001 return self.tab_ids.getIndex(child_id); 1002 } 1003 }; 1004