tweak ugui api, add some usefult functions

This commit is contained in:
Alessandro Mauri 2025-06-12 18:56:57 +02:00
parent 2014c67bfd
commit c4a3dd3a26
3 changed files with 18 additions and 2 deletions

View File

@ -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 };

View File

@ -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;
}

View File

@ -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;
}