╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
128 return self; 129 } 130 131 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 132 self.box.deinit(allocator); 133 self.tab_ids.deinit(allocator); 134 } 135 136 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 137 self.clearGrid(); 138 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 139 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 140 .text_box => |*x| x, 141 .auth_tab => |*at| &at.text_box, 142 else => null, 143 }; 144 if (tb) |t| { 145 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 146 } 147 } 148 try self.box.build(allocator, constraint, root_focus); 149 } 150 151 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 152 _ = allocator; 153 const current_tab = self.currentTabIndex() orelse return; 154 var new_tab = current_tab; 155 switch (key) { 156 .arrow_left => new_tab -|= 1, 157 .arrow_right => if (new_tab + 1 < self.tab_ids.count()) { 158 new_tab += 1; 159 }, 160 else => {}, 161 } 162 if (new_tab != current_tab) { 163 try root_focus.setFocus(self.tab_ids.keys()[new_tab]); 164 } 165 } 166 167 pub fn clearGrid(self: *View) void { 168 self.box.clearGrid(); 169 } 170 171 pub fn getGrid(self: View) ?Grid { 172 return self.box.getGrid(); 173 } 174 175 pub fn getFocus(self: *View) *Focus { 176 return self.box.getFocus(); 177 } 178 179 pub fn getSelectedIndex(self: View) ?usize { 180 return self.currentTabIndex(); 181 } 182 183 fn currentTabIndex(self: View) ?usize { 184 const child_id = self.box.focus.child_id orelse return null; 185 return self.tab_ids.getIndex(child_id); 186 } 187 }; 188