From e924529944703b8f99325a989881efed2538174f Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 25 Sep 2025 17:36:04 -0400 Subject: [PATCH] Enhance EditorManager and input handling with performance logging and UI improvements - Added performance logging to the LoadAssets method in EditorManager, tracking the time taken to load ROM assets. - Implemented lazy loading of workspace presets in the DrawLayoutPresets method to improve UI responsiveness. - Refactored menu item handling in the DrawMenu function to streamline the display of subitems and separators, enhancing user interaction. --- src/app/editor/editor_manager.cc | 15 +++++++++++ src/app/gui/input.cc | 44 +++++++++++++++----------------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/app/editor/editor_manager.cc b/src/app/editor/editor_manager.cc index d8cf1095..c250f5b9 100644 --- a/src/app/editor/editor_manager.cc +++ b/src/app/editor/editor_manager.cc @@ -1,5 +1,7 @@ #include "editor_manager.h" +#include + #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -1190,6 +1192,9 @@ absl::Status EditorManager::LoadAssets() { if (!current_rom_ || !current_editor_set_) { return absl::FailedPreconditionError("No ROM or editor set loaded"); } + + auto start_time = std::chrono::steady_clock::now(); + current_editor_set_->overworld_editor_.Initialize(); current_editor_set_->message_editor_.Initialize(); ASSIGN_OR_RETURN(*gfx::Arena::Get().mutable_gfx_sheets(), @@ -1202,6 +1207,11 @@ absl::Status EditorManager::LoadAssets() { RETURN_IF_ERROR(current_editor_set_->message_editor_.Load()); RETURN_IF_ERROR(current_editor_set_->music_editor_.Load()); RETURN_IF_ERROR(current_editor_set_->palette_editor_.Load()); + + auto end_time = std::chrono::steady_clock::now(); + auto duration = std::chrono::duration_cast(end_time - start_time); + util::logf("ROM assets loaded in %lld ms", duration.count()); + return absl::OkStatus(); } @@ -1715,6 +1725,11 @@ void EditorManager::DrawLayoutPresets() { ImGui::Separator(); ImGui::Text("%s Custom Presets", ICON_MD_BOOKMARK); + // Lazy load workspace presets when UI is accessed + if (!workspace_presets_loaded_) { + RefreshWorkspacePresets(); + } + for (const auto& preset : workspace_presets_) { if (ImGui::Button(absl::StrFormat("%s %s", ICON_MD_BOOKMARK, preset.c_str()).c_str(), ImVec2(-1, 0))) { LoadWorkspacePreset(preset); diff --git a/src/app/gui/input.cc b/src/app/gui/input.cc index add5d00e..8394dbda 100644 --- a/src/app/gui/input.cc +++ b/src/app/gui/input.cc @@ -402,24 +402,22 @@ void DrawMenu(Menu& menu) { if (!each_item.subitems.empty()) { if (ImGui::BeginMenu(each_item.name.c_str())) { for (const auto& each_subitem : each_item.subitems) { - if (ImGui::MenuItem(each_subitem.name.c_str(), - each_subitem.shortcut.c_str())) { - if (each_subitem.callback) each_subitem.callback(); - } else if (each_subitem.name == kSeparator) { + if (each_subitem.name == kSeparator) { ImGui::Separator(); + } else if (ImGui::MenuItem(each_subitem.name.c_str(), + each_subitem.shortcut.c_str())) { + if (each_subitem.callback) each_subitem.callback(); } } ImGui::EndMenu(); } - } else if (each_item.name == kSeparator) { - ImGui::Separator(); } else { - if (ImGui::MenuItem(each_item.name.c_str(), + if (each_item.name == kSeparator) { + ImGui::Separator(); + } else if (ImGui::MenuItem(each_item.name.c_str(), each_item.shortcut.c_str(), each_item.enabled_condition())) { if (each_item.callback) each_item.callback(); - } else if (each_item.name == kSeparator) { - ImGui::Separator(); } } } @@ -463,46 +461,46 @@ void MemoryEditorPopup(const std::string& label, std::span memory) { // Custom hex input functions that properly respect width bool InputHexByteCustom(const char* label, uint8_t* data, float input_width) { ImGui::PushID(label); - + // Create a simple hex input that respects width char buf[8]; snprintf(buf, sizeof(buf), "%02X", *data); - + ImGui::SetNextItemWidth(input_width); - bool changed = ImGui::InputText(label, buf, sizeof(buf), - ImGuiInputTextFlags_CharsHexadecimal | - ImGuiInputTextFlags_AutoSelectAll); - + bool changed = ImGui::InputText( + label, buf, sizeof(buf), + ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_AutoSelectAll); + if (changed) { unsigned int temp; if (sscanf(buf, "%X", &temp) == 1) { *data = static_cast(temp & 0xFF); } } - + ImGui::PopID(); return changed; } bool InputHexWordCustom(const char* label, uint16_t* data, float input_width) { ImGui::PushID(label); - + // Create a simple hex input that respects width char buf[8]; snprintf(buf, sizeof(buf), "%04X", *data); - + ImGui::SetNextItemWidth(input_width); - bool changed = ImGui::InputText(label, buf, sizeof(buf), - ImGuiInputTextFlags_CharsHexadecimal | - ImGuiInputTextFlags_AutoSelectAll); - + bool changed = ImGui::InputText( + label, buf, sizeof(buf), + ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_AutoSelectAll); + if (changed) { unsigned int temp; if (sscanf(buf, "%X", &temp) == 1) { *data = static_cast(temp & 0xFFFF); } } - + ImGui::PopID(); return changed; }