diff --git a/build_file.c b/build_file.c index b930669..14aaf6e 100644 --- a/build_file.c +++ b/build_file.c @@ -67,9 +67,9 @@ int main(int argc, char **argv) { if (ok != 0) return ok; } - if (win32_target && cache_code_modified(s8_lit("../src/app/app_win32_exe.c"), s8_lit("app_win32.exe"))) { + if (win32_target && cache_code_modified(s8_lit("../src/app/app_win32_exe.c"), s8_lit("app.exe"))) { ok = os_systemf( - "cl ../src/app/app_win32_exe.c -Fe:app_win32.exe -Fd:app_win32.pdb" + "cl ../src/app/app_win32_exe.c -Fe:app.exe -Fd:app_win32.pdb" " -I ../src" " /Zi /FC /nologo /Oi" " /WX /W3 /wd4200 /diagnostics:column" diff --git a/src/render/render.c b/src/render/render.c index 36bcea2..44fc8fb 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -22,7 +22,9 @@ fn rn_cmd_t *rn_get_cmd(rn_cmd_kind_t kind) { fn rn_vertex_t *rn_push_vertex(rn_cmd_t *cmd, u32 count) { rn_vertex_t *result = cmd->vertex + cmd->len; + assert(rn->cap >= rn->len + count); rn->len += count; + cmd->len += count; return result; } diff --git a/src/ui/ui.c b/src/ui/ui.c index 406a85b..e321c4e 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -75,7 +75,7 @@ fn u64 ui_hash_code_loc(ui_code_loc_t loc) { return result; } -fn ui_id_t ui_id_from_code_loc(ui_code_loc_t loc) { +fn ui_id_t ui_id_from_loc(ui_code_loc_t loc) { u64 id = ui_hash_code_loc(loc); ui_id_t result = {id}; return result; @@ -167,6 +167,7 @@ fn void ui_offset_box(ui_box_t *box, v2f32_t offset) { box->rect = r2f32_sub_v2f32(box->rect, offset); } +#define ui_box(...) ui_build_box_from_id(UILOC, __VA_ARGS__) fn ui_box_t *ui_build_box_from_id(ui_code_loc_t loc, ui_box_flags_t flags, ui_id_t id) { ui_box_t *box = ui_find_box(id); if (box) { @@ -233,6 +234,7 @@ fn ui_signal_t ui_signal_from_box(ui_box_t *box) { b32 inside = r2f32_contains(box->final_rect, ev->mouse_pos); if (ui_is_active_box(box)) { + result.press = true; result.dragging = true; result.drag = ui->event->mouse_delta; if (ev_left_up(ev)) { @@ -254,14 +256,17 @@ fn ui_signal_t ui_signal_from_box(ui_box_t *box) { result.drag.x -= 1; result.dragging = true; result.clicked = true; + result.press = true; } else if (ev->kind == app_event_kind_key_down && ev->key == app_key_right) { result.drag.x += 1; result.dragging = true; result.clicked = true; + result.press = true; } if (ev->kind == app_event_kind_key_down && ev->key == app_key_enter) { result.clicked = true; + result.press = true; } } @@ -300,7 +305,7 @@ fn ui_draw_compute_t ui_draw_compute(ui_box_t *box) { ui_draw_compute_t co = {0}; co.rect = box->full_rect; - f32 appear_t = f32_ease_out_n(f32_clamp01(box->appear_t*8), 10); + f32 appear_t = f32_ease_out_n(f32_clamp01(box->appear_t * 6), 10); if (!ui_id_is_null(box->id)) { v2f32_t size = v2f32_muls(r2f32_get_size(co.rect), 0.15f); r2f32_t smaller_rect = r2f32_shrink(co.rect, size); @@ -415,7 +420,8 @@ fn_test void ui_test_text_replace(void) { assert(s8_are_equal(ti.string, s8_lit("qaer"))); } -fn ui_signal_t ui_text_input(ui_code_loc_t loc, ui_text_input_t *ti) { +#define ui_text_input(ti) ui__text_input(UILOC, ti) +fn ui_signal_t ui__text_input(ui_code_loc_t loc, ui_text_input_t *ti) { ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_border = true, .draw_rect = true, .draw_text = true, .keyboard_nav = true }, s8_lit("text_input")); box->text_input = ti; box->custom_draw = ui_text_input_draw; @@ -503,7 +509,7 @@ fn ui_signal_t ui__label_button(ui_code_loc_t loc, char *str, ...) { #define ui_label(...) ui__label(UILOC, __VA_ARGS__) fn ui_box_t *ui__label(ui_code_loc_t loc, char *str, ...) { S8_FMT(tcx->temp, str, string); - ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_text = true, .draw_rect = true }, string); + ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_text = true, }, string); return box; } @@ -906,26 +912,71 @@ fn void ui_init(ma_arena_t *arena) { ui_reload(); } +#define ui_reverse_node_order() defer_block(ui_begin_reversal(), ui_end_reversal()) +fn void ui_begin_reversal(void) { + ui->reverse_order_ref = ui->top->last; +} + +fn void ui_end_reversal(void) { + assert(ui->reverse_order_ref); + assert(ui->reverse_order_ref->next); + ui_box_t *first = ui->reverse_order_ref->next; + ui_box_t *last = ui->top->last; + ui->reverse_order_ref = NULL; + + b32 connected = false; + for (ui_box_t *it = first; it; it = it->next) { + if (it == last) { + connected = true; + break; + } + } + assert(connected); + + ui_box_t *first2 = NULL; + ui_box_t *last2 = NULL; + for (ui_box_t *it = first, *next = it->next; next; it = next) { + next = it->next; + DLLQ_REMOVE(it->parent->first, it->parent->last, it); + DLLQ_APPEND(first2, last2, it); + } + + for (ui_box_t *it = last2, *prev = it->prev; prev; it = prev) { + prev = it->prev; + DLLQ_REMOVE(first2, last2, it); + DLLQ_APPEND(it->parent->first, it->parent->last, it); + } +} + + gb app_event_t ui_test_event; -gb i32 ui_g_panel = 1; +gb i32 ui_g_panel = 2; fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_count) { ui_begin_frame(frame); rn_begin_frame(frame); for (app_event_t *ev = frame->first_event; ev; ev = ev->next) { ui_begin_build(UILOC, ev, window_rect_from_frame(frame)); + if (ev->kind == app_event_kind_key_down && ev->key == app_key_f1) { + ui_g_panel = 1; + } else if (ev->kind == app_event_kind_key_down && ev->key == app_key_f2) { + ui_g_panel = 2; + } + ui_box_t *top_box = ui_box0((ui_box_flags_t){.draw_rect = true, .clip_rect = true}); ui_set_rect(top_box, r2f32_cut_top(&ui->top->rect, ui_em(1.5f))); ui_set_padding(ui_em(3)) ui_set_text_align(ui_text_align_center) ui_set_lop(ui_lop_cut_left) ui_set_top(top_box) { - ui_radio_button(&ui_g_panel, 1, "1"); - ui_radio_button(&ui_g_panel, 2, "2"); + ui_radio_button(&ui_g_panel, 1, "data"); + ui_radio_button(&ui_g_panel, 2, "log"); } ui->top->rect = r2f32_shrinks(ui->top->rect, ui_em(1)); + /////////////////////////////// + // First list panel if (ui_g_panel == 1) { ui_box_t *scroller_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "scrollbar"); ui_set_rect(scroller_box, r2f32_cut_right(&ui->top->rect, 10 * frame->dpr)); @@ -943,7 +994,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co text_input.str = buff; text_input.cap = lengthof(buff); } - ui_text_input(UILOC, &text_input); + ui_text_input(&text_input); for (i32 i = 0; i < tweak_count; i += 1) { mt_tweak_t *tweak = tweak_table + i; @@ -969,7 +1020,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co } ui_label("allocated boxes: %d", ui->allocated_boxes); ui_serial_type(&ui_test_event, type(app_event_t)); - ui_set_id(ui_idf("a")) { + ui_set_id(ui_id_from_loc(UILOC)) { ui_serial_type(&ui_test_event, type(app_event_t)); } } @@ -977,8 +1028,9 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co locl f32 scroller_value; defer_block(ui_push_top(scroller_box), ui_pop_top()) { f32 item_count = (f32)item_box->node_count; - f32 all_items_size = item_count * rn->main_font->size; - f32 item_box_size = r2f32_get_size(ui->top->full_rect).y; + f32 one_item_y_size = ui_em(1); + f32 all_items_size = item_count * one_item_y_size; + f32 item_box_size = r2f32_get_size(item_box->full_rect).y; f32 scroller_box_size = r2f32_get_size(scroller_box->full_rect).y; f32 scroller_size = CLAMP(item_box_size / (all_items_size + frame->window_size.y), 0, 1.0f); f32 scrollable_space = (1 - scroller_size); @@ -1004,7 +1056,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co if (signal.dragging) { scroller_value += drag * coef; } - if (upper_box_signal.clicked || down_box_signal.dragging) { + if (upper_box_signal.dragging || down_box_signal.dragging) { scroller_value = (ev->mouse_pos.y - upper_box->final_rect.min.y) * coef; scroller_value -= (slider_box_size / 2) * coef; } @@ -1017,30 +1069,252 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co ui_offset_box(it, v2f32(0, scroller_value)); } } - } else if (ui_g_panel == 2) { - } - // ui_box_t *lister = ui_box0((ui_box_flags_t){.draw_rect = true, .clip_rect = true}); - // ui_set_top(lister) - // ui_set_lop(ui_lop_cut_top) { - // v2f32_t max_size = v2f32_sub(frame->window_size, v2f32(ui_em(2), ui_em(2))); - // v2f32_t _lister_size = v2f32(ui_em(20), ui_em(40)); - // v2f32_t lister_size = v2f32_clamp(_lister_size, v2f32_null, max_size); - // v2f32_t pos = v2f32_divs(v2f32_sub(frame->window_size, lister_size), 2.0); - // r2f32_t rect = r2f32_min_dim(pos, lister_size); - // ui_set_rect(lister, rect); - // lister->background_color.g += 100; + /////////////////////////////// + // Log panel + if (ui_g_panel == 2) { + char *log_lines[] = { + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll ", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll ", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll ", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`22db0000 00007ff9`22dfe000 C:/Windows/System32/powrprof.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`22d90000 00007ff9`22da4000 C:/Windows/System32/umpdc.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`22900000 00007ff9`2295e000 C:/Windows/System32/winsta.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`23080000 00007ff9`2309a000 C:/Windows/System32/kernel.appcore.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`0d900000 00007ff9`0da46000 C:/Windows/System32/TextInputFramework.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1eec0000 00007ff9`1efe5000 C:/Windows/System32/CoreMessaging.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1c680000 00007ff9`1c963000 C:/Windows/System32/CoreUIComponents.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`201d0000 00007ff9`20338000 C:/Windows/System32/WinTypes.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`26860000 00007ff9`26908000 C:/Windows/System32/clbcatq.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`06a80000 00007ff9`06add000 C:/Windows/System32/ApplicationTargetedFeatureDatabase.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`16a50000 00007ff9`16c87000 C:/Windows/System32/twinapi.appcore.dll ", + "[27.01.2025 08:55:20] Thread exited: handle 0x854 with exit code 0 (0x0)", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1c410000 00007ff9`1c51f000 C:/dev/wasm/build/app_temp_2106011489.dll (symbols loaded)", + "opengl message: Buffer detailed info: Buffer object 1 (bound to NONE, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.", + "failed to load library: app_temp_1403378047.dll", + "failed to load library: app_temp_1765879053.dll", + "failed to load library: app_temp_1515670551.dll", + "[27.01.2025 08:55:28] Module loaded: 00007ff9`07c70000 00007ff9`07d7d000 C:/dev/wasm/build/app_temp_2418804559.dll ", + "[27.01.2025 08:55:28] Module loaded: 00007ff9`002c0000 00007ff9`003cf000 C:/dev/wasm/build/app_temp_2347134081.dll (symbols loaded)", + "[27.01.2025 08:55:37] Thread exited: handle 0x8f0 with exit code 0 (0x0)", + "[27.01.2025 08:55:37] Thread exited: handle 0x7f0 with exit code 0 (0x0)", + "[27.01.2025 08:55:37] Thread exited: handle 0x784 with exit code 0 (0x0)", + "[27.01.2025 08:55:37] Thread exited: handle 0x808 with exit code 0 (0x0)", + "[27.01.2025 08:55:37] Thread exited: handle 0x8d4 with exit code 0 (0x0)", + "[27.01.2025 08:55:37] Thread exited: handle 0x920 with exit code 0 (0x0)", + "[27.01.2025 08:55:37] Thread exited: handle 0x8bc with exit code 0 (0x0)", + "[27.01.2025 08:55:37] Thread exited: handle 0x86c with exit code 0 (0x0)", + "[27.01.2025 08:50:16] Module loaded: 00007ff9`0d900000 00007ff9`0da46000 C:/Windows/System32/TextInputFramework.dll ", + "[27.01.2025 08:50:16] Module loaded: 00007ff9`1eec0000 00007ff9`1efe5000 C:/Windows/System32/CoreMessaging.dll ", + "[27.01.2025 08:50:16] Module loaded: 00007ff9`1c680000 00007ff9`1c963000 C:/Windows/System32/CoreUIComponents.dll ", + "[27.01.2025 08:50:16] Module loaded: 00007ff9`201d0000 00007ff9`20338000 C:/Windows/System32/WinTypes.dll ", + "[27.01.2025 08:50:16] Module loaded: 00007ff9`26860000 00007ff9`26908000 C:/Windows/System32/clbcatq.dll ", + "[27.01.2025 08:50:16] Module loaded: 00007ff9`06a80000 00007ff9`06add000 C:/Windows/System32/ApplicationTargetedFeatureDatabase.dll ", + "[27.01.2025 08:50:16] Module loaded: 00007ff9`16a50000 00007ff9`16c87000 C:/Windows/System32/twinapi.appcore.dll ", + "[27.01.2025 08:50:16] Thread exited: handle 0x82c with exit code 0 (0x0)", + "[27.01.2025 08:50:16] Module loaded: 00007ff9`1c410000 00007ff9`1c51f000 C:/dev/wasm/build/app_temp_2106011489.dll (symbols loaded)", + "opengl message: Buffer detailed info: Buffer object 1 (bound to NONE, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.", + "[27.01.2025 08:50:46] Thread exited: handle 0x7d0 with exit code 0 (0x0)", + "[27.01.2025 08:51:46] Thread exited: handle 0x8bc with exit code 0 (0x0)", + "[27.01.2025 08:51:46] Thread exited: handle 0x900 with exit code 0 (0x0)", + "[27.01.2025 08:51:46] Thread exited: handle 0x8cc with exit code 0 (0x0)", + "failed to load library: app_temp_1403378047.dll", + "failed to load library: app_temp_1765879053.dll", + "failed to load library: app_temp_1515670551.dll", + "[27.01.2025 08:53:21] Module loaded: 00007ff9`07c70000 00007ff9`07d7d000 C:/dev/wasm/build/app_temp_2418804559.dll ", + "[27.01.2025 08:53:21] Module loaded: 00007ff9`002c0000 00007ff9`003cf000 C:/dev/wasm/build/app_temp_2347134081.dll (symbols loaded)", + "[27.01.2025 08:53:39] Module loaded: 00007ff8`f7b80000 00007ff8`f7c8e000 C:/dev/wasm/build/app_temp_919248920.dll ", + "[27.01.2025 08:53:39] Module loaded: 00007ff8`f6450000 00007ff8`f655f000 C:/dev/wasm/build/app_temp_3200004952.dll (symbols loaded)", + "failed to load library: app_temp_1322949950.dll", + "[27.01.2025 08:55:14] Module loaded: 00007ff8`f3900000 00007ff8`f3a0d000 C:/dev/wasm/build/app_temp_642754436.dll ", + "[27.01.2025 08:55:14] Module loaded: 00007ff8`e0ed0000 00007ff8`e0fdf000 C:/dev/wasm/build/app_temp_4237056459.dll (symbols loaded)", + "[27.01.2025 08:55:19] Thread exited: handle 0x904 with exit code 0 (0x0)", + "[27.01.2025 08:55:19] Thread exited: handle 0x7d0 with exit code 0 (0x0)", + "[27.01.2025 08:55:19] Thread exited: handle 0x878 with exit code 0 (0x0)", + "[27.01.2025 08:55:19] Thread exited: handle 0x584 with exit code 0 (0x0)", + "[27.01.2025 08:55:19] Thread exited: handle 0x8c0 with exit code 0 (0x0)", + "[27.01.2025 08:55:19] Thread exited: handle 0x8c8 with exit code 0 (0x0)", + "[27.01.2025 08:55:19] Thread exited: handle 0x8f0 with exit code 0 (0x0)", + "[27.01.2025 08:55:19] Process exited: with exit code 0 (0x0)", + "[27.01.2025 08:55:19] Debugging new process...[OK] Process ID: 17200", + "[27.01.2025 08:55:19] Module loaded: 00007ff6`a9fb0000 00007ff6`aa056000 C:/dev/wasm/build/app_win32.exe (symbols loaded)", + "[27.01.2025 08:55:19] Module loaded: 00007ff9`26d60000 00007ff9`26fc3000 C:/Windows/System32/ntdll.dll ", + "[27.01.2025 08:55:19] Module loaded: 00007ff9`25c00000 00007ff9`25cc8000 C:/Windows/System32/kernel32.dll ", + "[27.01.2025 08:55:19] Module loaded: 00007ff9`24800000 00007ff9`24bb2000 C:/Windows/System32/KernelBase.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`217a0000 00007ff9`217ce000 C:/Windows/System32/dwmapi.dll ", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll ", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll ", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll ", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`26ac0000 00007ff9`26ac8000 C:/Windows/System32/psapi.dll", + "[27.01.2025 08:55:20] Module unloaded: 00007ff9`1a760000 00007ff9`1a9a1000 C:/Windows/System32/dbghelp.dll", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`22db0000 00007ff9`22dfe000 C:/Windows/System32/powrprof.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`22d90000 00007ff9`22da4000 C:/Windows/System32/umpdc.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`22900000 00007ff9`2295e000 C:/Windows/System32/winsta.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`23080000 00007ff9`2309a000 C:/Windows/System32/kernel.appcore.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`0d900000 00007ff9`0da46000 C:/Windows/System32/TextInputFramework.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1eec0000 00007ff9`1efe5000 C:/Windows/System32/CoreMessaging.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1c680000 00007ff9`1c963000 C:/Windows/System32/CoreUIComponents.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`201d0000 00007ff9`20338000 C:/Windows/System32/WinTypes.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`26860000 00007ff9`26908000 C:/Windows/System32/clbcatq.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`06a80000 00007ff9`06add000 C:/Windows/System32/ApplicationTargetedFeatureDatabase.dll ", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`16a50000 00007ff9`16c87000 C:/Windows/System32/twinapi.appcore.dll ", + "[27.01.2025 08:55:20] Thread exited: handle 0x854 with exit code 0 (0x0)", + "[27.01.2025 08:55:20] Module loaded: 00007ff9`1c410000 00007ff9`1c51f000 C:/dev/wasm/build/app_temp_2106011489.dll (symbols loaded)", + "opengl message: Buffer detailed info: Buffer object 1 (bound to NONE, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.", + "failed to load library: app_temp_1403378047.dll", + "failed to load library: app_temp_1765879053.dll", + "failed to load library: app_temp_1515670551.dll", + }; + + locl f32 item_count; + if (item_count == 0) { + item_count = lengthof(log_lines) * 2; + } + + ui_set_padding(ui_em(3)) + ui_set_text_align(ui_text_align_center) + ui_set_lop(ui_lop_cut_right) + ui_set_top(top_box) + ui_reverse_node_order() { + if (ui_button("C").clicked) { + item_count = lengthof(log_lines); + } + if (ui_button("B").clicked) { + item_count = lengthof(log_lines) * 4; + } + if (ui_button("A").clicked) { + item_count = 4; + } + } + + ui_box_t *scroller_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "scrollbar"); + ui_set_rect(scroller_box, r2f32_cut_right(&ui->top->rect, 10 * frame->dpr)); + + ui_box_t *item_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "item_box"); + ui_set_rect(item_box, r2f32_cut_left(&ui->top->rect, ui_max)); + + locl f32 scroller_value; + + f32 one_item_y_size = ui_em(1); + f32 all_items_size = item_count * one_item_y_size; + f32 item_box_size = r2f32_get_size(item_box->full_rect).y; + f32 visible_item_count = f32_ceil(item_box_size / one_item_y_size); + f32 render_start_count = f32_floor(scroller_value / one_item_y_size); + + i32 istart = (i32)render_start_count; + i32 iend = (i32)render_start_count + (i32)visible_item_count; + istart = CLAMP(istart, 0, (i32)item_count); + iend = CLAMP(iend, 0, (i32)item_count); + + r2f32_cut_top_no_squash(&item_box->rect, render_start_count * one_item_y_size); + ui_set_top(item_box) { + for (i32 i = istart; i full_rect).y; + f32 scroller_size = CLAMP(item_box_size / (all_items_size + frame->window_size.y), 0, 1.0f); + f32 scrollable_space = (1 - scroller_size); + f32 scroller_norm = scroller_value / (all_items_size); + f32 scroller_percent = scroller_norm * scrollable_space; + + ui_box_t *upper_box = ui_boxf((ui_box_flags_t){.draw_rect = true}, "upper_box"); + ui_box_t *slider_box = ui_boxf((ui_box_flags_t){.draw_rect = true}, "slider_box"); + ui_box_t *down_box = ui_boxf((ui_box_flags_t){.draw_rect = true}, "down_box"); + ui_set_rect(upper_box, r2f32_cut_top(&ui->top->rect, scroller_percent * scroller_box_size)); + ui_set_rect(slider_box, r2f32_cut_top(&ui->top->rect, scroller_size * scroller_box_size)); + ui_set_rect(down_box, r2f32_cut_top(&ui->top->rect, ui_max)); + slider_box->background_color = ui_color_table[ui_color_scroller]; + slider_box->bg_hot_color = ui_color_table[ui_color_scroller_hot]; + slider_box->bg_active_color = ui_color_table[ui_color_scroller_active]; + ui_signal_t signal = ui_signal_from_box(slider_box); + ui_signal_t upper_box_signal = ui_signal_from_box(upper_box); + ui_signal_t down_box_signal = ui_signal_from_box(down_box); + f32 drag = ev->mouse_delta.y; + f32 coef = (all_items_size / item_box_size) / scrollable_space; + if (signal.dragging) { + scroller_value += drag * coef; + } + if (upper_box_signal.dragging || down_box_signal.dragging) { + scroller_value = (ev->mouse_pos.y - upper_box->full_rect.min.y) * coef; + scroller_value -= (r2f32_get_size(slider_box->full_rect).y / 2) * coef; + } + if (ev->kind == app_event_kind_mouse_wheel) { + scroller_value -= ev->mouse_wheel_delta.y; + } + scroller_value = CLAMP(scroller_value, 0, all_items_size); + + for (ui_box_t *it = item_box->first; it; it = it->next) { + ui_offset_box(it, v2f32(0, scroller_value)); + } + } + } + + + ui_id_t lister_id = ui_id_from_loc(UILOC); + locl b32 lister_open; + b32 lister_just_opened = false; + if (ev->kind == app_event_kind_key_down && ev->key == app_key_p && ev->ctrl) { + lister_open = !lister_open; + if (lister_open) lister_just_opened = true; + } + + if (lister_open) { + ui_box_t *lister = ui_box((ui_box_flags_t){.draw_rect = true, .draw_border = true, .clip_rect = true}, lister_id); + ui_set_top(lister) + ui_set_lop(ui_lop_cut_top) { + v2f32_t max_size = v2f32_sub(frame->window_size, v2f32(ui_em(2), ui_em(2))); + v2f32_t _lister_size = v2f32(ui_em(50), ui_em(40)); + v2f32_t lister_size = v2f32_clamp(_lister_size, v2f32_null, max_size); + v2f32_t pos = v2f32_divs(v2f32_sub(frame->window_size, lister_size), 2.0); + r2f32_t rect = r2f32_min_dim(pos, lister_size); + ui_set_rect(lister, rect); + + locl char buff[128]; + locl ui_text_input_t text_input; + if (text_input.str == NULL) { + text_input.str = buff; + text_input.cap = lengthof(buff); + } + ui_signal_t ti_sig = ui_text_input(&text_input); + if (lister_just_opened) ui->focus = ti_sig.box->id; + + ui_label("[27.01.2025 08:55:20] Module loaded: 00007ff9`26860000 00007ff9`26908000 C:/Windows/System32/clbcatq.dll "); + ui_label("[27.01.2025 08:55:20] Module loaded: 00007ff9`06a80000 00007ff9`06add000 C:/Windows/System32/ApplicationTargetedFeatureDatabase.dll "); + ui_label("[27.01.2025 08:55:20] Module loaded: 00007ff9`16a50000 00007ff9`16c87000 C:/Windows/System32/twinapi.appcore.dll "); + ui_label("[27.01.2025 08:55:20] Thread exited: handle 0x854 with exit code 0 (0x0)"); + ui_label("[27.01.2025 08:55:20] Module loaded: 00007ff9`1c410000 00007ff9`1c51f000 C:/dev/wasm/build/app_temp_2106011489.dll (symbols loaded)"); + ui_label("opengl message: Buffer detailed info: Buffer object 1 (bound to NONE, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations."); + ui_label("failed to load library: app_temp_1403378047.dll"); + ui_label("failed to load library: app_temp_1765879053.dll"); + ui_label("failed to load library: app_temp_1515670551.dll"); + } + } - // locl char buff[128]; - // locl ui_text_input_t text_input; - // if (text_input.str == NULL) { - // text_input.str = buff; - // text_input.cap = lengthof(buff); - // } - // ui_text_input(UILOC, &text_input); - // } ui_end_build(); } diff --git a/src/ui/ui.h b/src/ui/ui.h index e5a2eb1..62a6944 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -106,6 +106,7 @@ typedef struct ui_signal_t ui_signal_t; struct ui_signal_t { ui_box_t *box; b8 clicked; + b8 press; b8 dragging; v2f32_t drag; }; @@ -118,6 +119,7 @@ struct ui_t { ui_box_t root; ui_box_t *top; app_event_t *event; + ui_box_t *reverse_order_ref; UI_DECL_STACKS diff --git a/src/wasm_app/main.c b/src/wasm_app/main.c index f2677bd..c963645 100644 --- a/src/wasm_app/main.c +++ b/src/wasm_app/main.c @@ -14,8 +14,8 @@ fn_export b32 app_update(thread_ctx_t *thread_ctx, app_frame_t *frame) { if (frame->first_event->kind == app_event_kind_init) { run_all_tests(); - mt_tweak_f32(font_size, 50, 4, 200); - mt_tweak_f32(_font_size, 50, 50, 50); + mt_tweak_f32(font_size, 30, 4, 200); + mt_tweak_f32(_font_size, 30, 30, 30); ma_arena_t *perm = &tcx->perm; rn_init(perm, font_size, frame->dpr); diff --git a/src/wasm_app/wasm_app.gen.c b/src/wasm_app/wasm_app.gen.c index 6229385..ac14cdf 100644 --- a/src/wasm_app/wasm_app.gen.c +++ b/src/wasm_app/wasm_app.gen.c @@ -1,9 +1,9 @@ // automatically generated using: C:\dev\wasm\src/wasm_app/wasm_app.meta.c -gb f32 font_size = 50; -gb f32 _font_size = 50; +gb f32 font_size = 30; +gb f32 _font_size = 30; gb_read_only mt_tweak_t tweak_table[] = { {type(f32), s8_const_lit("font_size"), &font_size, 4, 200}, - {type(f32), s8_const_lit("_font_size"), &_font_size, 50, 50}, + {type(f32), s8_const_lit("_font_size"), &_font_size, 30, 30}, }; void run_all_tests(void) {