renamed libraries

This commit is contained in:
Alessandro Mauri 2025-01-31 12:20:19 +01:00
parent 0531f58a56
commit de64746fdf
19 changed files with 46 additions and 12 deletions

2
TODO
View File

@ -28,6 +28,8 @@ to maintain focus until mouse release (fix scroll bars)
[ ] gif support?
[ ] layout_set_max_rows() and layout_set_max_columns()
[ ] Maybe SDF sprites??
[ ] Stylesheets and stylesheet import
[ ] use SDF to draw anti-aliased rounded rectangles https://zed.dev/blog/videogame
## Layout

View File

@ -113,18 +113,6 @@ fn int main(String[] args)
while (!rl::windowShouldClose()) {
clock.mark();
/*
KeyboardKey k;
do {
k = rl::get_key_pressed();
if (!k) { break; }
if (rl::is_key_down(k)) { io::print("down "); }
if (rl::is_key_pressed(k)) { io::print("pressed "); }
if (rl::is_key_released(k)) { io::print("released "); }
io::printfn("%s", k);
} while (k != 0);
*/
ugui::ModKeys mod;
mod.rctrl = rl::isKeyDown(rl::KEY_RIGHT_CONTROL);
mod.lctrl = rl::isKeyDown(rl::KEY_LEFT_CONTROL);
@ -194,6 +182,10 @@ fn int main(String[] args)
ui.layout_next_column()!!;
ui.button_label("Continua!")!!;
ui.layout_next_row()!!;
static bool check;
ui.checkbox("check1", "", ugui::Point{}, &check)!!;
|};
ui.draw_sprite("sprite1", "tux")!!;
ui.div_end()!!;

View File

@ -8,6 +8,8 @@ struct ElemButton {
}
// draw a button, return the events on that button
// FIXME: "state" should be renamed "active" to toggle between an usable button and
// an inactive (greyed-out) button
fn ElemEvents! Ctx.button(&ctx, String label, Rect size, bool state = false)
{
Id id = ctx.gen_id(label)!;
@ -83,3 +85,41 @@ fn ElemEvents! Ctx.button_label(&ctx, String label, Rect size = Rect{0,0,short.m
return elem.events;
}
// FIXME: this should be inside the style
const ushort DEFAULT_CHECKBOX_SIZE = 16;
fn void! Ctx.checkbox(&ctx, String label, String description, Point off, bool* state)
{
Id id = ctx.gen_id(label)!;
Elem *parent = ctx.get_parent()!;
Elem *elem = ctx.get_elem(id)!;
// 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) {
return UgError.WRONG_ELEMENT_TYPE?;
}
Rect size = {off.x, off.y, DEFAULT_CHECKBOX_SIZE, DEFAULT_CHECKBOX_SIZE};
elem.bounds = ctx.position_element(parent, size, true);
// if the bounds are null the element is outside the div view,
// no interaction should occur so just return
if (elem.bounds.is_null()) return;
Color col = 0x0000ffffu.to_rgba();
elem.events = ctx.get_elem_events(elem);
if (state) {
col = 0xff0000ffu.to_rgba();
} else if (ctx.elem_focus(elem) || elem.events.mouse_hover) {
col = 0xff00ffffu.to_rgba();
}
// Draw the button
ctx.push_rect(elem.bounds, col, do_border: true, do_radius: true)!;
}