╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Users.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
47 pub fn init(allocator: std.mem.Allocator, data: *const Self) !View { 48 var self = blk: { 49 var list = try ui.FlowBox.Scroll.init(allocator, .{ .cell_height = 1 }); 50 errdefer list.deinit(allocator); 51 52 break :blk View{ 53 .list = list, 54 .data = data, 55 }; 56 }; 57 errdefer self.deinit(allocator); 58 59 var arena = std.heap.ArenaAllocator.init(allocator); 60 defer arena.deinit(); 61 const aa = arena.allocator(); 62 63 const lines = try aa.alloc([]const u8, data.users.len); 64 for (data.users, 0..) |user, i| { 65 lines[i] = try std.fmt.allocPrint(aa, "{s} ({s})", .{ user.name, user.display_name }); 66 } 67 try self.list.setItems(allocator, lines); 68 69 return self; 70 } 71 72 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 73 self.list.deinit(allocator); 74 } 75 76 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 77 try self.list.build(allocator, constraint, root_focus); 78 } 79 80 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 81 try self.list.input(allocator, key, root_focus); 82 } 83 84 pub fn clearGrid(self: *View) void { 85 self.list.clearGrid(); 86 } 87 88 pub fn getGrid(self: View) ?Grid { 89 return self.list.getGrid(); 90 } 91 92 pub fn getFocus(self: *View) *Focus { 93 return self.list.getFocus(); 94 } 95 96 pub fn getSelectedIndex(self: View) ?usize { 97 return self.list.getSelectedIndex(); 98 } 99 }; 100