mod: replace Layout.content with Layout.render
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 30s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 30s
The App.Renderer is used for the new `Layout.render` method. Each layout renders itself now with corresponding renderers which might only update parts of the screen, etc.
This commit is contained in:
@@ -11,32 +11,28 @@ const Key = terminal.Key;
|
||||
|
||||
const log = std.log.scoped(.layout_framing);
|
||||
|
||||
pub fn Layout(comptime Event: type) type {
|
||||
pub fn Layout(comptime Event: type, comptime Renderer: type) type {
|
||||
if (!isTaggedUnion(Event)) {
|
||||
@compileError("Provided user event `Event` for `Layout(comptime Event: type)` is not of type `union(enum)`.");
|
||||
}
|
||||
const Element = union(enum) {
|
||||
layout: @import("../layout.zig").Layout(Event),
|
||||
layout: @import("../layout.zig").Layout(Event, Renderer),
|
||||
widget: @import("../widget.zig").Widget(Event),
|
||||
};
|
||||
const Events = std.ArrayList(Event);
|
||||
const Contents = std.ArrayList(u8);
|
||||
return struct {
|
||||
size: terminal.Size = undefined,
|
||||
contents: Contents = undefined,
|
||||
element: Element = undefined,
|
||||
events: Events = undefined,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, element: Element) @This() {
|
||||
return .{
|
||||
.contents = Contents.init(allocator),
|
||||
.element = element,
|
||||
.events = Events.init(allocator),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(this: *@This()) void {
|
||||
this.contents.deinit();
|
||||
this.events.deinit();
|
||||
switch ((&this.element).*) {
|
||||
.layout => |*layout| {
|
||||
@@ -85,19 +81,18 @@ pub fn Layout(comptime Event: type) type {
|
||||
return &this.events;
|
||||
}
|
||||
|
||||
pub fn content(this: *@This()) !*Contents {
|
||||
this.contents.clearRetainingCapacity();
|
||||
pub fn render(this: *@This(), renderer: Renderer) !void {
|
||||
// TODO: padding contents accordingly
|
||||
switch ((&this.element).*) {
|
||||
.layout => |*layout| {
|
||||
const layout_content = try layout.content();
|
||||
try this.contents.appendSlice(layout_content.items);
|
||||
try layout.render(renderer);
|
||||
},
|
||||
.widget => |*widget| {
|
||||
try this.contents.appendSlice(try widget.content());
|
||||
const content = try widget.content();
|
||||
// TODO: use renderer
|
||||
_ = try terminal.write(content);
|
||||
},
|
||||
}
|
||||
return &this.contents;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user