aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-02-16 16:31:08 -0500
committerSam Anthony <sam@samanthony.xyz>2025-02-16 16:31:08 -0500
commit4ffae4aeec2e5cc708f3a13899ad6b280b25b83f (patch)
tree32a94ebef53a1e31965fa5eeab8323114a0532d1 /main.c
parent9bd3edfb51ac9b975bb02596eebafb2c9069aa36 (diff)
downloadvolute-4ffae4aeec2e5cc708f3a13899ad6b280b25b83f.zip
number field widget
Diffstat (limited to 'main.c')
-rw-r--r--main.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/main.c b/main.c
index d36d9be..fb0770a 100644
--- a/main.c
+++ b/main.c
@@ -5,6 +5,8 @@
#include <SDL2/SDL.h>
#include "renderer.h"
#include "microui.h"
+#include "widget.h"
+#include "ui.h"
/* Constants. */
@@ -33,11 +35,11 @@ static const char key_map[256] = {
static int text_width(mu_Font font, const char *text, int len);
static int text_height(mu_Font font);
-static void main_loop(mu_Context *ctx);
+static void main_loop(mu_Context *ctx, UI *ui);
static void handle_events(mu_Context *ctx);
static void handle_event(SDL_Event e, mu_Context *ctx);
-static void process_frame(mu_Context *ctx);
-static void main_window(mu_Context *ctx);
+static void process_frame(mu_Context *ctx, UI *ui);
+static void main_window(mu_Context *ctx, UI *ui);
static void render(mu_Context *ctx);
static void render_command(mu_Command *cmd);
@@ -63,7 +65,11 @@ main(void) {
ctx.text_width = text_width;
ctx.text_height = text_height;
- main_loop(&ctx);
+ /* Init data structures. */
+ static UI ui;
+ init_ui(&ui);
+
+ main_loop(&ctx, &ui);
return 0;
}
@@ -82,10 +88,10 @@ text_height(mu_Font font) {
}
static void
-main_loop(mu_Context *ctx) {
+main_loop(mu_Context *ctx, UI *ui) {
for (;;) {
handle_events(ctx);
- process_frame(ctx);
+ process_frame(ctx, ui);
render(ctx);
}
}
@@ -135,14 +141,14 @@ handle_event(SDL_Event e, mu_Context *ctx) {
}
static void
-process_frame(mu_Context *ctx) {
+process_frame(mu_Context *ctx, UI *ui) {
mu_begin(ctx);
- main_window(ctx);
+ main_window(ctx, ui);
mu_end(ctx);
}
static void
-main_window(mu_Context *ctx) {
+main_window(mu_Context *ctx, UI *ui) {
int w, h;
r_get_window_size(&w, &h);
@@ -151,8 +157,14 @@ main_window(mu_Context *ctx) {
}
/* TODO */
mu_layout_row(ctx, 2, (int[]) {0, 0}, 0);
- mu_label(ctx, "foo");
- mu_label(ctx, "bar");
+ static double value = 0.0;
+ if (field(ctx, &ui->displacement) & MU_RES_CHANGE) {
+ /* TODO */
+ value = ui->displacement.value;
+ }
+ static char buf[64];
+ snprintf(buf, sizeof(buf), "%lf", value);
+ mu_label(ctx, buf);
mu_end_window(ctx);
}