diff --git a/lib/ugui.c3l/src/ugui_button.c3 b/lib/ugui.c3l/src/ugui_button.c3 index 5661fbb..93e519f 100644 --- a/lib/ugui.c3l/src/ugui_button.c3 +++ b/lib/ugui.c3l/src/ugui_button.c3 @@ -145,8 +145,6 @@ fn void? Ctx.checkbox_id(&ctx, Id id, String description, Point off, bool* activ // add it to the tree ctx.tree.add(id, ctx.active_div)!; - // FIXME: for now checkboxes and buttons have no members so the element types - // can be the same if (elem.flags.is_new) { elem.type = ETYPE_BUTTON; } else if (elem.type != ETYPE_BUTTON) { @@ -163,21 +161,19 @@ fn void? Ctx.checkbox_id(&ctx, Id id, String description, Point off, bool* activ elem.events = ctx.get_elem_events(elem); if (elem.events.mouse_hover && elem.events.mouse_release) *active = !(*active); - Color col; + Color col = ctx.style.bgcolor; if (tick_sprite != {}) { - col = ctx.style.bgcolor; ctx.push_rect(elem.bounds, col, parent.div.z_index, do_border: true, do_radius: true)!; if (*active) { - ctx.draw_sprite_raw(tick_sprite, elem.bounds)!; + ctx.draw_sprite_raw(tick_sprite, elem.bounds, center: true)!; } } else { - if (*active) { - col = 0xff0000ffu.to_rgba(); - } else { - col = 0xff00ffffu.to_rgba(); - } - // Draw the button ctx.push_rect(elem.bounds, col, parent.div.z_index, do_border: true, do_radius: true)!; + if (*active) { + ushort x = DEFAULT_CHECKBOX_SIZE / 4; + Rect check = elem.bounds.add({x, x, -x*2, -x*2}); + ctx.push_rect(check, 0xff0000ffu.to_rgba(), parent.div.z_index, do_radius: true)!; + } } } diff --git a/lib/ugui.c3l/src/ugui_cmd.c3 b/lib/ugui.c3l/src/ugui_cmd.c3 index 5b2ac83..5c76aeb 100644 --- a/lib/ugui.c3l/src/ugui_cmd.c3 +++ b/lib/ugui.c3l/src/ugui_cmd.c3 @@ -124,7 +124,6 @@ fn void? Ctx.push_rect(&ctx, Rect rect, Color color, int z_index, bool do_border ctx.push_cmd(&cmd, z_index)!; } -// TODO: add texture id fn void? Ctx.push_sprite(&ctx, Rect bounds, Rect texture, Id texture_id, int z_index, Color hue = 0xffffffffu.to_rgba(), SpriteType type = SPRITE_NORMAL) { Cmd cmd = { diff --git a/lib/ugui.c3l/src/ugui_sprite.c3 b/lib/ugui.c3l/src/ugui_sprite.c3 index 888a1b4..216b1e2 100644 --- a/lib/ugui.c3l/src/ugui_sprite.c3 +++ b/lib/ugui.c3l/src/ugui_sprite.c3 @@ -145,10 +145,16 @@ fn void? Ctx.draw_sprite_id(&ctx, Id id, String name, Point off) return ctx.push_sprite(elem.bounds, uv, tex_id, parent.div.z_index)!; } -fn void? Ctx.draw_sprite_raw(&ctx, String name, Rect bounds) +fn void? Ctx.draw_sprite_raw(&ctx, String name, Rect bounds, bool center = false) { Elem *parent = ctx.get_parent()!; Sprite* sprite = ctx.sprite_atlas.get(name)!; Id tex_id = ctx.sprite_atlas.id; + + if (center) { + Point off = {.x = (bounds.w - sprite.w) / 2, .y = (bounds.h - sprite.h) / 2}; + bounds = bounds.off(off); + } + return ctx.push_sprite(bounds, sprite.uv(), tex_id, parent.div.z_index, type: sprite.type)!; } diff --git a/src/main.c3 b/src/main.c3 index af2b584..337cf81 100644 --- a/src/main.c3 +++ b/src/main.c3 @@ -228,6 +228,7 @@ fn int main(String[] args) ui.layout_next_row()!!; static bool check; ui.checkbox("", {}, &check, "tick")!!; + ui.checkbox("", {}, &check)!!; ui.toggle("", {}, &toggle)!!; }; ui.draw_sprite("tux")!!;