╭ changed ─────────╮ │src/ui/AuthTab.zig│ ╰──────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────────────────────────────────╮ │ 9 const Focus = xitui.focus.Focus; │ │10 │ │11 const login_tab_label = "login"; │ │12 -const logout_tab_label = "logout";│ │12 │ │13 pub const View = struct { │ │14 text_box: wgt.TextBox, │ ╰──────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │15 session: *ui.Session, │ │17 - // backs the bottom label, which borrows it │ │18 - bottom_label_buf: [ui.clipped_bottom_label_max_len]u8, │ │16 │ │17 pub fn init(allocator: std.mem.Allocator, session: *ui.Session) !View { │ │18 var text_box = try wgt.TextBox.init(allocator, login_tab_label, .{ .border_style = .single, .round_corners = true, .wrap_kind = .none });│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────╮ │22 return .{ │ │23 .text_box = text_box, │ │24 .session = session, │ │28 - .bottom_label_buf = undefined,│ │25 }; │ │26 } │ │27 │ ╰──────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │29 self.text_box.deinit(allocator); │ │30 } │ │31 │ │32 + // the logged-in user's name, or the login label │ │33 fn text(self: *const View) []const u8 { │ │37 - return if (self.session.data.user_id == null) login_tab_label else logout_tab_label; │ │34 + if (self.session.data.user_id == null) return login_tab_label; │ │35 + return self.session.data.user_name orelse unreachable; │ │36 } │ │37 │ │40 - fn bottomLabel(self: *View) []const u8 { │ │41 - if (self.session.data.user_id == null) return ""; │ │42 - const name = self.session.data.user_name orelse return ""; │ │43 - return ui.clippedBottomLabel(&self.bottom_label_buf, name) catch unreachable; │ │38 + pub fn minWidth(self: *const View) usize { │ │39 + return self.text().len + 2; │ │40 } │ │41 │ │46 - pub fn minWidth(self: *View) usize { │ │47 - return @max(self.text().len, self.bottomLabel().len) + 2; │ │48 - } │ │49 - │ │42 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void {│ │43 try self.text_box.setContent(allocator, self.text()); │ │52 - self.text_box.options.bottom_label = self.bottomLabel(); │ │44 try self.text_box.build(allocator, constraint, root_focus); │ │45 } │ │46 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯