╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Quit.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
3 const inp = @import("./input.zig"); 4 const xit = @import("xit"); 5 const xitui = xit.xitui; 6 const wgt = xitui.widget; 7 const layout = xitui.layout; 8 const Key = xitui.input.Key; 9 const Grid = xitui.grid.Grid; 10 const Focus = xitui.focus.Focus; 11 12 const Self = @This(); 13 14 // focus kind marking the header's quit tab 15 pub const tab_kind = "quit"; 16 17 // label shown on the header's quit tab (a single-column box-drawing cross) 18 pub const tab_label = "╳"; 19 20 pub fn init() Self { 21 return .{}; 22 } 23 24 pub const View = struct { 25 center: ui.widget.Center, 26 session: *ui.Session, 27 button_id: usize, 28 29 pub fn init(allocator: std.mem.Allocator, session: *ui.Session) !View { 30 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .round_corners = true, .direction = .vert }); 31 errdefer box.deinit(allocator); 32 33 { 34 var prompt = try wgt.Text.init(allocator, "are you sure?"); 35 errdefer prompt.deinit(allocator); 36 try box.children.put(allocator, prompt.getFocus().id, .{ 37 .widget = .{ .text = prompt }, 38 .rect = null, 39 .min_size = null, 40 }); 41 } 42 43 var button_id: usize = undefined; 44 { 45 var button = try wgt.TextBox.init(allocator, "quit", .{ .border = .single, .round_corners = true, .wrap_kind = .none }); 46 errdefer button.deinit(allocator); 47 button.getFocus().mode = .all; 48 button_id = button.getFocus().id; 49 try box.children.put(allocator, button.getFocus().id, .{ 50 .widget = .{ .text_box = button }, 51 .rect = null, 52 .min_size = null, 53 }); 54 } 55 56 box.getFocus().child_id = button_id; 57 58 return .{ 59 .center = try ui.widget.Center.init(allocator, .{ .box = box }), 60 .session = session, 61 .button_id = button_id, 62 }; 63 } 64 65 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 66 self.center.deinit(allocator); 67 } 68 69 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 70 try self.center.build(allocator, constraint, root_focus); 71 } 72 73 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 74 _ = allocator; 75 switch (key) { 76 .enter => { 77 self.session.quit_requested = true; 78 return; 79 }, 80 .mouse => |mouse| { 81 if (inp.leftClickOn(root_focus, self.button_id, mouse)) { 82 self.session.quit_requested = true; 83 return; 84 } 85 }, 86 else => {}, 87 } 88 } 89 90 pub fn clearGrid(self: *View) void { 91 self.center.clearGrid(); 92 } 93 94 pub fn getGrid(self: View) ?Grid { 95 return self.center.getGrid(); 96 } 97 98 pub fn getFocus(self: *View) *Focus { 99 return self.center.getFocus(); 100 } 101 102 pub fn atTop(self: View) bool { 103 _ = self; 104 return true; 105 } 106 }; 107