diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-06-16 09:51:00 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-06-16 09:51:00 -0400 |
| commit | 66ebed74456f76277597b3b07f3e67cc45388ece (patch) | |
| tree | 5e7d0c429867a294bca78269124954ce0a4823fc /editor | |
| parent | c1ad6ceeb301bc1f2a4f850e08587748a6d9107b (diff) | |
pke: update FontRender text (editor: for ui-box)
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/editor.cpp | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index b48a40e..9257f6a 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -24,6 +24,7 @@ #include "static-ui.hpp" #include "thread-pool.hpp" #include "vendor-glm-include.hpp" +#include "vendor-imgui-ext.hpp" #include "vendor-tinyfiledialogs.h" #include "window.hpp" #include "pk.h" @@ -65,12 +66,21 @@ bool shouldDisableEditor = false; bool shouldRebuildProjectDir = true; bool shouldRebuildAssetList = true; +// TODO Can't make certain changes *this* tick through DearImGui. +// ex: Changing text in a FontRender, adding an instance, etc. +// Specifically when it causes a vulkan buffer resize. +// Each "should" should be refactored *out* of the editor. +// ex: ecs should be responsible for creating instances in a deferred manner. +// - COULD lead to ugly callbacks or listeners? +// Suggestion: Consider a minor engine change that adds a post-tick phase, so that if the engine sleeps we don't slow down the next tick when it can be avoided. +// Note: Could have ecs implications (marked for removal, etc) pk_arr_t<EntityType *> entityInstancesToCreate{}; CompInstance *selectedEntity = nullptr; CompInstance *hoveredEntity = nullptr; bool shouldCreateEntityType = false; EntityType entityTypeToCreate{}; CameraHandle selectedCamera = CameraHandle_MAX; +static pke_ui_box *selected_ui_box = NULL; const char* const newSceneName = "newScene.pstf"; bool shouldOpenLoadSceneDialog = false; @@ -228,6 +238,7 @@ void PkeEditor_Tick(double delta) { const PkeMouseButtonEvent *mbEvent = static_cast<PkeMouseButtonEvent *>(holder.ptr); if (mbEvent->isPressed) { selectedEntity = nullptr; + selected_ui_box = nullptr; } } } @@ -1225,6 +1236,122 @@ void RecordImGuiCameras() { ImGui::End(); } +void RecordImGuiUITree_inner(pke_ui_box *box) { + if (ImGui::TreeNode(box, pk_uuid_printf_format, pk_uuid_printf_var(box->uuid))) { + ImGui::SameLine(); + if (ImGui::Selectable("SELECT", false, 0)) { + selected_ui_box = box; + } + for (int i = 0; i < box->internal.h_children; ++i) { + RecordImGuiUITree_inner(box->internal.children[i]); + } + ImGui::TreePop(); + } +} +void RecordImGuiUITree() { + if (!ImGui::Begin("pke_ui_tree")) { + ImGui::End(); + return; + } + pke_ui_box_count_T count; + pke_ui_box ** root_boxes = pke_ui_get_root_boxes(&count); + for (int i = 0; i < count; ++i) { + pke_ui_box *box = root_boxes[i]; + RecordImGuiUITree_inner(box); + } + // if (ImGui::Selectable( + ImGui::End(); +} +void RecordImGuiUIEdit() { + const ImGuiInputTextFlags text_flags = ImGuiInputTextFlags_AllowTabInput; + bool changed; + if (!ImGui::Begin("pke_ui_edit")) { + ImGui::End(); + return; + } + if (selected_ui_box == NULL) { + ImGui::End(); + return; + } + + changed = false; + + ImGui::Text("Position Type:"); + ImGui::BeginDisabled(PK_HAS_FLAG(selected_ui_box->flags, PKE_UI_BOX_FLAG_POSITION_TYPE_FLEX)); + if (ImGui::Button("Flex")) { + selected_ui_box->flags &= ~(const_cast<PKE_UI_BOX_FLAG&>(PKE_UI_BOX_FLAG_POSITION_TYPE_ALL)); + selected_ui_box->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_FLEX; + changed = true; + } + ImGui::EndDisabled(); + ImGui::SameLine(); + ImGui::BeginDisabled(PK_HAS_FLAG(selected_ui_box->flags, PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC)); + if (ImGui::Button("Static")) { + selected_ui_box->flags &= ~(const_cast<PKE_UI_BOX_FLAG&>(PKE_UI_BOX_FLAG_POSITION_TYPE_ALL)); + selected_ui_box->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC; + changed = true; + } + ImGui::EndDisabled(); + ImGui::SameLine(); + ImGui::BeginDisabled(PK_HAS_FLAG(selected_ui_box->flags, PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC)); + if (ImGui::Button("Dynamic")) { + selected_ui_box->flags &= ~(const_cast<PKE_UI_BOX_FLAG&>(PKE_UI_BOX_FLAG_POSITION_TYPE_ALL)); + selected_ui_box->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC; + changed = true; + } + ImGui::EndDisabled(); + + ImGui::Separator(); + + if (ImGui::CheckboxFlags("flag: Center Horizontal", reinterpret_cast<PKE_UI_BOX_FLAG_T*>(&selected_ui_box->flags), static_cast<PKE_UI_BOX_FLAG_T>(PKE_UI_BOX_FLAG_CENTER_HORIZONTAL))) { + changed = true; + } + if (ImGui::CheckboxFlags("flag: Center Vertical", reinterpret_cast<PKE_UI_BOX_FLAG_T*>(&selected_ui_box->flags), static_cast<PKE_UI_BOX_FLAG_T>(PKE_UI_BOX_FLAG_CENTER_VERTICAL))) { + 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; + changed = ImGui::InputScalarN("min_size", ImGuiDataType_Float, &selected_ui_box->min_size, 2, nullptr, nullptr, nullptr, 0) || changed; + changed = ImGui::InputScalarN("max_size", ImGuiDataType_Float, &selected_ui_box->max_size, 2, nullptr, nullptr, nullptr, 0) || changed; + changed = ImGui::InputScalarN("flex_weight", ImGuiDataType_Float, &selected_ui_box->flex_weight, 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 (selected_ui_box->type == PKE_UI_BOX_TYPE_TEXT) { + assert(selected_ui_box->type_data != NULL); + ImGui::Text("Type: Text"); + ImGui::Separator(); + FontRender fr = *FontType_GetFontRender(selected_ui_box->type_data->text.font_render_handle); + const int buffer_len = 1024; + char *text_buffer = pk_new<char>(buffer_len, pkeSettings.mem_bkt.game_transient); + size_t len = fr.text.length; + sprintf(text_buffer, "%s", fr.text.val); + // nocheckin test this + if (ImGui::InputText("Text", text_buffer, buffer_len-1, text_flags)) { + // TODO specific bucket + len = strlen(text_buffer); + char *s = pk_new<char>(len + 1); + sprintf(s, "%s", text_buffer); + pk_cstr cstr{}; + cstr.reserved = len+1; + cstr.length = len; + cstr.val = s; + FontType_UpdateStringRenderText(fr.fr_handle, std::move(cstr)); + changed = true; + } + ImGui::SameLine(); + ImGui::Text("(%.4zu/%4i)", len, buffer_len); + } + + if (changed) { + pke_ui_force_recalc(); + } + + ImGui::End(); +} + void RecordImGuiUBO() { if (!ImGui::Begin("UBO", &pkeSettings.editorSettings.isShowingUBO)) { ImGui::End(); @@ -1784,6 +1911,8 @@ void PkeEditor_RecordImGui() { RecordImGuiSceneEditor(); RecordImGuiUBO(); RecordImGuiCameras(); + RecordImGuiUITree(); + RecordImGuiUIEdit(); RecordImGuiLevels(); RecordImGuiEntityTypes(); RecordImGuiAssets(); |
