╭ AuthTab.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const ui = @import("../ui.zig"); 3 const xit = @import("xit"); 4 const xitui = xit.xitui; 5 const wgt = xitui.widget; 6 const layout = xitui.layout; 7 const inp = xitui.input; 8 const Grid = xitui.grid.Grid; 9 const Focus = xitui.focus.Focus; 10 11 const Self = @This(); 12 13 pub const min_width: usize = "logout".len + 2; 14 15 pub fn init() Self { 16 return .{}; 17 } 18 19 pub const View = struct { 20 text_box: wgt.TextBox(ui.Widget), 21 data: *const Self, 22 session: *ui.Session, 23 24 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 25 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "login", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 26 errdefer text_box.deinit(allocator); 27 text_box.getFocus().focusable = true; 28 text_box.getFocus().kind = .{ .custom = "a:/auth" }; 29 return .{ 30 .text_box = text_box, 31 .data = data, 32 .session = session, 33 }; 34 } 35 36 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 37 self.text_box.deinit(allocator); 38 } 39 40 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 41 // update the displayed label based on session state. the inner Text 42 // widget's content is just a slice, so we can repoint it without 43 // re-allocating. 44 if (self.text_box.box.children.values().len > 0) { 45 const text_widget = &self.text_box.box.children.values()[0].widget.text; 46 text_widget.content = if (self.session.data.user_id != null) "logout" else "login"; 47 } 48 try self.text_box.build(allocator, constraint, root_focus); 49 } 50 51 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 52 try self.text_box.input(allocator, key, root_focus); 53 } 54 55 pub fn clearGrid(self: *View) void { 56 self.text_box.clearGrid(); 57 } 58 59 pub fn getGrid(self: View) ?Grid { 60 return self.text_box.getGrid(); 61 } 62 63 pub fn getFocus(self: *View) *Focus { 64 return self.text_box.getFocus(); 65 } 66 }; 67