changes text size func to one function that includes a max witdth
This commit is contained in:
26
src/root.zig
26
src/root.zig
@@ -22,18 +22,20 @@ const Spaceing = 4;
|
|||||||
|
|
||||||
pub fn TextType(
|
pub fn TextType(
|
||||||
comptime FontType: type,
|
comptime FontType: type,
|
||||||
comptime getTextWidthFunc: fn (string: []const u8, FontType) Real,
|
comptime getTextSizeFunc: fn (string: []const u8, FontType, max_width: ?Real) Rect,
|
||||||
comptime getTextHeightFunc: fn (string: []const u8, FontType) Real,
|
|
||||||
) type {
|
) type {
|
||||||
return struct {
|
return struct {
|
||||||
const Optional = struct {
|
// const Optional = struct {
|
||||||
font: FontType,
|
// font: FontType,
|
||||||
};
|
// };
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
string: []const u8,
|
string: []const u8,
|
||||||
colour: Colour,
|
colour: Colour,
|
||||||
background: Colour,
|
background: Colour,
|
||||||
font: FontType,
|
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 {
|
pub fn init(string: []const u8, font: FontType, colour: Colour) Self {
|
||||||
return Self{
|
return Self{
|
||||||
@@ -55,12 +57,8 @@ pub fn TextType(
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getTextWidth(self: Self) Real {
|
pub fn getTextSize(self: Self) Rect {
|
||||||
return getTextWidthFunc(self.string, self.font);
|
return getTextSizeFunc(self.string, self.font, self.max_width);
|
||||||
}
|
|
||||||
|
|
||||||
pub fn getTextHeight(self: Self) Real {
|
|
||||||
return getTextHeightFunc(self.string, self.font);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -419,9 +417,11 @@ pub fn Shoots(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
.text => {
|
.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});
|
// 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});
|
// std.debug.print("parent.element.rect.w : {}\n", .{parent.element.rect.w});
|
||||||
},
|
},
|
||||||
.texture => {
|
.texture => {
|
||||||
|
|||||||
Reference in New Issue
Block a user