feat(element): parameter *const App.Model
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 55s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 55s
The renderer will provide `resize`, `reposition` and `minSize` (for the `Scrollable` `Element`) with a read-only pointer to the model of the application (similar to how it is already done for `handle` and `content`). Every interface function now has the same data that it can each use for implementing its corresponding task based on local and shared variables through the element instance and model pointer.
This commit is contained in:
@@ -654,10 +654,10 @@ pub fn Container(Model: type, Event: type) type {
|
||||
try this.elements.append(this.allocator, element);
|
||||
}
|
||||
|
||||
pub fn reposition(this: *@This(), origin: Point) void {
|
||||
pub fn reposition(this: *@This(), model: *const Model, origin: Point) void {
|
||||
const layout = this.properties.layout;
|
||||
this.origin = origin;
|
||||
this.element.reposition(origin);
|
||||
this.element.reposition(model, origin);
|
||||
|
||||
var offset = origin.add(.{
|
||||
.x = Layout.getAbsolutePadding(layout.padding.left, this.size.x),
|
||||
@@ -669,7 +669,7 @@ pub fn Container(Model: type, Event: type) type {
|
||||
if (sides.top) offset.y += 1;
|
||||
|
||||
for (this.elements.items) |*child| {
|
||||
child.reposition(offset);
|
||||
child.reposition(model, offset);
|
||||
|
||||
switch (layout.direction) {
|
||||
.horizontal => offset.x += child.size.x + layout.gap,
|
||||
@@ -739,7 +739,7 @@ pub fn Container(Model: type, Event: type) type {
|
||||
}
|
||||
|
||||
/// growable implicitly requires the root `Container` to have a set a size property to the size of the available terminal screen
|
||||
fn grow_resize(this: *@This(), max_size: Point) void {
|
||||
fn grow_resize(this: *@This(), model: *const Model, max_size: Point) void {
|
||||
const layout = this.properties.layout;
|
||||
var remainder = switch (layout.direction) {
|
||||
.horizontal => max_size.x -| (Layout.getAbsolutePadding(layout.padding.left, this.size.x) + Layout.getAbsolutePadding(layout.padding.right, this.size.x)),
|
||||
@@ -881,11 +881,11 @@ pub fn Container(Model: type, Event: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
this.element.resize(this.size);
|
||||
for (this.elements.items) |*child| child.grow_resize(child.size);
|
||||
this.element.resize(model, this.size);
|
||||
for (this.elements.items) |*child| child.grow_resize(model, child.size);
|
||||
}
|
||||
|
||||
pub fn resize(this: *@This(), size: Point) void {
|
||||
pub fn resize(this: *@This(), model: *const Model, size: Point) void {
|
||||
// NOTE assume that this function is only called for the root `Container`
|
||||
this.size = size;
|
||||
const fit_size = this.fit_resize();
|
||||
@@ -902,7 +902,7 @@ pub fn Container(Model: type, Event: type) type {
|
||||
.y = @max(size.y, fit_size.y),
|
||||
},
|
||||
}
|
||||
this.grow_resize(this.size);
|
||||
this.grow_resize(model, this.size);
|
||||
}
|
||||
|
||||
pub fn handle(this: *const @This(), model: *Model, event: Event) !void {
|
||||
|
||||
Reference in New Issue
Block a user