1
0
Fork 0

fix: correct text positioning

This commit is contained in:
LordMZTE 2024-01-13 13:23:19 +01:00
parent 8c859623a4
commit 48527a02e0
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 17 additions and 5 deletions

View file

@ -119,5 +119,5 @@ pub fn renderSize(self: Span) Size {
max.x = @max(max.x, glyph.position.x + glyph.glyph.size.width);
}
return max.sub(self.origin_off).size();
return max.size();
}

View file

@ -47,7 +47,10 @@ pub fn treevent(self: *Button, selfw: *Widget, tv: anytype) !void {
});
}
selfw.data.size = self.span.?.renderSize().add(layout.Size.two(style.padding * 2));
selfw.data.size = layout.Size.two(style.padding * 2).add(.{
.width = self.span.?.baseline_width,
.height = self.span.?.font.yOffset(self.span.?.style.size),
});
},
treev.Draw => {
@ -72,7 +75,10 @@ pub fn treevent(self: *Button, selfw: *Widget, tv: anytype) !void {
);
try tv.painter.span(
selfw.data.position.add(layout.Position.two(style.padding)),
selfw.data.position.add(layout.Position.two(style.padding)).add(.{
.x = 0,
.y = self.span.?.font.yOffset(self.span.?.style.size) - self.span.?.baseline_y,
}),
self.span.?,
);
},

View file

@ -33,10 +33,16 @@ pub fn deinit(self: *Label, selfw: *Widget) void {
pub fn treevent(self: *Label, selfw: *Widget, tv: anytype) !void {
switch (@TypeOf(tv)) {
treev.LayoutSize => {
selfw.data.size = tv.constraints.clamp(self.span.renderSize());
selfw.data.size = tv.constraints.clamp(.{
.width = self.span.baseline_width,
.height = self.span.font.yOffset(self.span.style.size),
});
},
treev.Draw => {
try tv.painter.span(selfw.data.position, self.span);
try tv.painter.span(selfw.data.position.add(.{
.x = 0,
.y = self.span.font.yOffset(self.span.style.size) - self.span.baseline_y,
}), self.span);
},
else => try tv.dispatch(selfw),
}