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);
|
const Events = std.ArrayList(Event);
|
||||||
return struct {
|
return struct {
|
||||||
size: terminal.Size = undefined,
|
size: terminal.Size = undefined,
|
||||||
|
require_render: bool = false,
|
||||||
element: Element = undefined,
|
element: Element = undefined,
|
||||||
events: Events = undefined,
|
events: Events = undefined,
|
||||||
config: Config = undefined,
|
config: Config = undefined,
|
||||||
@@ -60,6 +61,7 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
switch (event) {
|
switch (event) {
|
||||||
.resize => |size| {
|
.resize => |size| {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
|
this.require_render = true;
|
||||||
log.debug("Event .resize: {{ .anchor = {{ .col = {d}, .row = {d} }}, .cols = {d}, .rows = {d} }}", .{
|
log.debug("Event .resize: {{ .anchor = {{ .col = {d}, .row = {d} }}, .cols = {d}, .rows = {d} }}", .{
|
||||||
size.anchor.col,
|
size.anchor.col,
|
||||||
size.anchor.row,
|
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 {
|
pub fn render(this: *@This(), renderer: *Renderer) !void {
|
||||||
|
if (this.require_render) {
|
||||||
|
try renderer.clear(this.size);
|
||||||
|
this.require_render = false;
|
||||||
|
}
|
||||||
|
|
||||||
switch ((&this.element).*) {
|
switch ((&this.element).*) {
|
||||||
.layout => |*layout| {
|
.layout => |*layout| {
|
||||||
try layout.render(renderer);
|
try layout.render(renderer);
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ pub fn main() !void {
|
|||||||
var padding = Layout.Padding.init(
|
var padding = Layout.Padding.init(
|
||||||
allocator,
|
allocator,
|
||||||
.{
|
.{
|
||||||
.padding = 1,
|
.padding = 3,
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.layout = Layout.createFrom(vstack: {
|
.layout = Layout.createFrom(vstack: {
|
||||||
|
|||||||
Reference in New Issue
Block a user