From ba01bf00bbef6addeab441f873af2e69018ae2cd Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Sat, 9 Nov 2024 01:52:37 +0100 Subject: [PATCH] mod(pane) example layout pane has top and bottom empty row Fix corresponding RawText line control (i.e. last line and changes to the window size in regards to the current line). --- src/layout/Pane.zig | 3 +-- src/widget/RawText.zig | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/layout/Pane.zig b/src/layout/Pane.zig index 8f15b59..ceaf0ef 100644 --- a/src/layout/Pane.zig +++ b/src/layout/Pane.zig @@ -54,10 +54,9 @@ pub fn Layout(comptime Event: type) type { } pub fn content(this: *@This()) !*std.ArrayList(u8) { - const widget_content = try this.widget.content(); this.c.clearRetainingCapacity(); try this.c.appendSlice("\n"); - try this.c.appendSlice(widget_content); + try this.c.appendSlice(try this.widget.content()); try this.c.appendSlice("\n"); return &this.c; } diff --git a/src/widget/RawText.zig b/src/widget/RawText.zig index 7814b46..90f07c3 100644 --- a/src/widget/RawText.zig +++ b/src/widget/RawText.zig @@ -39,6 +39,9 @@ pub fn Widget(comptime Event: type) type { // store the received size .resize => |size| { this.size = size; + if (this.line > this.line_index.items.len - 1 - size.rows) { + this.line = this.line_index.items.len - 1 - size.rows; + } }, .key => |key| { if (key.matches(.{ .cp = 'g' })) { @@ -47,11 +50,11 @@ pub fn Widget(comptime Event: type) type { } if (key.matches(.{ .cp = 'G' })) { // bottom - this.line = this.line_index.items.len - 1; + this.line = this.line_index.items.len - 1 - this.size.rows; } if (key.matches(.{ .cp = 'j' })) { // down - if (this.line < this.line_index.items.len - 1) { + if (this.line < this.line_index.items.len - 1 - this.size.rows) { this.line +|= 1; } }