mirror of
https://github.com/fairyglade/ly.git
synced 2026-05-07 07:40:35 +00:00
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:
@@ -44,6 +44,7 @@ pub const BigLabelLocale = enum {
|
||||
fa,
|
||||
};
|
||||
|
||||
instance: ?Widget = null,
|
||||
allocator: ?Allocator = null,
|
||||
buffer: *TerminalBuffer,
|
||||
text: []const u8,
|
||||
@@ -67,6 +68,7 @@ pub fn init(
|
||||
calculate_timeout_fn: ?*const fn (*BigLabel, *anyopaque) anyerror!?usize,
|
||||
) BigLabel {
|
||||
return .{
|
||||
.instance = null,
|
||||
.allocator = null,
|
||||
.buffer = buffer,
|
||||
.text = text,
|
||||
@@ -85,8 +87,9 @@ pub fn deinit(self: *BigLabel) void {
|
||||
if (self.allocator) |allocator| allocator.free(self.text);
|
||||
}
|
||||
|
||||
pub fn widget(self: *BigLabel) Widget {
|
||||
return Widget.init(
|
||||
pub fn widget(self: *BigLabel) *Widget {
|
||||
if (self.instance) |*instance| return instance;
|
||||
self.instance = Widget.init(
|
||||
"BigLabel",
|
||||
null,
|
||||
self,
|
||||
@@ -97,6 +100,7 @@ pub fn widget(self: *BigLabel) Widget {
|
||||
null,
|
||||
calculateTimeout,
|
||||
);
|
||||
return &self.instance.?;
|
||||
}
|
||||
|
||||
pub fn setTextAlloc(
|
||||
|
||||
Reference in New Issue
Block a user