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
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 35s
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user