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
commit 60e3380375
No known key found for this signature in database
15 changed files with 93 additions and 41 deletions

View file

@ -18,6 +18,7 @@ const Message = struct {
fg: u32,
};
instance: ?Widget = null,
label: *MessageLabel,
pub fn init(
@ -28,6 +29,7 @@ pub fn init(
arrow_bg: u32,
) !InfoLine {
return .{
.instance = null,
.label = try MessageLabel.init(
allocator,
buffer,
@ -46,8 +48,9 @@ pub fn deinit(self: *InfoLine) void {
self.label.deinit();
}
pub fn widget(self: *InfoLine) Widget {
return Widget.init(
pub fn widget(self: *InfoLine) *Widget {
if (self.instance) |*instance| return instance;
self.instance = Widget.init(
"InfoLine",
self.label.keybinds,
self,
@ -58,6 +61,7 @@ pub fn widget(self: *InfoLine) Widget {
handle,
null,
);
return &self.instance.?;
}
pub fn addMessage(self: *InfoLine, text: []const u8, bg: u32, fg: u32) !void {

View file

@ -18,6 +18,7 @@ const EnvironmentLabel = CyclableLabel(Env, *UserList);
const Session = @This();
instance: ?Widget = null,
label: *EnvironmentLabel,
user_list: *UserList,
@ -31,6 +32,7 @@ pub fn init(
bg: u32,
) !Session {
return .{
.instance = null,
.label = try EnvironmentLabel.init(
allocator,
buffer,
@ -55,8 +57,9 @@ pub fn deinit(self: *Session) void {
self.label.deinit();
}
pub fn widget(self: *Session) Widget {
return Widget.init(
pub fn widget(self: *Session) *Widget {
if (self.instance) |*instance| return instance;
self.instance = Widget.init(
"Session",
self.label.keybinds,
self,
@ -67,6 +70,7 @@ pub fn widget(self: *Session) Widget {
handle,
null,
);
return &self.instance.?;
}
pub fn addEnvironment(self: *Session, environment: Environment) !void {

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 {