add(Layout/Padding): clear only when necessary
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 36s

This commit is contained in:
2024-11-13 16:10:25 +01:00
parent 270ca9b1be
commit 1e59a7c593
2 changed files with 8 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
const Events = std.ArrayList(Event);
return struct {
size: terminal.Size = undefined,
require_render: bool = false,
element: Element = undefined,
events: Events = undefined,
config: Config = undefined,
@@ -60,6 +61,7 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
switch (event) {
.resize => |size| {
this.size = size;
this.require_render = true;
log.debug("Event .resize: {{ .anchor = {{ .col = {d}, .row = {d} }}, .cols = {d}, .rows = {d} }}", .{
size.anchor.col,
size.anchor.row,
@@ -123,6 +125,11 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
}
pub fn render(this: *@This(), renderer: *Renderer) !void {
if (this.require_render) {
try renderer.clear(this.size);
this.require_render = false;
}
switch ((&this.element).*) {
.layout => |*layout| {
try layout.render(renderer);

View File

@@ -81,7 +81,7 @@ pub fn main() !void {
var padding = Layout.Padding.init(
allocator,
.{
.padding = 1,
.padding = 3,
},
.{
.layout = Layout.createFrom(vstack: {