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.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "editor_manager.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#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<std::chrono::milliseconds>(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);
|
||||
|
||||
@@ -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<uint8_t> 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<uint8_t>(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<uint16_t>(temp & 0xFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui::PopID();
|
||||
return changed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user