mod(renderer): dynamic clear of size for widgets to improve render performance
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 35s

This commit is contained in:
2024-11-13 15:07:26 +01:00
parent 80459a51b1
commit 270ca9b1be
4 changed files with 39 additions and 14 deletions

View File

@@ -12,6 +12,7 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
}
return struct {
size: terminal.Size = undefined,
size_changed: bool = false,
pub fn init() @This() {
return .{};
@@ -25,6 +26,7 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
switch (event) {
.resize => |size| {
this.size = size;
this.size_changed = true;
},
else => {},
}
@@ -32,7 +34,10 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
}
pub fn render(this: *@This(), renderer: *Renderer) !void {
try renderer.clear(this.size);
if (this.size_changed) {
try renderer.clear(this.size);
this.size_changed = false;
}
}
};
}