╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
231 .link = try std.fmt.allocPrint(aa, "a:{s}", .{try route.toUrl(session.page_arena)}), 232 }); 233 } 234 if (data.forks_next_start) |next_start| 235 try items.append(aa, .{ .text = "next →", .link = try std.fmt.allocPrint(aa, "a:/user/{s}/forks/start:{d}", .{ data.user.name, next_start }) }); 236 try list.setItems(allocator, items.items); 237 try stack.children.put(allocator, list.getFocus().id, .{ .flow_box_scroll = list }); 238 } 239 240 // the header has no settings tab without a login, so keep the 241 // stack's children 1:1 with the tabs by skipping the view too 242 if (session.data.user_id != null) { 243 var settings_view = try Settings.View.init(allocator, session); 244 errdefer settings_view.deinit(allocator); 245 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 246 } 247 248 { 249 var auth_view = try Auth.View.init(allocator, &data.auth, session); 250 errdefer auth_view.deinit(allocator); 251 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 252 } 253 254 if (session.is_terminal) { 255 var quit_view = try Quit.View.init(allocator, session); 256 errdefer quit_view.deinit(allocator); 257 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 258 } 259 260 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 261 } 262 263 var self = View{ .box = box }; 264 self.getFocus().child_id = box.children.keys()[header_index]; 265 return self; 266 } 267 268 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 269 self.box.deinit(allocator); 270 } 271 272 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 273 self.clearGrid(); 274 const header = &self.box.children.values()[header_index].widget.user_header; 275 const stack = &self.box.children.values()[stack_index].widget.stack; 276 277 // each header tab maps 1:1 to a stack child by position 278 if (header.getSelectedIndex()) |index| 279 stack.getFocus().child_id = stack.children.keys()[index]; 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 if (self.getFocus().child_id) |child_id| { 285 if (self.box.children.getIndex(child_id)) |current_index| { 286 const child = &self.box.children.values()[current_index].widget; 287 var index = current_index; 288 289 const direction = inp.vertDirection(key); 290 291 switch (direction) { 292 .up => { 293 switch (child.*) { 294 .user_header => { 295 try child.input(allocator, key, root_focus); 296 }, 297 .stack => { 298 if (child.stack.getSelected()) |selected_widget| { 299 const at_top = switch (selected_widget.*) { 300 .flow_box_scroll => |*v| v.getSelectedIndex() == 0, 301 .home_settings => |*v| v.getSelectedIndex() == 0, 302 .home_auth => |*v| v.getSelectedIndex() == 0, 303 .quit => |*v| v.getSelectedIndex() == 0, 304 else => false, 305 }; 306 if (at_top) { 307 index = header_index; 308 } else { 309 try child.input(allocator, key, root_focus); 310 } 311 } 312 }, 313 else => {}, 314 } 315 }, 316 .down => { 317 switch (child.*) { 318 .user_header => { 319 index = stack_index; 320 }, 321 .stack => { 322 try child.input(allocator, key, root_focus); 323 }, 324 else => {}, 325 } 326 }, 327 .none => { 328 try child.input(allocator, key, root_focus); 329 }, 330 } 331 332 if (index != current_index) { 333 root_focus.setFocus(self.box.children.keys()[index]); 334 } 335 } 336 } 337 } 338 339 pub fn clearGrid(self: *View) void { 340 self.box.clearGrid(); 341 } 342 343 pub fn getGrid(self: View) ?Grid { 344 return self.box.getGrid(); 345 } 346 347 pub fn getFocus(self: *View) *Focus { 348 return self.box.getFocus(); 349 } 350 }; 351