mirror of
https://github.com/fairyglade/ly.git
synced 2026-03-25 01:36:05 +00:00
Add Widget.calculateTimeout function
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -9,6 +9,7 @@ const VTable = struct {
|
||||
draw_fn: *const fn (ptr: *anyopaque) void,
|
||||
update_fn: ?*const fn (ptr: *anyopaque, ctx: *anyopaque) anyerror!void,
|
||||
handle_fn: ?*const fn (ptr: *anyopaque, maybe_key: ?keyboard.Key, insert_mode: bool) anyerror!void,
|
||||
calculate_timeout_fn: ?*const fn (ptr: *anyopaque, ctx: *anyopaque) anyerror!?usize,
|
||||
};
|
||||
|
||||
id: u64,
|
||||
@@ -24,6 +25,7 @@ pub fn init(
|
||||
comptime draw_fn: fn (ptr: @TypeOf(pointer)) void,
|
||||
comptime update_fn: ?fn (ptr: @TypeOf(pointer), ctx: *anyopaque) anyerror!void,
|
||||
comptime handle_fn: ?fn (ptr: @TypeOf(pointer), maybe_key: ?keyboard.Key, insert_mode: bool) anyerror!void,
|
||||
comptime calculate_timeout_fn: ?fn (ptr: @TypeOf(pointer), ctx: *anyopaque) anyerror!?usize,
|
||||
) Widget {
|
||||
const Pointer = @TypeOf(pointer);
|
||||
const Impl = struct {
|
||||
@@ -77,12 +79,23 @@ pub fn init(
|
||||
);
|
||||
}
|
||||
|
||||
pub fn calculateTimeoutImpl(ptr: *anyopaque, ctx: *anyopaque) !?usize {
|
||||
const impl: Pointer = @ptrCast(@alignCast(ptr));
|
||||
|
||||
return @call(
|
||||
.always_inline,
|
||||
calculate_timeout_fn.?,
|
||||
.{ impl, ctx },
|
||||
);
|
||||
}
|
||||
|
||||
const vtable = VTable{
|
||||
.deinit_fn = if (deinit_fn != null) deinitImpl else null,
|
||||
.realloc_fn = if (realloc_fn != null) reallocImpl else null,
|
||||
.draw_fn = drawImpl,
|
||||
.update_fn = if (update_fn != null) updateImpl else null,
|
||||
.handle_fn = if (handle_fn != null) handleImpl else null,
|
||||
.calculate_timeout_fn = if (calculate_timeout_fn != null) calculateTimeoutImpl else null,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -151,3 +164,17 @@ pub fn handle(self: *Widget, maybe_key: ?keyboard.Key, insert_mode: bool) !void
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn calculateTimeout(self: *Widget, ctx: *anyopaque) !?usize {
|
||||
const impl: @TypeOf(self.pointer) = @ptrCast(@alignCast(self.pointer));
|
||||
|
||||
if (self.vtable.calculate_timeout_fn) |calculate_timeout_fn| {
|
||||
return @call(
|
||||
.auto,
|
||||
calculate_timeout_fn,
|
||||
.{ impl, ctx },
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user