better checkboxes
This commit is contained in:
parent
586e81935c
commit
1de4fd78b8
@ -145,8 +145,6 @@ fn void? Ctx.checkbox_id(&ctx, Id id, String description, Point off, bool* activ
|
|||||||
// add it to the tree
|
// add it to the tree
|
||||||
ctx.tree.add(id, ctx.active_div)!;
|
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) {
|
if (elem.flags.is_new) {
|
||||||
elem.type = ETYPE_BUTTON;
|
elem.type = ETYPE_BUTTON;
|
||||||
} else if (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);
|
elem.events = ctx.get_elem_events(elem);
|
||||||
if (elem.events.mouse_hover && elem.events.mouse_release) *active = !(*active);
|
if (elem.events.mouse_hover && elem.events.mouse_release) *active = !(*active);
|
||||||
|
|
||||||
Color col;
|
Color col = ctx.style.bgcolor;
|
||||||
if (tick_sprite != {}) {
|
if (tick_sprite != {}) {
|
||||||
col = ctx.style.bgcolor;
|
|
||||||
ctx.push_rect(elem.bounds, col, parent.div.z_index, do_border: true, do_radius: true)!;
|
ctx.push_rect(elem.bounds, col, parent.div.z_index, do_border: true, do_radius: true)!;
|
||||||
if (*active) {
|
if (*active) {
|
||||||
ctx.draw_sprite_raw(tick_sprite, elem.bounds)!;
|
ctx.draw_sprite_raw(tick_sprite, elem.bounds, center: true)!;
|
||||||
}
|
}
|
||||||
} else {
|
} 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)!;
|
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)!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)!;
|
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)
|
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 = {
|
Cmd cmd = {
|
||||||
|
@ -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)!;
|
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()!;
|
Elem *parent = ctx.get_parent()!;
|
||||||
Sprite* sprite = ctx.sprite_atlas.get(name)!;
|
Sprite* sprite = ctx.sprite_atlas.get(name)!;
|
||||||
Id tex_id = ctx.sprite_atlas.id;
|
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)!;
|
return ctx.push_sprite(bounds, sprite.uv(), tex_id, parent.div.z_index, type: sprite.type)!;
|
||||||
}
|
}
|
||||||
|
@ -228,6 +228,7 @@ fn int main(String[] args)
|
|||||||
ui.layout_next_row()!!;
|
ui.layout_next_row()!!;
|
||||||
static bool check;
|
static bool check;
|
||||||
ui.checkbox("", {}, &check, "tick")!!;
|
ui.checkbox("", {}, &check, "tick")!!;
|
||||||
|
ui.checkbox("", {}, &check)!!;
|
||||||
ui.toggle("", {}, &toggle)!!;
|
ui.toggle("", {}, &toggle)!!;
|
||||||
};
|
};
|
||||||
ui.draw_sprite("tux")!!;
|
ui.draw_sprite("tux")!!;
|
||||||
|
Loading…
Reference in New Issue
Block a user