add push_sprite()

font_atlas
Alessandro Mauri 2 weeks ago
parent c880c2b26e
commit 5c687bd24e
  1. 13
      src/ugui_cmd.c3
  2. 27
      src/ugui_text.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)!; ctx.cmd_queue.enqueue(&cmd)!;
} }
Cmd cmd = { Cmd cmd = {
.type = CMD_RECT, .type = CMD_RECT,
.rect.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)!; 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)!;
}

@ -89,23 +89,20 @@ fn void! Ctx.text_unbounded(&ctx, String label, String text)
Codepoint cp = (Codepoint)c; Codepoint cp = (Codepoint)c;
if (cp != '\n') { if (cp != '\n') {
gp = ctx.font.get_glyph(cp)!; gp = ctx.font.get_glyph(cp)!;
Cmd cmd = { Rect gb = {
.type = CMD_SPRITE, .x = orig.x + line_len + gp.ox,
.sprite.rect = { .y = orig.y + gp.oy + baseline,
.x = orig.x + line_len + gp.ox, .w = gp.w,
.y = orig.y + gp.oy + baseline, .h = gp.h,
.w = gp.w,
.h = gp.h,
},
.sprite.texture_rect = {
.x = gp.u,
.y = gp.v,
.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; line_len += gp.adv;
ctx.cmd_queue.enqueue(&cmd)!;
} else { } else {
orig.y += line_height + line_gap; orig.y += line_height + line_gap;
line_len = 0; line_len = 0;

Loading…
Cancel
Save