╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Logout.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
52 try box.children.put(allocator, button.getFocus().id, .{ 53 .widget = .{ .text_box = button }, 54 .rect = null, 55 .min_size = null, 56 }); 57 } 58 59 box.getFocus().child_id = button_id; 60 61 return .{ 62 .center = try ui.Center.init(allocator, .{ .box = box }, .both), 63 .data = data, 64 .session = session, 65 .button_id = button_id, 66 .users_tab_id = users_tab_id, 67 }; 68 } 69 70 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 71 self.center.deinit(allocator); 72 } 73 74 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 75 const box = &self.center.child.box; 76 const button = &box.children.values()[button_index].widget.text_box; 77 button.options.border_style = if (root_focus.grandchild_id == self.button_id) 78 .double 79 else 80 .single; 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 try 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