╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
436 // as min_height with no max), we can still vertically center while 437 // letting taller content extend past the min. 438 const width = if (constraint.max_size.width) |w| w 439 else if (constraint.min_size.width) |min_w| @max(min_w, child_grid.size.width) 440 else child_grid.size.width; 441 const height = if (constraint.max_size.height) |h| h 442 else if (constraint.min_size.height) |min_h| @max(min_h, child_grid.size.height) 443 else child_grid.size.height; 444 if (width == 0 or height == 0) return; 445 446 const offset_x: usize = if (self.direction == .horiz or self.direction == .both) 447 (width -| child_grid.size.width) / 2 448 else 449 0; 450 const offset_y: usize = if (self.direction == .vert or self.direction == .both) 451 (height -| child_grid.size.height) / 2 452 else 453 0; 454 455 var grid = try Grid.init(allocator, .{ .width = width, .height = height }); 456 errdefer grid.deinit(); 457 try grid.drawGrid(child_grid, offset_x, offset_y); 458 try self.getFocus().addChild(self.child.getFocus(), child_grid.size, offset_x, offset_y); 459 self.getFocus().child_id = self.child.getFocus().id; 460 461 self.grid = grid; 462 } 463 464 pub fn input(self: *Center, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 465 try self.child.input(allocator, key, root_focus); 466 } 467 468 pub fn clearGrid(self: *Center) void { 469 if (self.grid) |*grid| { 470 grid.deinit(); 471 self.grid = null; 472 } 473 self.child.clearGrid(); 474 } 475 476 pub fn getGrid(self: Center) ?Grid { 477 return self.grid; 478 } 479 480 pub fn getFocus(self: *Center) *Focus { 481 return &self.focus; 482 } 483 }; 484