From c349a7ca82d97a5ae7094de0c63052598b20569f Mon Sep 17 00:00:00 2001 From: sirlilpanda Date: Sun, 10 May 2026 00:54:16 +1200 Subject: [PATCH] changes text size func to one function that includes a max witdth --- src/root.zig | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/root.zig b/src/root.zig index 8d57c45..cdb5702 100644 --- a/src/root.zig +++ b/src/root.zig @@ -22,18 +22,20 @@ const Spaceing = 4; pub fn TextType( comptime FontType: type, - comptime getTextWidthFunc: fn (string: []const u8, FontType) Real, - comptime getTextHeightFunc: fn (string: []const u8, FontType) Real, + comptime getTextSizeFunc: fn (string: []const u8, FontType, max_width: ?Real) Rect, ) type { return struct { - const Optional = struct { - font: FontType, - }; + // const Optional = struct { + // font: FontType, + // }; const Self = @This(); string: []const u8, colour: Colour, background: Colour, font: FontType, + /// this lib just cares about rendering some text + /// text wrapping is your job SDL3 ttf does it :D + max_width: ?Real = null, pub fn init(string: []const u8, font: FontType, colour: Colour) Self { return Self{ @@ -55,12 +57,8 @@ pub fn TextType( return s; } - pub fn getTextWidth(self: Self) Real { - return getTextWidthFunc(self.string, self.font); - } - - pub fn getTextHeight(self: Self) Real { - return getTextHeightFunc(self.string, self.font); + pub fn getTextSize(self: Self) Rect { + return getTextSizeFunc(self.string, self.font, self.max_width); } }; } @@ -419,9 +417,11 @@ pub fn Shoots( } }, .text => { - parent.element.rect.h += node.text.getTextHeight(); + const text_size: Rect = node.text.getTextSize(); + + parent.element.rect.h += text_size.h; // std.debug.print("parent.element.rect.h : {}\n", .{parent.element.rect.h}); - parent.element.rect.w += node.text.getTextWidth(); + parent.element.rect.w += text_size.w; // std.debug.print("parent.element.rect.w : {}\n", .{parent.element.rect.w}); }, .texture => {