╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
916 917 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 918 errdefer tab_ids.deinit(allocator); 919 920 const aa = session.page_arena.allocator(); 921 922 // a list tab per status, labeled with its listing's issue count 923 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 924 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 925 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 926 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 927 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 928 errdefer text_box.deinit(allocator); 929 text_box.getFocus().focusable = true; 930 text_box.getFocus().kind = .{ .custom = link }; 931 try tab_ids.put(allocator, text_box.getFocus().id, {}); 932 try box.children.put(allocator, text_box.getFocus().id, .{ 933 .widget = .{ .text_box = text_box }, 934 .rect = null, 935 .min_size = .{ .width = label.len + 2, .height = null }, 936 }); 937 } 938 939 // tags tab, labeled with the active tag filter 940 { 941 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 942 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 943 const label = if (data.tag.len == 0) "tags" else blk: { 944 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 945 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 946 }; 947 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 948 errdefer text_box.deinit(allocator); 949 text_box.getFocus().focusable = true; 950 text_box.getFocus().kind = .{ .custom = tags_link }; 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