From 5c687bd24e358b27686f1b9639422e93b508ef7f Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Fri, 13 Dec 2024 14:05:07 +0100 Subject: [PATCH] add push_sprite() --- src/ugui_cmd.c3 | 13 ++++++++++++- src/ugui_text.c3 | 27 ++++++++++++--------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/ugui_cmd.c3 b/src/ugui_cmd.c3 index 14919ca..d3ce0c9 100644 --- a/src/ugui_cmd.c3 +++ b/src/ugui_cmd.c3 @@ -18,7 +18,7 @@ fn void! Ctx.push_rect(&ctx, Rect rect, Color color, bool do_border = false, boo }; ctx.cmd_queue.enqueue(&cmd)!; } - + Cmd cmd = { .type = CMD_RECT, .rect.rect = { @@ -32,3 +32,14 @@ fn void! Ctx.push_rect(&ctx, Rect rect, Color color, bool do_border = false, boo }; ctx.cmd_queue.enqueue(&cmd)!; } + +// TODO: add texture id +fn void! Ctx.push_sprite(&ctx, Rect bounds, Rect texture) +{ + Cmd cmd = { + .type = CMD_SPRITE, + .sprite.rect = bounds, + .sprite.texture_rect = texture, + }; + ctx.cmd_queue.enqueue(&cmd)!; +} diff --git a/src/ugui_text.c3 b/src/ugui_text.c3 index 15bcd28..97efbae 100644 --- a/src/ugui_text.c3 +++ b/src/ugui_text.c3 @@ -89,23 +89,20 @@ fn void! Ctx.text_unbounded(&ctx, String label, String text) Codepoint cp = (Codepoint)c; if (cp != '\n') { gp = ctx.font.get_glyph(cp)!; - Cmd cmd = { - .type = CMD_SPRITE, - .sprite.rect = { - .x = orig.x + line_len + gp.ox, - .y = orig.y + gp.oy + baseline, - .w = gp.w, - .h = gp.h, - }, - .sprite.texture_rect = { - .x = gp.u, - .y = gp.v, - .w = gp.w, - .h = gp.h, - }, + Rect gb = { + .x = orig.x + line_len + gp.ox, + .y = orig.y + gp.oy + baseline, + .w = gp.w, + .h = gp.h, }; + Rect gt = { + .x = gp.u, + .y = gp.v, + .w = gp.w, + .h = gp.h, + }; + ctx.push_sprite(gb, gt)!; line_len += gp.adv; - ctx.cmd_queue.enqueue(&cmd)!; } else { orig.y += line_height + line_gap; line_len = 0;