diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-09-29 15:05:36 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-09-29 15:05:36 -0400 |
| commit | 38118ca060f28749eb7be02c83b2e109cdb63b52 (patch) | |
| tree | 93fea5dfe4c220c5d7733815fe33ace35d7a4542 /src | |
| parent | 0ee2243d459cbbf0f119249012c7e3787937607a (diff) | |
pke: static-ui input deactivate + remove children
Diffstat (limited to 'src')
| -rw-r--r-- | src/static-ui.cpp | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/static-ui.cpp b/src/static-ui.cpp index f3d0810..255d81d 100644 --- a/src/static-ui.cpp +++ b/src/static-ui.cpp @@ -53,7 +53,7 @@ struct pke_ui_master { bool should_update_buffer = false; glm::vec2 px_scale; pk_arr_t<pke_input_event> events_this_tick; - pke_input_action_set_handle input_action_set_handle; + pke_input_action_set_handle input_action_set_handle = pke_input_action_set_handle_MAX; struct pke_ui_master_state { const pke_input_event *mouse_left = nullptr; const pke_input_event *mouse_right = nullptr; @@ -247,15 +247,37 @@ struct pke_ui_flex_params { float used_units; }; -void pke_ui_calc_px(pk_arr_t<pke_ui_box_instance_buffer_item> &buffer, pk_arr_t<std::pair<pke_ui_box*,pke_ui_box_instance_buffer_item>> &tmp_txtr_buffer, pke_ui_flex_params *flex_params, pke_ui_box *box) { +bool pke_ui_calc_px(pk_arr_t<pke_ui_box_instance_buffer_item> &buffer, pk_arr_t<std::pair<pke_ui_box*,pke_ui_box_instance_buffer_item>> &tmp_txtr_buffer, pke_ui_flex_params *flex_params, pke_ui_box *box) { assert(box != nullptr); + pke_ui_box_count_T i; glm::vec2 px_size; glm::vec2 px_min_size; glm::vec2 px_max_size; glm::vec2 parent_size_padded; glm::vec2 parent_pos_and_offset; - if (box->isMarkedForRemoval == true) return; + if (box->isMarkedForRemoval == true) { + // root + if (box->internal.parent == nullptr) { + // this shouldn't happen + return true; + } + // TODO simplify + for (i = 0; i < box->internal.parent->internal.h_children; ++i) { + if (box->internal.parent->internal.children[i] == box) { + break; + } + } + for (; i < box->internal.parent->internal.h_children; ++i) { + if (i+1 >= box->internal.parent->internal.r_children) { + box->internal.parent->internal.children[i] = nullptr; + break; + } + box->internal.parent->internal.children[i] = box->internal.parent->internal.children[i+1]; + } + box->internal.parent->internal.h_children -= 1; + return false; + } assert(box->pos_top_left.x >= 0.0); assert(box->pos_top_left.y >= 0.0); @@ -388,7 +410,7 @@ void pke_ui_calc_px(pk_arr_t<pke_ui_box_instance_buffer_item> &buffer, pk_arr_t< } if (PK_HAS_FLAG(box->flags, PKE_UI_BOX_FLAG_VISIBILITY_INVISIBLE)) { - return; + return true; } // update buffer @@ -431,6 +453,7 @@ void pke_ui_calc_px(pk_arr_t<pke_ui_box_instance_buffer_item> &buffer, pk_arr_t< } else { pk_arr_append_t(&buffer, tmp); } + return true; } void pke_ui_recalc_sizes_recursive(pk_arr_t<pke_ui_box_instance_buffer_item> &arr, pk_arr_t<std::pair<pke_ui_box*,pke_ui_box_instance_buffer_item>> &tmp_txtr_buffer, pke_ui_box *box) { @@ -468,7 +491,10 @@ void pke_ui_recalc_sizes_recursive(pk_arr_t<pke_ui_box_instance_buffer_item> &ar } for (pke_ui_box_count_T i = 0; i < box->internal.h_children; ++i) { - pke_ui_calc_px(arr, tmp_txtr_buffer, &flex_params, box->internal.children[i]); + if (!pke_ui_calc_px(arr, tmp_txtr_buffer, &flex_params, box->internal.children[i])) { + i -= 1; + continue; + } pke_ui_recalc_sizes_recursive(arr, tmp_txtr_buffer, box->internal.children[i]); } } @@ -614,8 +640,13 @@ void pke_ui_tick(double delta) { pke_ui_master.h_root_boxes -= 1; i -= 1; pke_ui_master.should_update_buffer = true; + if (pke_ui_master.h_root_boxes == 0) { + pke_input_deactivate_set(pke_ui_master.input_action_set_handle); + break; + } continue; } + // root boxes marked for removal were already skipped pke_ui_calc_px(arr, tmp_txtr_arr, nullptr, box); pke_ui_recalc_sizes_recursive(arr, tmp_txtr_arr, box); } |
