From c4a3dd3a26c583250c96e3acd2e6ce900bd15c5c Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Thu, 12 Jun 2025 18:56:57 +0200 Subject: [PATCH] tweak ugui api, add some usefult functions --- lib/ugui.c3l/src/ugui_core.c3 | 2 +- lib/ugui.c3l/src/ugui_font.c3 | 10 ++++++++++ lib/ugui.c3l/src/ugui_shapes.c3 | 8 +++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/ugui.c3l/src/ugui_core.c3 b/lib/ugui.c3l/src/ugui_core.c3 index a1c7e2b..efa804c 100644 --- a/lib/ugui.c3l/src/ugui_core.c3 +++ b/lib/ugui.c3l/src/ugui_core.c3 @@ -62,7 +62,7 @@ alias ElemCache = cache::Cache{Id, Elem, MAX_ELEMENTS}; alias CmdQueue = fifo::Fifo{Cmd}; -faultdef INVALID_SIZE, EVENT_UNSUPPORTED, UNEXPECTED_ELEMENT, WRONG_ELEMENT_TYPE; +faultdef INVALID_SIZE, EVENT_UNSUPPORTED, UNEXPECTED_ELEMENT, WRONG_ELEMENT_TYPE, WRONG_ID; const Rect DIV_FILL = { .x = 0, .y = 0, .w = 0, .h = 0 }; diff --git a/lib/ugui.c3l/src/ugui_font.c3 b/lib/ugui.c3l/src/ugui_font.c3 index 5afe033..23700c6 100644 --- a/lib/ugui.c3l/src/ugui_font.c3 +++ b/lib/ugui.c3l/src/ugui_font.c3 @@ -224,3 +224,13 @@ fn Id Ctx.get_font_id(&ctx, String label) { return (Id)label.hash(); } + +fn Atlas*? Ctx.get_font_atlas(&ctx, String name) +{ + // TODO: use the font name, for now there is only one font + if (name.hash() != ctx.font.id) { + return WRONG_ID?; + } + + return &ctx.font.atlas; +} diff --git a/lib/ugui.c3l/src/ugui_shapes.c3 b/lib/ugui.c3l/src/ugui_shapes.c3 index ebef525..1bfb00a 100644 --- a/lib/ugui.c3l/src/ugui_shapes.c3 +++ b/lib/ugui.c3l/src/ugui_shapes.c3 @@ -193,7 +193,7 @@ struct Color{ char r, g, b, a; } -macro Color uint.to_rgba(uint u) +macro Color uint.to_rgba(u) { return { .r = (char)((u >> 24) & 0xff), @@ -202,3 +202,9 @@ macro Color uint.to_rgba(uint u) .a = (char)((u >> 0) & 0xff) }; } + +macro uint Color.to_uint(c) +{ + uint u = c.r | (c.g << 8) | (c.b << 16) | (c.a << 24); + return u; +}