diff --git a/TODO b/TODO index d62e1de..c2e8c1b 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/lib/libgrapheme.c3l/Makefile b/lib/grapheme.c3l/Makefile similarity index 100% rename from lib/libgrapheme.c3l/Makefile rename to lib/grapheme.c3l/Makefile diff --git a/lib/libgrapheme.c3l/libgrapheme.c3i b/lib/grapheme.c3l/libgrapheme.c3i similarity index 100% rename from lib/libgrapheme.c3l/libgrapheme.c3i rename to lib/grapheme.c3l/libgrapheme.c3i diff --git a/lib/libgrapheme.c3l/manifest.json b/lib/grapheme.c3l/manifest.json similarity index 100% rename from lib/libgrapheme.c3l/manifest.json rename to lib/grapheme.c3l/manifest.json diff --git a/lib/libgrapheme.c3l/project.json b/lib/grapheme.c3l/project.json similarity index 100% rename from lib/libgrapheme.c3l/project.json rename to lib/grapheme.c3l/project.json diff --git a/lib/libgrapheme.c3l/thirdparty/libgrapheme b/lib/grapheme.c3l/thirdparty/libgrapheme similarity index 100% rename from lib/libgrapheme.c3l/thirdparty/libgrapheme rename to lib/grapheme.c3l/thirdparty/libgrapheme diff --git a/lib/libschrift.c3l/linux-x64/libschrift.a b/lib/libschrift.c3l/linux-x64/libschrift.a deleted file mode 100644 index e3a0423..0000000 Binary files a/lib/libschrift.c3l/linux-x64/libschrift.a and /dev/null differ diff --git a/lib/libmqoi.c3l/Makefile b/lib/mini-qoi.c3l/Makefile similarity index 100% rename from lib/libmqoi.c3l/Makefile rename to lib/mini-qoi.c3l/Makefile diff --git a/lib/libmqoi.c3l/libmqoi.c3i b/lib/mini-qoi.c3l/libmqoi.c3i similarity index 100% rename from lib/libmqoi.c3l/libmqoi.c3i rename to lib/mini-qoi.c3l/libmqoi.c3i diff --git a/lib/libmqoi.c3l/manifest.json b/lib/mini-qoi.c3l/manifest.json similarity index 100% rename from lib/libmqoi.c3l/manifest.json rename to lib/mini-qoi.c3l/manifest.json diff --git a/lib/libmqoi.c3l/project.json b/lib/mini-qoi.c3l/project.json similarity index 100% rename from lib/libmqoi.c3l/project.json rename to lib/mini-qoi.c3l/project.json diff --git a/lib/libmqoi.c3l/thirdparty/mini-qoi b/lib/mini-qoi.c3l/thirdparty/mini-qoi similarity index 100% rename from lib/libmqoi.c3l/thirdparty/mini-qoi rename to lib/mini-qoi.c3l/thirdparty/mini-qoi diff --git a/lib/libschrift.c3l/Makefile b/lib/schrift.c3l/Makefile similarity index 100% rename from lib/libschrift.c3l/Makefile rename to lib/schrift.c3l/Makefile diff --git a/lib/libschrift.c3l/libschrift.c3 b/lib/schrift.c3l/libschrift.c3 similarity index 100% rename from lib/libschrift.c3l/libschrift.c3 rename to lib/schrift.c3l/libschrift.c3 diff --git a/lib/libschrift.c3l/manifest.json b/lib/schrift.c3l/manifest.json similarity index 100% rename from lib/libschrift.c3l/manifest.json rename to lib/schrift.c3l/manifest.json diff --git a/lib/libschrift.c3l/project.json b/lib/schrift.c3l/project.json similarity index 100% rename from lib/libschrift.c3l/project.json rename to lib/schrift.c3l/project.json diff --git a/lib/libschrift.c3l/thirdparty/libschrift b/lib/schrift.c3l/thirdparty/libschrift similarity index 100% rename from lib/libschrift.c3l/thirdparty/libschrift rename to lib/schrift.c3l/thirdparty/libschrift diff --git a/src/main.c3 b/src/main.c3 index 5f4873e..7c7228d 100644 --- a/src/main.c3 +++ b/src/main.c3 @@ -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()!!; diff --git a/src/ugui_button.c3 b/src/ugui_button.c3 index f18b417..ee3a898 100644 --- a/src/ugui_button.c3 +++ b/src/ugui_button.c3 @@ -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)!; +}