╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ AuthTab.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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