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