ui work
This commit is contained in:
@@ -5,61 +5,58 @@
|
||||
#include "app/app.c"
|
||||
#include "gfx2d/gfx2d.c"
|
||||
|
||||
// #include "ui.c"
|
||||
#include "ui.c"
|
||||
|
||||
typedef struct ui_widget_t ui_widget_t;
|
||||
struct ui_widget_t {
|
||||
/*
|
||||
** UI Design:
|
||||
** - keyboard friendly (not in the windows sense, more console sense)
|
||||
**
|
||||
**
|
||||
** [ ]
|
||||
**
|
||||
**
|
||||
*/
|
||||
|
||||
typedef struct globals_t globals_t;
|
||||
struct globals_t {
|
||||
gfx_t *gfx;
|
||||
app_event_t event;
|
||||
};
|
||||
gb globals_t *globals;
|
||||
|
||||
typedef struct ui_t ui_t;
|
||||
struct ui_t {
|
||||
|
||||
// update cycle data
|
||||
b8 left_press;
|
||||
b8 left_unpress;
|
||||
b8 left_down;
|
||||
v2f64_t mouse_pos;
|
||||
v2f64_t window_size;
|
||||
fn void app_init(void) {
|
||||
ui_test_iterators();
|
||||
|
||||
//
|
||||
|
||||
};
|
||||
|
||||
gb ui_t gb_ui = {0};
|
||||
gb gfx_t *gfx = NULL;
|
||||
|
||||
gb i32 config_indent = 4;
|
||||
|
||||
void ui_begin_interaction(ui_t *ui, app_event_t *ev) {
|
||||
ui->mouse_pos = ev->mouse_pos;
|
||||
ui->window_size = ev->window_size;
|
||||
ui->left_press = false;
|
||||
ui->left_unpress = false;
|
||||
if (ev->kind == app_event_kind_mouse_down && ev->mouse_button == app_mouse_button_left) {
|
||||
ui->left_press = true;
|
||||
ui->left_down = true;
|
||||
}
|
||||
if (ev->kind == app_event_kind_mouse_up && ev->mouse_button == app_mouse_button_left) {
|
||||
ui->left_unpress = true;
|
||||
ui->left_down = false;
|
||||
}
|
||||
}
|
||||
|
||||
void app_handle_event(app_event_t *ev) {
|
||||
ui_t *ui = &gb_ui;
|
||||
ui_begin_interaction(ui, ev);
|
||||
}
|
||||
|
||||
void app_init(void) {
|
||||
ma_arena_t *perm = &tcx._perm;
|
||||
gfx = ma_push_type(perm, gfx_t);
|
||||
|
||||
|
||||
globals = ma_push_type(perm, globals_t);
|
||||
globals->gfx = ma_push_type(perm, gfx_t);
|
||||
ui_init(perm);
|
||||
}
|
||||
|
||||
b32 app_update(app_event_list_t events) {
|
||||
|
||||
fn b32 app_update(app_event_list_t events) {
|
||||
for (app_event_t *ev = events.first; ev; ev = ev->next) {
|
||||
app_handle_event(ev);
|
||||
if (globals->event.kind == app_event_kind_null) {
|
||||
globals->event = *ev;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// ui_struct()
|
||||
type_t *ti = type(app_event_t);
|
||||
|
||||
ui_push_list("▼ %S: struct", ti->name);
|
||||
for (type_member_t *tm = ti->members; tm < ti->members + ti->count; tm += 1) {
|
||||
if (tm->kind == type_kind_struct) {
|
||||
ui_list_struct(tm->type, ti_get_member_offset(tm, p)
|
||||
} else {
|
||||
ui_list_item("%-20S: %S = %S", tm->name, ti_serial_type(tcx.temp, tm->type), ti_serial_data(p, type));
|
||||
}
|
||||
}
|
||||
ui_pop_list();
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
// These steps should be totally optional!!
|
||||
@@ -67,13 +64,31 @@ b32 app_update(app_event_list_t events) {
|
||||
app_event_t *ev = events.last;
|
||||
f64 delta = app_get_anim_delta_time();
|
||||
f64 time = app_get_anim_time();
|
||||
f64 font_height = get_font_height();
|
||||
|
||||
// animate
|
||||
// render
|
||||
gfx_begin(gfx, ev);
|
||||
gfx_clear(gfx, white_color_global);
|
||||
gfx_textf(gfx, (v2f64_t){0,0}, black_color_global, "delta: %f, time: %f", delta, time);
|
||||
gfx_end(gfx);
|
||||
gfx_begin(globals->gfx, ev);
|
||||
gfx_clear(globals->gfx, white_color_global);
|
||||
gfx_textf(globals->gfx, (v2f64_t){0,ev->window_size.y - font_height}, black_color_global, "delta: %f, time: %f", delta, time);
|
||||
|
||||
|
||||
// ►
|
||||
type_t *ti = type(app_event_t);
|
||||
f64 xoffset = measure_text("--");
|
||||
|
||||
|
||||
v2f64_t p = {0, 0};
|
||||
gfx_textf(globals->gfx, p, black_color_global, "▼ %S: struct", ti->name);
|
||||
p.x += xoffset; p.y += font_height + 5;
|
||||
|
||||
for (type_member_t *tm = ti->members; tm < ti->members + ti->count; tm += 1) {
|
||||
s8_t value = ti__serial_data(tcx.temp, ti_extract_member(&globals->event, tm), tm->type);
|
||||
gfx_textf(globals->gfx, p, black_color_global, "%-20S: %-20S = %S", tm->name, ti_serial_type(tcx.temp, tm->type), value);
|
||||
p.y += font_height + 5;
|
||||
}
|
||||
|
||||
gfx_end(globals->gfx);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user