╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Logout.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
46 .min_size = null, 47 }); 48 } 49 50 var button_id: usize = undefined; 51 { 52 var button = try wgt.TextBox(ui.Widget).init(allocator, "logout", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 53 errdefer button.deinit(allocator); 54 button.getFocus().focusable = true; 55 // the renderer distinguishes plain clickables from buttons that 56 // should POST to a server route by this kind. 57 button.getFocus().kind = .{ .custom = "submit" }; 58 button_id = button.getFocus().id; 59 try box.children.put(allocator, button.getFocus().id, .{ 60 .widget = .{ .text_box = button }, 61 .rect = null, 62 .min_size = null, 63 }); 64 } 65 66 box.getFocus().child_id = button_id; 67 68 return .{ 69 .center = try ui.Center.init(allocator, .{ .box = box }), 70 .data = data, 71 .session = session, 72 .button_id = button_id, 73 .users_tab_id = users_tab_id, 74 }; 75 } 76 77 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 78 self.center.deinit(allocator); 79 } 80 81 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 82 try self.center.build(allocator, constraint, root_focus); 83 } 84 85 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 86 _ = allocator; 87 switch (key) { 88 .enter => { 89 try self.logout(root_focus); 90 return; 91 }, 92 .mouse => |mouse| { 93 if (inp.leftClickOn(root_focus, self.button_id, mouse)) { 94 try self.logout(root_focus); 95 return; 96 } 97 }, 98 else => {}, 99 } 100 } 101 102 fn logout(self: *View, root_focus: *Focus) !void { 103 self.session.data.user_id = null; 104 // jump focus back to the users tab — the logout button is about to 105 // be hidden by the tab-label swap. 106 root_focus.setFocus(self.users_tab_id); 107 } 108 109 pub fn clearGrid(self: *View) void { 110 self.center.clearGrid(); 111 } 112 113 pub fn getGrid(self: View) ?Grid { 114 return self.center.getGrid(); 115 } 116 117 pub fn getFocus(self: *View) *Focus { 118 return self.center.getFocus(); 119 } 120 121 pub fn getSelectedIndex(self: View) ?usize { 122 _ = self; 123 return 0; 124 } 125 }; 126