╭ 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 fn init() Self { 14 return .{}; 15 } 16 17 pub const View = struct { 18 text_box: wgt.TextBox(ui.Widget), 19 data: *const Self, 20 session: *ui.Session, 21 22 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 23 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "login", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 24 errdefer text_box.deinit(allocator); 25 text_box.getFocus().focusable = true; 26 return .{ 27 .text_box = text_box, 28 .data = data, 29 .session = session, 30 }; 31 } 32 33 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 34 self.text_box.deinit(allocator); 35 } 36 37 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 38 // update the displayed label based on session state. the inner Text 39 // widget's content is just a slice, so we can repoint it without 40 // re-allocating. 41 if (self.text_box.box.children.values().len > 0) { 42 const text_widget = &self.text_box.box.children.values()[0].widget.text; 43 text_widget.content = if (self.session.data.user_id != null) "logout" else "login"; 44 } 45 try self.text_box.build(allocator, constraint, root_focus); 46 } 47 48 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 49 try self.text_box.input(allocator, key, root_focus); 50 } 51 52 pub fn clearGrid(self: *View) void { 53 self.text_box.clearGrid(); 54 } 55 56 pub fn getGrid(self: View) ?Grid { 57 return self.text_box.getGrid(); 58 } 59 60 pub fn getFocus(self: *View) *Focus { 61 return self.text_box.getFocus(); 62 } 63 }; 64