From 49179d08910f4b14f8f1cb0875498f1f64a3e95c Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Wed, 25 Oct 2023 11:40:51 +0200 Subject: [PATCH] Fix #151 It seems that this was caused by setting the `pos` to undefined, but all my code assumed that it was `.{0, 0}`. --- src/gui/components/HorizontalList.zig | 11 +++++------ src/gui/components/VerticalList.zig | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/gui/components/HorizontalList.zig b/src/gui/components/HorizontalList.zig index 9722800f..cf5b2003 100644 --- a/src/gui/components/HorizontalList.zig +++ b/src/gui/components/HorizontalList.zig @@ -21,7 +21,7 @@ pub fn init() Allocator.Error!*HorizontalList { const self = try main.globalAllocator.create(HorizontalList); self.* = HorizontalList { .children = std.ArrayList(GuiComponent).init(main.globalAllocator), - .pos = undefined, + .pos = .{0, 0}, .size = .{0, 0}, }; return self; @@ -48,11 +48,10 @@ pub fn add(self: *HorizontalList, _other: anytype) Allocator.Error!void { } else { other = _other.toComponent(); } - const added = try self.children.addOne(); - added.* = other; - added.mutPos().*[0] += self.size[0]; - self.size[0] = added.pos()[0] + added.size()[0]; - self.size[1] = @max(self.size[1], added.pos()[1] + added.size()[1]); + other.mutPos().*[0] += self.size[0]; + self.size[0] = other.pos()[0] + other.size()[0]; + self.size[1] = @max(self.size[1], other.pos()[1] + other.size()[1]); + try self.children.append(other); } pub fn finish(self: *HorizontalList, pos: Vec2f, alignment: graphics.TextBuffer.Alignment) void { diff --git a/src/gui/components/VerticalList.zig b/src/gui/components/VerticalList.zig index f25a9093..2d85ccc8 100644 --- a/src/gui/components/VerticalList.zig +++ b/src/gui/components/VerticalList.zig @@ -62,12 +62,11 @@ pub fn add(self: *VerticalList, _other: anytype) Allocator.Error!void { } else { other = _other.toComponent(); } - const added = try self.children.addOne(); - added.* = other; - added.mutPos().*[1] += self.size[1]; - if(self.size[1] != 0) added.mutPos().*[1] += self.padding; - self.size[1] = added.pos()[1] + added.size()[1]; - self.size[0] = @max(self.size[0], added.pos()[0] + added.size()[0]); + other.mutPos().*[1] += self.size[1]; + if(self.size[1] != 0) other.mutPos().*[1] += self.padding; + self.size[1] = other.pos()[1] + other.size()[1]; + self.size[0] = @max(self.size[0], other.pos()[0] + other.size()[0]); + try self.children.append(other); } pub fn finish(self: *VerticalList, alignment: graphics.TextBuffer.Alignment) void {