╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2625 const label: []const u8 = switch (data.view) { 2626 .edit => "edit", 2627 .new_comment => "reply", 2628 .edit_comment => "edit", 2629 .resolve => "resolve", 2630 else => "new", 2631 }; 2632 try addTab(allocator, &box, &tab_ids, label, link); 2633 } 2634 2635 // conflicts tab, labeled with the conflict count 2636 if (data.conflicts.count > 0) { 2637 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 2638 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2639 const label = try std.fmt.allocPrint(aa, "conflicts ({d})", .{data.conflicts.count}); 2640 try addTab(allocator, &box, &tab_ids, label, link); 2641 } 2642 2643 var self = Header{ .box = box, .tab_ids = tab_ids }; 2644 // the tab matching the page's view is selected initially. 2645 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 2646 return self; 2647 } 2648 2649 fn addTab(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), tab_ids: *std.AutoArrayHashMapUnmanaged(usize, void), label: []const u8, link: []const u8) !void { 2650 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 2651 errdefer text_box.deinit(allocator); 2652 text_box.getFocus().focusable = true; 2653 text_box.getFocus().kind = .{ .custom = link }; 2654 try tab_ids.put(allocator, text_box.getFocus().id, {}); 2655 try box.children.put(allocator, text_box.getFocus().id, .{ 2656 .widget = .{ .text_box = text_box }, 2657 .rect = null, 2658 .min_size = .{ .width = label.len + 2, .height = null }, 2659 }); 2660 } 2661 2662 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 2663 self.box.deinit(allocator); 2664 self.tab_ids.deinit(allocator); 2665 } 2666 2667 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2668 self.clearGrid(); 2669 // only the selected tab shows its border 2670 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 2671 switch (child.widget) { 2672 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 2673 else => {}, 2674 } 2675 } 2676 try self.box.build(allocator, constraint, root_focus); 2677 } 2678 2679 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2680 _ = allocator; 2681 const current_tab = self.currentTabIndex() orelse return; 2682 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 2683 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 2684 } 2685 } 2686 2687 pub fn clearGrid(self: *Header) void { 2688 self.box.clearGrid(); 2689 } 2690 2691 pub fn getGrid(self: Header) ?Grid { 2692 return self.box.getGrid(); 2693 } 2694 2695 pub fn getFocus(self: *Header) *Focus { 2696 return self.box.getFocus(); 2697 } 2698 2699 pub fn getSelectedIndex(self: Header) ?usize { 2700 return self.currentTabIndex(); 2701 } 2702 2703 fn currentTabIndex(self: Header) ?usize { 2704 const child_id = self.box.focus.child_id orelse return null; 2705 return self.tab_ids.getIndex(child_id); 2706 } 2707 }; 2708