mirror of
https://github.com/fairyglade/ly.git
synced 2026-05-06 15:20:36 +00:00
Add Widget.calculateTimeout function
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -14,6 +14,7 @@ max_width: ?usize,
|
||||
fg: u32,
|
||||
bg: u32,
|
||||
update_fn: ?*const fn (*Label, *anyopaque) anyerror!void,
|
||||
calculate_timeout_fn: ?*const fn (*Label, *anyopaque) anyerror!?usize,
|
||||
component_pos: Position,
|
||||
children_pos: Position,
|
||||
|
||||
@@ -23,6 +24,7 @@ pub fn init(
|
||||
fg: u32,
|
||||
bg: u32,
|
||||
update_fn: ?*const fn (*Label, *anyopaque) anyerror!void,
|
||||
calculate_timeout_fn: ?*const fn (*Label, *anyopaque) anyerror!?usize,
|
||||
) Label {
|
||||
return .{
|
||||
.allocator = null,
|
||||
@@ -31,6 +33,7 @@ pub fn init(
|
||||
.fg = fg,
|
||||
.bg = bg,
|
||||
.update_fn = update_fn,
|
||||
.calculate_timeout_fn = calculate_timeout_fn,
|
||||
.component_pos = TerminalBuffer.START_POSITION,
|
||||
.children_pos = TerminalBuffer.START_POSITION,
|
||||
};
|
||||
@@ -49,6 +52,7 @@ pub fn widget(self: *Label) Widget {
|
||||
draw,
|
||||
update,
|
||||
null,
|
||||
calculateTimeout,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,3 +134,15 @@ fn update(self: *Label, ctx: *anyopaque) !void {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn calculateTimeout(self: *Label, ctx: *anyopaque) !?usize {
|
||||
if (self.calculate_timeout_fn) |calculate_timeout_fn| {
|
||||
return @call(
|
||||
.auto,
|
||||
calculate_timeout_fn,
|
||||
.{ self, ctx },
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user