╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Auth.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
19 pub fn init() Self { 20 return .{ 21 .login = Login.init(), 22 .logout = Logout.init(), 23 }; 24 } 25 26 pub const View = struct { 27 stack: wgt.Stack(ui.Widget), 28 session: *ui.Session, 29 30 const login_index = 0; 31 const logout_index = 1; 32 33 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 34 var stack = try wgt.Stack(ui.Widget).init(allocator); 35 errdefer stack.deinit(allocator); 36 { 37 var login = try Login.View.init(allocator, &data.login, session); 38 errdefer login.deinit(allocator); 39 try stack.children.put(allocator, login.getFocus().id, .{ .auth_login = login }); 40 } 41 { 42 var logout = try Logout.View.init(allocator, &data.logout, session); 43 errdefer logout.deinit(allocator); 44 try stack.children.put(allocator, logout.getFocus().id, .{ .auth_logout = logout }); 45 } 46 return .{ 47 .stack = stack, 48 .session = session, 49 }; 50 } 51 52 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 53 self.stack.deinit(allocator); 54 } 55 56 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 57 const index: usize = if (self.session.data.user_id != null) logout_index else login_index; 58 self.stack.getFocus().child_id = self.stack.children.keys()[index]; 59 try self.stack.build(allocator, constraint, root_focus); 60 } 61 62 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 63 try self.stack.input(allocator, key, root_focus); 64 } 65 66 pub fn clearGrid(self: *View) void { 67 self.stack.clearGrid(); 68 } 69 70 pub fn getGrid(self: View) ?Grid { 71 return self.stack.getGrid(); 72 } 73 74 pub fn getFocus(self: *View) *Focus { 75 return self.stack.getFocus(); 76 } 77 78 pub fn atTop(self: View, root_focus: *Focus) bool { 79 const selected = self.stack.getSelected() orelse return false; 80 return selected.atTop(root_focus); 81 } 82 }; 83