It seems that this was caused by setting the `pos` to undefined, but all my code assumed that it was `.{0, 0}`.
This commit is contained in:
IntegratedQuantum 2023-10-25 11:40:51 +02:00
parent 420f727683
commit 49179d0891
2 changed files with 10 additions and 12 deletions

View File

@ -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 {

View File

@ -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 {