scroller working
This commit is contained in:
@@ -15,16 +15,6 @@
|
||||
#include "ui_iter.c"
|
||||
#include "ui.c"
|
||||
|
||||
/*
|
||||
** UI Design:
|
||||
** - keyboard friendly (not in the windows sense, more console sense)
|
||||
**
|
||||
**
|
||||
** [ ]
|
||||
**
|
||||
**
|
||||
*/
|
||||
|
||||
typedef struct globals_t globals_t;
|
||||
struct globals_t {
|
||||
// gfx_t *gfx;
|
||||
@@ -55,9 +45,16 @@ 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;
|
||||
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()) {
|
||||
defer_block(ui_push_container(UI_CODE_LOC, ui_percent(97), ui_percent(100)), 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);
|
||||
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");
|
||||
@@ -75,29 +72,29 @@ fn b32 app_update(app_frame_t *frame) {
|
||||
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");
|
||||
}
|
||||
// pop ui_offset_all_entries_by(scroller_percent);
|
||||
|
||||
}
|
||||
|
||||
// scroller
|
||||
{
|
||||
ui_push_container(UI_CODE_LOC, ui_percent(3), ui_percent(100));
|
||||
static f32 scroller_percent;
|
||||
f32 scroller_first = scroller_percent;
|
||||
f32 scroller_second = 90 - scroller_percent;
|
||||
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;
|
||||
|
||||
ui_spacer(UI_CODE_LOC, ui_percent(100), ui_percent(scroller_first));
|
||||
ui_signal_t sig = ui_scroller_button(UI_CODE_LOC, ui_percent(100), ui_percent(10));
|
||||
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) * 100;
|
||||
scroller_percent = CLAMP(scroller_percent, 0, 90);
|
||||
scroller_percent += (ev->mouse_delta.y / frame->window_size.y);
|
||||
scroller_percent = CLAMP(scroller_percent, 0, 0.9f);
|
||||
}
|
||||
ui_spacer(UI_CODE_LOC, ui_percent(100), ui_percent(scroller_second));
|
||||
ui_spacer(UI_CODE_LOC, ui_percent(1), ui_percent(scroller_second));
|
||||
ui_pop_parent();
|
||||
}
|
||||
}
|
||||
@@ -107,7 +104,7 @@ fn b32 app_update(app_frame_t *frame) {
|
||||
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", ui->allocated_boxes, frame->delta, frame->update, frame->event_count, frame->last_event->mouse_delta.x, frame->last_event->mouse_delta.y);
|
||||
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();
|
||||
|
||||
@@ -235,7 +235,7 @@ fn void ui_set_indented_string(ui_box_t *box, s8_t string) { box->string = s8_pr
|
||||
fn ui_signal_t ui_push_exp(ui_code_loc_t loc, char *str, ...) {
|
||||
S8_FMT(tcx.temp, str, string);
|
||||
ui_box_t *box = ui_build_box_from_string(loc, string, flag2(ui_box_flag_draw_rect, ui_box_flag_draw_text));
|
||||
ui_set_semantic_size(box, ui_percent(100), ui_text());
|
||||
ui_set_semantic_size(box, ui_percent(1), ui_text());
|
||||
|
||||
if (box->created_new) box->expanded = true;
|
||||
|
||||
@@ -275,9 +275,8 @@ fn void ui_end_frame(void) {
|
||||
}
|
||||
}
|
||||
|
||||
fn void ui_draw(void) {
|
||||
fn void ui_layout(void) {
|
||||
rn_font_t *font = &rn_state.main_font;
|
||||
ui_test_iterator();
|
||||
|
||||
// compute standalone sizes: (pixels, text_content)
|
||||
for (ui_preorder_iter_t it = ui_iterate_preorder(ui->root); ui_preorder_iter_is_valid(it); ui_iter_advance_preorder(&it)) {
|
||||
@@ -301,11 +300,11 @@ fn void ui_draw(void) {
|
||||
for (ui_axis2_t axis = 0; axis < ui_axis2_count; axis += 1) {
|
||||
ui_size_t sem = box->semantic_size[axis];
|
||||
if (sem.kind == ui_size_kind_percent_of_parent) {
|
||||
// assert(sem.value >= 0 && sem.value <= 100.0);
|
||||
assert(sem.value >= 0 && sem.value <= 1.0);
|
||||
assert(parent->semantic_size[axis].kind == ui_size_kind_pixels ||
|
||||
parent->semantic_size[axis].kind == ui_size_kind_text_content ||
|
||||
parent->semantic_size[axis].kind == ui_size_kind_percent_of_parent);
|
||||
box->computed_size[axis] = (sem.value / 100.0f) * parent->computed_size[axis];
|
||||
box->computed_size[axis] = (sem.value) * parent->computed_size[axis];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,6 +343,10 @@ fn void ui_draw(void) {
|
||||
f32 *iter_pos = &parent->iter_pos[axis];
|
||||
|
||||
*pos = parent_pos + *iter_pos;
|
||||
if (is_flag_set(parent->flags, ui_box_flag_scroll)) {
|
||||
*pos -= parent->view_offset.e[axis];
|
||||
}
|
||||
|
||||
if (parent->grow_axis == axis) *iter_pos += size;
|
||||
}
|
||||
|
||||
@@ -351,6 +354,12 @@ fn void ui_draw(void) {
|
||||
v2f32_t size = v2f32(box->computed_size[0], box->computed_size[1]);
|
||||
box->rect = r2f32_mindim(pos, size);
|
||||
}
|
||||
}
|
||||
|
||||
fn void ui_draw(void) {
|
||||
rn_font_t *font = &rn_state.main_font;
|
||||
ui_test_iterator();
|
||||
ui_layout();
|
||||
|
||||
// actually draw
|
||||
for (ui_preorder_iter_t it = ui_iterate_preorder(ui->root); ui_preorder_iter_is_valid(it); ui_iter_advance_preorder(&it)) {
|
||||
|
||||
@@ -51,6 +51,7 @@ struct ui_size_t {
|
||||
#define flag3(a, b, c) (set_bit(a) | set_bit(b) | set_bit(c))
|
||||
#define flag4(a, b, c, d) (set_bit(a) | set_bit(b) | set_bit(c) | set_bit(d))
|
||||
#define is_flag_set(x, FLAG) ((x) & flag1(FLAG))
|
||||
#define set_flag1(x, FLAG) ((x) |= flag1(FLAG))
|
||||
|
||||
typedef u32 ui_box_flag_t;
|
||||
enum {
|
||||
@@ -58,6 +59,8 @@ enum {
|
||||
ui_box_flag_draw_text,
|
||||
ui_box_flag_draw_rect,
|
||||
ui_box_flag_draw_scroller,
|
||||
|
||||
ui_box_flag_scroll,
|
||||
};
|
||||
|
||||
typedef struct ui_box_t ui_box_t;
|
||||
@@ -86,6 +89,7 @@ struct ui_box_t {
|
||||
f32 computed_rel_pos[ui_axis2_count];
|
||||
f32 computed_size[ui_axis2_count];
|
||||
r2f32_t rect;
|
||||
v2f32_t view_offset;
|
||||
|
||||
// state
|
||||
b32 expanded;
|
||||
|
||||
Reference in New Issue
Block a user