╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
145 switch (session.data.current_page) { 146 .user_settings => 1, 147 .user_auth => 2, 148 else => 0, 149 } 150 ]; 151 return self; 152 } 153 154 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 155 self.box.deinit(allocator); 156 self.tab_ids.deinit(allocator); 157 } 158 159 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 160 self.clearGrid(); 161 // only the selected tab shows its border 162 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 163 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 164 .text_box => |*x| x, 165 .auth_tab => |*at| &at.text_box, 166 else => null, 167 }; 168 if (tb) |t| { 169 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 170 } 171 } 172 try self.box.build(allocator, constraint, root_focus); 173 } 174 175 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 176 _ = allocator; 177 const current_tab = self.currentTabIndex() orelse return; 178 var new_tab = current_tab; 179 switch (key) { 180 .arrow_left => new_tab -|= 1, 181 .arrow_right => if (new_tab + 1 < self.tab_ids.count()) { 182 new_tab += 1; 183 }, 184 else => {}, 185 } 186 if (new_tab != current_tab) { 187 try root_focus.setFocus(self.tab_ids.keys()[new_tab]); 188 } 189 } 190 191 pub fn clearGrid(self: *View) void { 192 self.box.clearGrid(); 193 } 194 195 pub fn getGrid(self: View) ?Grid { 196 return self.box.getGrid(); 197 } 198 199 pub fn getFocus(self: *View) *Focus { 200 return self.box.getFocus(); 201 } 202 203 pub fn getSelectedIndex(self: View) ?usize { 204 return self.currentTabIndex(); 205 } 206 207 fn currentTabIndex(self: View) ?usize { 208 const child_id = self.box.focus.child_id orelse return null; 209 return self.tab_ids.getIndex(child_id); 210 } 211 }; 212