╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
221 .rect = null, 222 .min_size = .{ .width = "settings".len + 2, .height = null }, 223 }); 224 } 225 226 // auth tab (login / logout). AuthTab defaults to the global ai:/auth 227 // link; repoint its instance at this repo's auth route so it stays on 228 // this page. local mode has no accounts, so it has no auth tab. 229 if (!session.data.is_local) { 230 var auth_tab = try AuthTab.View.init(allocator, session); 231 errdefer auth_tab.deinit(allocator); 232 auth_tab.text_box.getFocus().kind = .{ .custom = auth_link }; 233 try tab_ids.put(allocator, auth_tab.getFocus().id, {}); 234 if (std.mem.eql(u8, auth_link, current_link)) selected_tab = auth_tab.getFocus().id; 235 try box.children.put(allocator, auth_tab.getFocus().id, .{ 236 .widget = .{ .auth_tab = auth_tab }, 237 .rect = null, 238 .min_size = .{ .width = AuthTab.min_width, .height = null }, 239 }); 240 } 241 242 // quit tab 243 if (session.is_terminal) { 244 var text_box = try wgt.TextBox(ui.Widget).init(allocator, ui.Quit.tab_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 245 errdefer text_box.deinit(allocator); 246 text_box.getFocus().focusable = true; 247 text_box.getFocus().kind = .{ .custom = ui.Quit.tab_kind }; 248 try tab_ids.put(allocator, text_box.getFocus().id, {}); 249 try box.children.put(allocator, text_box.getFocus().id, .{ 250 .widget = .{ .text_box = text_box }, 251 .rect = null, 252 // the label is a single column; +2 for the border 253 .min_size = .{ .width = 1 + 2, .height = null }, 254 }); 255 } 256 257 var self = View{ .box = box, .data = data, .tab_ids = tab_ids }; 258 self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0]; 259 return self; 260 } 261 262 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 263 self.box.deinit(allocator); 264 self.tab_ids.deinit(allocator); 265 } 266 267 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 268 self.clearGrid(); 269 // only the selected tab shows its border 270 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 271 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 272 .text_box => |*x| x, 273 .auth_tab => |*at| &at.text_box, 274 else => null, 275 }; 276 if (tb) |t| { 277 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 278 } 279 } 280 try self.box.build(allocator, constraint, root_focus); 281 } 282 283 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 284 _ = allocator; 285 const current_tab = self.currentTabIndex() orelse return; 286 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 287 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 288 } 289 } 290 291 pub fn clearGrid(self: *View) void { 292 self.box.clearGrid(); 293 } 294 295 pub fn getGrid(self: View) ?Grid { 296 return self.box.getGrid(); 297 } 298 299 pub fn getFocus(self: *View) *Focus { 300 return self.box.getFocus(); 301 } 302 303 pub fn getSelectedIndex(self: View) ?usize { 304 return self.currentTabIndex(); 305 } 306 307 fn currentTabIndex(self: View) ?usize { 308 const child_id = self.box.focus.child_id orelse return null; 309 return self.tab_ids.getIndex(child_id); 310 } 311 }; 312