mod: change interface for rendering of Layouts and Widgets to use a non-const pointer to the renderer instead
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 38s

This commit is contained in:
2024-11-11 13:47:01 +01:00
parent 8b3f863404
commit d2d655c829
10 changed files with 23 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
//! Dynamic dispatch for layout implementations.
//! Each layout should at last implement these functions:
//! - handle(this: *@This(), event: Event) anyerror!*std.ArrayList(Event) {}
//! - render(this: *@This(), renderer: Renderer) anyerror!void {}
//! - render(this: *@This(), renderer: *Renderer) anyerror!void {}
//! - deinit(this: *@This()) void {}
//!
//! Create a `Layout` using `createFrom(object: anytype)` and use them through
@@ -28,7 +28,7 @@ pub fn Layout(comptime Event: type, comptime Renderer: type) type {
const VTable = struct {
handle: *const fn (this: *LayoutType, event: Event) anyerror!*Events,
render: *const fn (this: *LayoutType, renderer: Renderer) anyerror!void,
render: *const fn (this: *LayoutType, renderer: *Renderer) anyerror!void,
deinit: *const fn (this: *LayoutType) void,
};
@@ -41,7 +41,7 @@ pub fn Layout(comptime Event: type, comptime Renderer: type) type {
}
// Render this `Layout` completely. This will render contained sub-elements too.
pub fn render(this: *LayoutType, renderer: Renderer) !void {
pub fn render(this: *LayoutType, renderer: *Renderer) !void {
return try this.vtable.render(this, renderer);
}
@@ -63,7 +63,7 @@ pub fn Layout(comptime Event: type, comptime Renderer: type) type {
}.handle,
.render = struct {
// Render the contents of this `Layout`.
fn render(this: *LayoutType, renderer: Renderer) !void {
fn render(this: *LayoutType, renderer: *Renderer) !void {
const layout: @TypeOf(object) = @ptrFromInt(this.object);
try layout.render(renderer);
}