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
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 36s
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -81,7 +81,7 @@ pub fn main() !void {
|
||||
var padding = Layout.Padding.init(
|
||||
allocator,
|
||||
.{
|
||||
.padding = 1,
|
||||
.padding = 3,
|
||||
},
|
||||
.{
|
||||
.layout = Layout.createFrom(vstack: {
|
||||
|
||||
Reference in New Issue
Block a user