mod(container/element): remove origin: Point argument from Element.content function
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m12s

Renamed `Container.contents` to `Container.content` to be in line with
the corresponding `Element` function name. This has also been done for
the properties structs used by the `Container`.
This commit is contained in:
2025-03-11 07:52:35 +01:00
parent adda53c5a9
commit dddc09b4ce
15 changed files with 37 additions and 56 deletions

View File

@@ -16,7 +16,7 @@ pub fn Element(Event: type) type {
resize: ?*const fn (ctx: *anyopaque, size: Point) void = null,
reposition: ?*const fn (ctx: *anyopaque, origin: Point) void = null,
handle: ?*const fn (ctx: *anyopaque, event: Event) anyerror!void = null,
content: ?*const fn (ctx: *anyopaque, cells: []Cell, origin: Point, size: Point) anyerror!void = null,
content: ?*const fn (ctx: *anyopaque, cells: []Cell, size: Point) anyerror!void = null,
};
/// Resize the corresponding `Element` with the given *size*.
@@ -58,9 +58,9 @@ pub fn Element(Event: type) type {
/// non-recoverable (i.e. an allocation error, system error, etc.).
/// Otherwise user specific errors should be caught using the `handle`
/// function before the rendering of the `Container` happens.
pub inline fn content(this: @This(), cells: []Cell, origin: Point, size: Point) !void {
pub inline fn content(this: @This(), cells: []Cell, size: Point) !void {
if (this.vtable.content) |content_fn|
try content_fn(this.ptr, cells, origin, size);
try content_fn(this.ptr, cells, size);
}
};
}
@@ -130,13 +130,13 @@ pub fn Scrollable(Event: type) type {
}
}
fn render_container(container: Container(Event), cells: []Cell, container_origin: Point, container_size: Point) !void {
fn render_container(container: Container(Event), cells: []Cell, container_size: Point) !void {
const size = container.size;
const origin = container.origin;
const contents = try container.contents();
const contents = try container.content();
defer container.allocator.free(contents);
const anchor = (@as(usize, origin.y -| container_origin.y) * @as(usize, container_size.x)) + @as(usize, origin.x -| container_origin.x);
const anchor = (@as(usize, origin.y) * @as(usize, container_size.x)) + @as(usize, origin.x);
var idx: usize = 0;
blk: for (0..size.y) |row| {
@@ -148,25 +148,23 @@ pub fn Scrollable(Event: type) type {
}
}
for (container.elements.items) |child| try render_container(child, cells, origin, size);
for (container.elements.items) |child| try render_container(child, cells, size);
}
fn content(ctx: *anyopaque, cells: []Cell, origin: Point, size: Point) !void {
fn content(ctx: *anyopaque, cells: []Cell, size: Point) !void {
const this: *@This() = @ptrCast(@alignCast(ctx));
_ = origin;
std.debug.assert(cells.len == @as(usize, this.size.x) * @as(usize, this.size.y));
const container_size = this.container.size;
const container_origin = this.container.origin;
const container_cells = try this.container.allocator.alloc(Cell, @as(usize, container_size.x) * @as(usize, container_size.y));
{
const container_cells_const = try this.container.contents();
const container_cells_const = try this.container.content();
defer this.container.allocator.free(container_cells_const);
std.debug.assert(container_cells_const.len == @as(usize, container_size.x) * @as(usize, container_size.y));
@memcpy(container_cells, container_cells_const);
}
for (this.container.elements.items) |child| try render_container(child, container_cells, container_origin, container_size);
for (this.container.elements.items) |child| try render_container(child, container_cells, container_size);
const anchor = (@as(usize, this.anchor.y) * @as(usize, container_size.x)) + @as(usize, this.anchor.x);
// TODO render scrollbar according to configuration!