new ui idea
This commit is contained in:
@@ -10,14 +10,12 @@
|
||||
#include "render/backup_font.c"
|
||||
#include "render/font.c"
|
||||
#include "render/render_opengl.c"
|
||||
// #include "gfx2d/gfx2d.c"dv
|
||||
|
||||
#include "ui_iter.c"
|
||||
#include "ui.c"
|
||||
|
||||
typedef struct globals_t globals_t;
|
||||
struct globals_t {
|
||||
// gfx_t *gfx;
|
||||
app_event_t event;
|
||||
};
|
||||
gb globals_t *globals;
|
||||
@@ -26,131 +24,11 @@ gb globals_t *globals;
|
||||
fn void app_init(f32 dpr) {
|
||||
ma_arena_t *perm = &tcx._perm;
|
||||
globals = ma_push_type(perm, globals_t);
|
||||
ma_arena_t *ui_arena = ma_push_arena(perm, mib(1));
|
||||
ui_init(ui_arena);
|
||||
rn_init(perm, 50 * dpr);
|
||||
ui_demo_init(perm);
|
||||
}
|
||||
|
||||
fn b32 app_update(app_frame_t *frame) {
|
||||
assert(frame != NULL);
|
||||
ui_begin_frame(frame);
|
||||
|
||||
assert(frame->first_event);
|
||||
|
||||
for (app_event_t *ev = frame->first_event; ev; ev = ev->next) {
|
||||
static f32 scroller_value;
|
||||
defer_block(ui_begin_build(UI_CODE_LOC, ev), ui_end_build()) {
|
||||
defer_block(ui_push_xcontainer(UI_CODE_LOC, ui_em(25), ui_em(30)), ui_pop_parent()) {
|
||||
|
||||
|
||||
ui_box_t *item_box = ui_build_box_from_string(UI_CODE_LOC, (ui_box_flags_t){.scroll = true, .draw_rect = true}, s8_lit("scrolled item_box"));
|
||||
ui_set_semantic_size(item_box, ui_percent(0.97f), ui_percent(1));
|
||||
item_box->grow_axis = ui_axis2_y;
|
||||
defer_block(ui_push_parent(item_box), ui_pop_parent()) {
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "app_event_t").clicked, ui_pop_exp()) {
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "mouse_wheel_delta: v3f64_t").clicked, ui_pop_exp()) {
|
||||
ui_label(UI_CODE_LOC, "x: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "z: f64 = value");
|
||||
}
|
||||
ui_label(UI_CODE_LOC, "kind: app_event_kind_t = value");
|
||||
ui_label(UI_CODE_LOC, "ctrl: b8 = value");
|
||||
ui_label(UI_CODE_LOC, "shift: b8 = value");
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "pos: v2f64_t").clicked, ui_pop_exp()) {
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "inner_pos: v2f64_t##asd").clicked, ui_pop_exp()) {
|
||||
ui_label(UI_CODE_LOC, "x: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
}
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "inner_pos: v2f64_t##qwe").clicked, ui_pop_exp()) {
|
||||
ui_label(UI_CODE_LOC, "x: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
}
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
}
|
||||
ui_label(UI_CODE_LOC, "alt: b8 = value");
|
||||
ui_label(UI_CODE_LOC, "meta: b8 = value");
|
||||
}
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "app_event_t").clicked, ui_pop_exp()) {
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "mouse_wheel_delta: v3f64_t").clicked, ui_pop_exp()) {
|
||||
ui_label(UI_CODE_LOC, "x: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "z: f64 = value");
|
||||
}
|
||||
ui_label(UI_CODE_LOC, "kind: app_event_kind_t = value");
|
||||
ui_label(UI_CODE_LOC, "ctrl: b8 = value");
|
||||
ui_label(UI_CODE_LOC, "shift: b8 = value");
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "pos: v2f64_t").clicked, ui_pop_exp()) {
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "inner_pos: v2f64_t##asd").clicked, ui_pop_exp()) {
|
||||
ui_label(UI_CODE_LOC, "x: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
}
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "inner_pos: v2f64_t##qwe").clicked, ui_pop_exp()) {
|
||||
ui_label(UI_CODE_LOC, "x: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
}
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
}
|
||||
ui_label(UI_CODE_LOC, "alt: b8 = value");
|
||||
ui_label(UI_CODE_LOC, "meta: b8 = value");
|
||||
}
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "app_event_t").clicked, ui_pop_exp()) {
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "mouse_wheel_delta: v3f64_t").clicked, ui_pop_exp()) {
|
||||
ui_label(UI_CODE_LOC, "x: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "z: f64 = value");
|
||||
}
|
||||
ui_label(UI_CODE_LOC, "kind: app_event_kind_t = value");
|
||||
ui_label(UI_CODE_LOC, "ctrl: b8 = value");
|
||||
ui_label(UI_CODE_LOC, "shift: b8 = value");
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "pos: v2f64_t").clicked, ui_pop_exp()) {
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "inner_pos: v2f64_t##asd").clicked, ui_pop_exp()) {
|
||||
ui_label(UI_CODE_LOC, "x: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
}
|
||||
defer_if (ui_push_exp(UI_CODE_LOC, "inner_pos: v2f64_t##qwe").clicked, ui_pop_exp()) {
|
||||
ui_label(UI_CODE_LOC, "x: f64 = value");
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
}
|
||||
ui_label(UI_CODE_LOC, "y: f64 = value");
|
||||
}
|
||||
ui_label(UI_CODE_LOC, "alt: b8 = value");
|
||||
ui_label(UI_CODE_LOC, "meta: b8 = value");
|
||||
}
|
||||
}
|
||||
|
||||
// scroller
|
||||
{
|
||||
f32 all_items_size = (f32)item_box->node_count * rn_state.main_font.size;
|
||||
f32 item_box_size = r2f32_get_size(item_box->rect).y;
|
||||
|
||||
f32 scroller_size = CLAMP(item_box_size / all_items_size, 0, 1.0f);
|
||||
f32 scrollable_space = (1 - scroller_size);
|
||||
f32 scroller_norm = scroller_value / (all_items_size);
|
||||
f32 scroller_percent = scroller_norm * scrollable_space;
|
||||
f32 scroller_second = scrollable_space - scroller_percent;
|
||||
|
||||
ui_push_container(UI_CODE_LOC, ui_percent(0.03f), ui_percent(1));
|
||||
ui_spacer(UI_CODE_LOC, ui_percent(1), ui_percent(scroller_percent));
|
||||
ui_signal_t sig = ui_scroller_button(UI_CODE_LOC, ui_percent(1), ui_percent(scroller_size));
|
||||
if (sig.dragging) {
|
||||
scroller_value += (ev->mouse_delta.y / item_box_size * 2) * (all_items_size);
|
||||
scroller_value = CLAMP(scroller_value, 0, all_items_size);
|
||||
}
|
||||
ui_spacer(UI_CODE_LOC, ui_percent(1), ui_percent(scroller_second));
|
||||
ui_pop_parent();
|
||||
|
||||
item_box->view_offset.y = scroller_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rn_begin();
|
||||
|
||||
ui_draw();
|
||||
rn_draw_stringf(&rn_state.main_font, v2f32(0,frame->window_size.y - 100), black_color_global, "ui_boxes: %d delta: %f update: %f event_count: %d, delta: %f %f dpr: %f", ui->allocated_boxes, frame->delta, frame->update, frame->event_count, frame->last_event->mouse_delta.x, frame->last_event->mouse_delta.y, frame->dpr);
|
||||
rn_end(frame->window_size, white_color_global);
|
||||
|
||||
ui_end_frame();
|
||||
ui_demo_update(frame);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user