improving scroller
This commit is contained in:
@@ -45,16 +45,61 @@ fn b32 app_update(app_frame_t *frame) {
|
||||
assert(frame->first_event);
|
||||
|
||||
for (app_event_t *ev = frame->first_event; ev; ev = ev->next) {
|
||||
static f32 scroller_percent;
|
||||
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 *container = ui_push_container(UI_CODE_LOC, ui_percent(0.97f), ui_percent(1));
|
||||
set_flag1(container->flags, ui_box_flag_scroll);
|
||||
container->view_offset.y = scroller_percent * frame->window_size.y;//r2f32_get_size(container->rect).y;
|
||||
defer_block(container, ui_pop_parent()) {
|
||||
|
||||
// ui_offset_all_entries_by(scroller_percent);
|
||||
ui_box_t *item_box = ui_build_box_from_string(UI_CODE_LOC, flag3(ui_box_flag_scroll, ui_box_flag_draw_rect, ui_box_flag_draw_border), 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");
|
||||
@@ -78,24 +123,31 @@ fn b32 app_update(app_frame_t *frame) {
|
||||
ui_label(UI_CODE_LOC, "alt: b8 = value");
|
||||
ui_label(UI_CODE_LOC, "meta: b8 = value");
|
||||
}
|
||||
// pop ui_offset_all_entries_by(scroller_percent);
|
||||
|
||||
}
|
||||
|
||||
// scroller
|
||||
{
|
||||
ui_push_container(UI_CODE_LOC, ui_percent(0.03f), ui_percent(1));
|
||||
f32 scroller_size = 0.1f;
|
||||
f32 scroller_second = (1 - scroller_size) - scroller_percent;
|
||||
|
||||
f32 all_items_size = (f32)item_box->node_count * get_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_percent = scroller_value * scrollable_space;
|
||||
f32 inV_scroller_percent = 1.f / scroller_percent;
|
||||
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_percent += (ev->mouse_delta.y / frame->window_size.y);
|
||||
scroller_percent = CLAMP(scroller_percent, 0, 0.9f);
|
||||
scroller_value += (ev->mouse_delta.y / item_box_size * 2);
|
||||
}
|
||||
scroller_value = CLAMP(scroller_value, 0, 1.0f);
|
||||
ui_spacer(UI_CODE_LOC, ui_percent(1), ui_percent(scroller_second));
|
||||
ui_pop_parent();
|
||||
|
||||
item_box->view_offset.y = scroller_value * (all_items_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user