Switch to single-instance Widget model

And make widget() functions return pointers to widgets instead of just
widgets

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2026-03-21 16:19:33 +01:00
parent aa392837bc
commit 60e3380375
15 changed files with 93 additions and 41 deletions

View File

@@ -21,6 +21,7 @@ const UserLabel = CyclableLabel(User, *Session);
const UserList = @This();
instance: ?Widget = null,
label: *UserLabel,
pub fn init(
@@ -35,6 +36,7 @@ pub fn init(
bg: u32,
) !UserList {
var user_list = UserList{
.instance = null,
.label = try UserLabel.init(
allocator,
buffer,
@@ -89,8 +91,9 @@ pub fn deinit(self: *UserList) void {
self.label.deinit();
}
pub fn widget(self: *UserList) Widget {
return Widget.init(
pub fn widget(self: *UserList) *Widget {
if (self.instance) |*instance| return instance;
self.instance = Widget.init(
"UserList",
self.label.keybinds,
self,
@@ -101,6 +104,7 @@ pub fn widget(self: *UserList) Widget {
handle,
null,
);
return &self.instance.?;
}
pub fn getCurrentUsername(self: UserList) []const u8 {