╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2321 }; 2322 try addTab(allocator, &box, &tab_ids, label, link); 2323 } 2324 2325 // conflicts tab, labeled with the conflict count 2326 if (data.conflicts.count > 0) { 2327 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 2328 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2329 const label = try std.fmt.allocPrint(aa, "conflicts ({d})", .{data.conflicts.count}); 2330 try addTab(allocator, &box, &tab_ids, label, link); 2331 } 2332 2333 var self = Header{ .box = box, .tab_ids = tab_ids }; 2334 // the tab matching the page's view is selected initially. 2335 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 2336 return self; 2337 } 2338 2339 fn addTab(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), tab_ids: *std.AutoArrayHashMapUnmanaged(usize, void), label: []const u8, link: []const u8) !void { 2340 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 2341 errdefer text_box.deinit(allocator); 2342 text_box.getFocus().focusable = true; 2343 text_box.getFocus().kind = .{ .custom = link }; 2344 try tab_ids.put(allocator, text_box.getFocus().id, {}); 2345 try box.children.put(allocator, text_box.getFocus().id, .{ 2346 .widget = .{ .text_box = text_box }, 2347 .rect = null, 2348 .min_size = .{ .width = label.len + 2, .height = null }, 2349 }); 2350 } 2351 2352 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 2353 self.box.deinit(allocator); 2354 self.tab_ids.deinit(allocator); 2355 } 2356 2357 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2358 self.clearGrid(); 2359 // only the selected tab shows its border 2360 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 2361 switch (child.widget) { 2362 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 2363 else => {}, 2364 } 2365 } 2366 try self.box.build(allocator, constraint, root_focus); 2367 } 2368 2369 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2370 _ = allocator; 2371 const current_tab = self.currentTabIndex() orelse return; 2372 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 2373 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 2374 } 2375 } 2376 2377 pub fn clearGrid(self: *Header) void { 2378 self.box.clearGrid(); 2379 } 2380 2381 pub fn getGrid(self: Header) ?Grid { 2382 return self.box.getGrid(); 2383 } 2384 2385 pub fn getFocus(self: *Header) *Focus { 2386 return self.box.getFocus(); 2387 } 2388 2389 pub fn getSelectedIndex(self: Header) ?usize { 2390 return self.currentTabIndex(); 2391 } 2392 2393 fn currentTabIndex(self: Header) ?usize { 2394 const child_id = self.box.focus.child_id orelse return null; 2395 return self.tab_ids.getIndex(child_id); 2396 } 2397 }; 2398