diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-11-10 11:40:08 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-11-10 11:40:08 -0500 |
| commit | 9a2d0d05350cae88bcbfd403941d5adf21b19451 (patch) | |
| tree | d34cc3011bb32f9cb9f9fe4afe27a34d1a699957 | |
| parent | e40814b646af877f90834036f4f1cbac9e34be83 (diff) | |
pke: static-ui add pixel-perfect flag
| -rw-r--r-- | editor/editor.cpp | 15 | ||||
| -rw-r--r-- | src/static-ui.cpp | 27 | ||||
| -rw-r--r-- | src/static-ui.hpp | 6 |
3 files changed, 43 insertions, 5 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index 2a53b61..a1b8613 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -1513,6 +1513,16 @@ void RecordImGuiUIEdit() { changed = true; } ImGui::Separator(); + if (ImGui::CheckboxFlags("flag: Visibility Invisible", reinterpret_cast<PKE_UI_BOX_FLAG_T*>(&selected_ui_box->flags), static_cast<PKE_UI_BOX_FLAG_T>(PKE_UI_BOX_FLAG_VISIBILITY_INVISIBLE))) { + changed = true; + } + if (ImGui::CheckboxFlags("flag: Visibility Disabled", reinterpret_cast<PKE_UI_BOX_FLAG_T*>(&selected_ui_box->flags), static_cast<PKE_UI_BOX_FLAG_T>(PKE_UI_BOX_FLAG_VISIBILITY_DISABLED))) { + changed = true; + } + if (ImGui::CheckboxFlags("flag: Visibility Pixel Perfect", reinterpret_cast<PKE_UI_BOX_FLAG_T*>(&selected_ui_box->flags), static_cast<PKE_UI_BOX_FLAG_T>(PKE_UI_BOX_FLAG_VISIBILITY_PIXEL_PERFECT))) { + changed = true; + } + ImGui::Separator(); changed = ImGui::InputScalarN("flags", ImGuiDataType_U64, &selected_ui_box->flags, 1, nullptr, nullptr, nullptr, ImGuiInputTextFlags_ReadOnly) || changed; changed = ImGui::InputScalarN("pos_top_left", ImGuiDataType_Float, &selected_ui_box->pos_top_left, 2, nullptr, nullptr, nullptr, 0) || changed; @@ -1521,6 +1531,7 @@ void RecordImGuiUIEdit() { if (PK_HAS_FLAG(selected_ui_box->flags, PKE_UI_BOX_FLAG_POSITION_TYPE_FLEX)) { changed = ImGui::InputScalarN("flex_weight", ImGuiDataType_Float, &selected_ui_box->flex_weight, 1, nullptr, nullptr, nullptr, 0) || changed; } + changed = ImGui::InputScalarN("flex_padding", ImGuiDataType_Float, &selected_ui_box->flex_padding, 1, nullptr, nullptr, nullptr, 0) || changed; changed = ImGui::InputScalarN("flex_direction", ImGuiDataType_U8, &selected_ui_box->flex_direction, 1, nullptr, nullptr, nullptr, 0) || changed; changed = ImGui::InputScalarN("layer", ImGuiDataType_U8, &selected_ui_box->layer, 1, nullptr, nullptr, nullptr, 0) || changed; if (PK_HAS_FLAG(selected_ui_box->flags, PKE_UI_BOX_FLAG_VISIBILITY_INVISIBLE) == false) { @@ -1528,6 +1539,10 @@ void RecordImGuiUIEdit() { changed = ImGui::ColorEdit4("color_background", &selected_ui_box->color_background[0]) || changed; } + ImGui::Text("Internal:"); + ImGui::Text("px_corner: %0.3f : %0.3f", selected_ui_box->internal.px_corner.x, selected_ui_box->internal.px_corner.y); + ImGui::Text("px_size: %0.3f : %0.3f", selected_ui_box->internal.px_size.x, selected_ui_box->internal.px_size.y); + if (selected_ui_box->type == PKE_UI_BOX_TYPE_TEXT) { assert(selected_ui_box->type_data != NULL); ImGui::Text("Type: Text"); diff --git a/src/static-ui.cpp b/src/static-ui.cpp index c61b0aa..1204879 100644 --- a/src/static-ui.cpp +++ b/src/static-ui.cpp @@ -267,7 +267,7 @@ struct pke_ui_flex_params { 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, uint8_t child_index) { assert(box != nullptr); pke_ui_box_count_T i; - float flex_padding; + float flex_padding, l, t; glm::vec2 px_size; glm::vec2 px_min_size; glm::vec2 px_max_size; @@ -400,6 +400,19 @@ bool pke_ui_calc_px(pk_arr_t<pke_ui_box_instance_buffer_item> &buffer, pk_arr_t< box->internal.px_size.x = px_size.x; box->internal.px_size.y = px_size.y; + if (PK_HAS_FLAG(box->flags, PKE_UI_BOX_FLAG_VISIBILITY_PIXEL_PERFECT)) { + l = fmod(box->internal.px_corner.x, 1.0); + t = fmod(box->internal.px_corner.y, 1.0); + box->internal.px_corner.x -= l; + box->internal.px_corner.y -= t; + box->internal.px_size.x += l; + box->internal.px_size.y += t; + l = fmod(box->internal.px_size.x, 1.0); + t = fmod(box->internal.px_size.y, 1.0); + box->internal.px_size.x += 1.0 - l; + box->internal.px_size.y += 1.0 - t; + } + // type-specific changes FontRenderSettings frs; switch (box->type) { @@ -537,13 +550,21 @@ void pke_ui_recalc_sizes_recursive(pk_arr_t<pke_ui_box_instance_buffer_item> &ar return; } if (flex_count != 0) { - assert(box->flex_padding == box->flex_padding); // NaN + assert(!glm::isnan(box->flex_padding)); available_size = box->flex_direction == 0 ? (box->internal.px_size.x - box->internal.px_padding_l - box->internal.px_padding_r) : (box->internal.px_size.y - box->internal.px_padding_t - box->internal.px_padding_b); available_size -= (float)(flex_count+1) * (box->flex_padding); - flex_params.px_per_unit = available_size / flex_params.unit_total; + if (PK_HAS_FLAG(box->flags, PKE_UI_BOX_FLAG_VISIBILITY_PIXEL_PERFECT)) { + assert(fmod(box->flex_padding, 1.0) == 0.0); + available_size = floor(available_size); + flex_params.px_per_unit = available_size / flex_params.unit_total; + flex_params.px_per_unit = floor(flex_params.px_per_unit); + } else { + available_size -= (float)(flex_count+1) * (box->flex_padding); + flex_params.px_per_unit = available_size / flex_params.unit_total; + } } for (pke_ui_box_count_T i = 0; i < box->internal.h_children; ++i) { diff --git a/src/static-ui.hpp b/src/static-ui.hpp index 17301a1..9972b92 100644 --- a/src/static-ui.hpp +++ b/src/static-ui.hpp @@ -65,12 +65,14 @@ const PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_CENTER_VERTICAL = PKE_UI_BOX_FLAG((1 << 6)); const PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_CENTER_BOTH = PKE_UI_BOX_FLAG((1 << 5) | (1 << 6)); -// [07-09] visibility +// [07-14] visibility const PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_VISIBILITY_INVISIBLE = PKE_UI_BOX_FLAG((1 << 7)); const PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_VISIBILITY_DISABLED = PKE_UI_BOX_FLAG((1 << 8)); -// [10-??] +const PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_VISIBILITY_PIXEL_PERFECT + = PKE_UI_BOX_FLAG((1 << 9)); +// [14-??] // PKE_UI_BOX_STATE_FLAG represent the current state THIS TICK. // So, e.g. |
