╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1556 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1557 const label: []const u8 = if (data.view == .edit) "edit" else "new"; 1558 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1559 errdefer text_box.deinit(allocator); 1560 text_box.getFocus().focusable = true; 1561 text_box.getFocus().kind = .{ .custom = link }; 1562 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1563 try box.children.put(allocator, text_box.getFocus().id, .{ 1564 .widget = .{ .text_box = text_box }, 1565 .rect = null, 1566 .min_size = .{ .width = label.len + 2, .height = null }, 1567 }); 1568 } 1569 1570 var self = Header{ .box = box, .tab_ids = tab_ids }; 1571 // the tab matching the page's view is selected initially. 1572 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 1573 return self; 1574 } 1575 1576 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 1577 self.box.deinit(allocator); 1578 self.tab_ids.deinit(allocator); 1579 } 1580 1581 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1582 self.clearGrid(); 1583 // only the selected tab shows its border 1584 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 1585 switch (child.widget) { 1586 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 1587 else => {}, 1588 } 1589 } 1590 try self.box.build(allocator, constraint, root_focus); 1591 } 1592 1593 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1594 _ = allocator; 1595 const current_tab = self.currentTabIndex() orelse return; 1596 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 1597 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 1598 } 1599 } 1600 1601 pub fn clearGrid(self: *Header) void { 1602 self.box.clearGrid(); 1603 } 1604 1605 pub fn getGrid(self: Header) ?Grid { 1606 return self.box.getGrid(); 1607 } 1608 1609 pub fn getFocus(self: *Header) *Focus { 1610 return self.box.getFocus(); 1611 } 1612 1613 pub fn getSelectedIndex(self: Header) ?usize { 1614 return self.currentTabIndex(); 1615 } 1616 1617 fn currentTabIndex(self: Header) ?usize { 1618 const child_id = self.box.focus.child_id orelse return null; 1619 return self.tab_ids.getIndex(child_id); 1620 } 1621 }; 1622