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
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 38s
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//! Dynamic dispatch for widget implementations.
|
||||
//! Each widget should at last implement these functions:
|
||||
//! - handle(this: *@This(), event: Event) ?Event {}
|
||||
//! - render(this: *@This(), renderer: Renderer) !void {}
|
||||
//! - render(this: *@This(), renderer: *Renderer) !void {}
|
||||
//! - deinit(this: *@This()) void {}
|
||||
//!
|
||||
//! Create a `Widget` using `createFrom(object: anytype)` and use them through
|
||||
@@ -27,7 +27,7 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
|
||||
|
||||
const VTable = struct {
|
||||
handle: *const fn (this: *WidgetType, event: Event) ?Event,
|
||||
render: *const fn (this: *WidgetType, renderer: Renderer) anyerror!void,
|
||||
render: *const fn (this: *WidgetType, renderer: *Renderer) anyerror!void,
|
||||
deinit: *const fn (this: *WidgetType) void,
|
||||
};
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
|
||||
}
|
||||
|
||||
// Render the content of this `Widget` given the `Size` of the widget (.resize System`Event`).
|
||||
pub fn render(this: *WidgetType, renderer: Renderer) !void {
|
||||
pub fn render(this: *WidgetType, renderer: *Renderer) !void {
|
||||
try this.vtable.render(this, renderer);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
|
||||
}.handle,
|
||||
.render = struct {
|
||||
// Return the entire content of this `Widget`.
|
||||
fn render(this: *WidgetType, renderer: Renderer) !void {
|
||||
fn render(this: *WidgetType, renderer: *Renderer) !void {
|
||||
const widget: @TypeOf(object) = @ptrFromInt(this.object);
|
||||
try widget.render(renderer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user