╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Quit.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
39 }); 40 } 41 42 var button_id: usize = undefined; 43 { 44 var button = try wgt.TextBox(ui.Widget).init(allocator, "quit", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 45 errdefer button.deinit(allocator); 46 button.getFocus().focusable = true; 47 button_id = button.getFocus().id; 48 try box.children.put(allocator, button.getFocus().id, .{ 49 .widget = .{ .text_box = button }, 50 .rect = null, 51 .min_size = null, 52 }); 53 } 54 55 box.getFocus().child_id = button_id; 56 57 return .{ 58 .center = try ui.Center.init(allocator, .{ .box = box }), 59 .session = session, 60 .button_id = button_id, 61 }; 62 } 63 64 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 65 self.center.deinit(allocator); 66 } 67 68 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 69 try self.center.build(allocator, constraint, root_focus); 70 } 71 72 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 73 _ = allocator; 74 switch (key) { 75 .enter => { 76 self.session.quit_requested = true; 77 return; 78 }, 79 .mouse => |mouse| { 80 if (mouse.action == .press and mouse.action.press == .left) { 81 if (root_focus.children.get(self.button_id)) |entry| { 82 const r = entry.rect; 83 if (mouse.x >= r.x and mouse.y >= r.y and 84 mouse.x < r.x + r.size.width and mouse.y < r.y + r.size.height) 85 { 86 self.session.quit_requested = true; 87 return; 88 } 89 } 90 } 91 }, 92 else => {}, 93 } 94 } 95 96 pub fn clearGrid(self: *View) void { 97 self.center.clearGrid(); 98 } 99 100 pub fn getGrid(self: View) ?Grid { 101 return self.center.getGrid(); 102 } 103 104 pub fn getFocus(self: *View) *Focus { 105 return self.center.getFocus(); 106 } 107 108 pub fn getSelectedIndex(self: View) ?usize { 109 _ = self; 110 return 0; 111 } 112 }; 113