From 7ff787f71fe211c4c8341280cad14618195a98d5 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Wed, 22 Oct 2025 14:35:35 +0200 Subject: [PATCH] separate font module and font now allocates in arena --- lib/ugui.c3l/src/font.c3 | 13 ++++++++----- src/main.c3 | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/ugui.c3l/src/font.c3 b/lib/ugui.c3l/src/font.c3 index 90be1c1..46ef15c 100644 --- a/lib/ugui.c3l/src/font.c3 +++ b/lib/ugui.c3l/src/font.c3 @@ -1,4 +1,4 @@ -module ugui; +module ugui::font; import schrift; import std::collections::map; @@ -74,9 +74,9 @@ macro Rect Glyph.uv(&g) => {.x = g.u, .y = g.v, .w = g.w, .h = g.h}; @param [&in] path @require height > 0, scale > 0: "height and scale must be positive non-zero" *> -fn void? Font.load(&font, String name, ZString path, uint height, float scale) +fn void? Font.load(&font, Allocator allocator, String name, ZString path, uint height, float scale) { - font.table.init(allocator::mem, capacity: FONT_CACHED); + font.table.init(allocator, capacity: FONT_CACHED); font.id = name.hash(); font.size = height*scale; @@ -128,6 +128,7 @@ fn Glyph*? Font.get_glyph(&font, Codepoint code) return gp; } + // missing glyph, render and place into an atlas Glyph glyph; @@ -188,15 +189,17 @@ fn void Font.free(&font) // FONT LOAD AND QUERY // // ---------------------------------------------------------------------------------- // +module ugui; + <* @param [&inout] ctx @param [in] name @param [&in] path @require height > 0, scale > 0: "height and scale must be positive non-zero" *> -fn void? Ctx.load_font(&ctx, String name, ZString path, uint height, float scale = 1.0) +fn void? Ctx.load_font(&ctx, Allocator allocator, String name, ZString path, uint height, float scale = 1.0) { - return ctx.font.load(name, path, height, scale); + return ctx.font.load(allocator, name, path, height, scale); } <* diff --git a/src/main.c3 b/src/main.c3 index 431f74d..ce62be5 100644 --- a/src/main.c3 +++ b/src/main.c3 @@ -74,7 +74,7 @@ fn int main(String[] args) // FONT LOADING // // ========================================================================================== // // import font in the ui context - ui.load_font("font1", "resources/hack-nerd.ttf", 16)!!; + ui.load_font(&arena, "font1", "resources/hack-nerd.ttf", 16)!!; // set the renderer's font atlas ren.font_atlas_id = ui.get_font_id("font1");