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