╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1377 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 1378 errdefer tab_ids.deinit(allocator); 1379 1380 const aa = session.page_arena.allocator(); 1381 1382 // a list tab per status, labeled with its listing's issue count 1383 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 1384 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 1385 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1386 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 1387 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1388 errdefer text_box.deinit(allocator); 1389 text_box.getFocus().focusable = true; 1390 text_box.getFocus().kind = .{ .custom = link }; 1391 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1392 try box.children.put(allocator, text_box.getFocus().id, .{ 1393 .widget = .{ .text_box = text_box }, 1394 .rect = null, 1395 .min_size = .{ .width = label.len + 2, .height = null }, 1396 }); 1397 } 1398 1399 // tags tab, labeled with the active tag filter 1400 { 1401 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 1402 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 1403 const label = if (data.tag.len == 0) "tags" else blk: { 1404 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 1405 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 1406 }; 1407 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1408 errdefer text_box.deinit(allocator); 1409 text_box.getFocus().focusable = true; 1410 text_box.getFocus().kind = .{ .custom = tags_link }; 1411 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1412 try box.children.put(allocator, text_box.getFocus().id, .{ 1413 .widget = .{ .text_box = text_box }, 1414 .rect = null, 1415 .min_size = .{ .width = label.len + 2, .height = null }, 1416 }); 1417 } 1418 1419 // new-issue tab; an edit url shows the edit tab in its place 1420 { 1421 const route = if (data.view == .edit) 1422 ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong 1423 else 1424 ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong; 1425 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1426 const label: []const u8 = if (data.view == .edit) "edit" else "new"; 1427 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1428 errdefer text_box.deinit(allocator); 1429 text_box.getFocus().focusable = true; 1430 text_box.getFocus().kind = .{ .custom = link }; 1431 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1432 try box.children.put(allocator, text_box.getFocus().id, .{ 1433 .widget = .{ .text_box = text_box }, 1434 .rect = null, 1435 .min_size = .{ .width = label.len + 2, .height = null }, 1436 }); 1437 } 1438 1439 var self = Header{ .box = box, .tab_ids = tab_ids }; 1440 // the tab matching the page's view is selected initially. 1441 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 1442 return self; 1443 } 1444 1445 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 1446 self.box.deinit(allocator); 1447 self.tab_ids.deinit(allocator); 1448 } 1449 1450 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1451 self.clearGrid(); 1452 // only the selected tab shows its border 1453 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 1454 switch (child.widget) { 1455 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 1456 else => {}, 1457 } 1458 } 1459 try self.box.build(allocator, constraint, root_focus); 1460 } 1461 1462 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1463 _ = allocator; 1464 const current_tab = self.currentTabIndex() orelse return; 1465 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 1466 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 1467 } 1468 } 1469 1470 pub fn clearGrid(self: *Header) void { 1471 self.box.clearGrid(); 1472 } 1473 1474 pub fn getGrid(self: Header) ?Grid { 1475 return self.box.getGrid(); 1476 } 1477 1478 pub fn getFocus(self: *Header) *Focus { 1479 return self.box.getFocus(); 1480 } 1481 1482 pub fn getSelectedIndex(self: Header) ?usize { 1483 return self.currentTabIndex(); 1484 } 1485 1486 fn currentTabIndex(self: Header) ?usize { 1487 const child_id = self.box.focus.child_id orelse return null; 1488 return self.tab_ids.getIndex(child_id); 1489 } 1490 }; 1491