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