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 "editor_manager.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "absl/strings/match.h"
|
#include "absl/strings/match.h"
|
||||||
#include "absl/strings/str_cat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
@@ -1190,6 +1192,9 @@ absl::Status EditorManager::LoadAssets() {
|
|||||||
if (!current_rom_ || !current_editor_set_) {
|
if (!current_rom_ || !current_editor_set_) {
|
||||||
return absl::FailedPreconditionError("No ROM or editor set loaded");
|
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_->overworld_editor_.Initialize();
|
||||||
current_editor_set_->message_editor_.Initialize();
|
current_editor_set_->message_editor_.Initialize();
|
||||||
ASSIGN_OR_RETURN(*gfx::Arena::Get().mutable_gfx_sheets(),
|
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_->message_editor_.Load());
|
||||||
RETURN_IF_ERROR(current_editor_set_->music_editor_.Load());
|
RETURN_IF_ERROR(current_editor_set_->music_editor_.Load());
|
||||||
RETURN_IF_ERROR(current_editor_set_->palette_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();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1715,6 +1725,11 @@ void EditorManager::DrawLayoutPresets() {
|
|||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::Text("%s Custom Presets", ICON_MD_BOOKMARK);
|
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_) {
|
for (const auto& preset : workspace_presets_) {
|
||||||
if (ImGui::Button(absl::StrFormat("%s %s", ICON_MD_BOOKMARK, preset.c_str()).c_str(), ImVec2(-1, 0))) {
|
if (ImGui::Button(absl::StrFormat("%s %s", ICON_MD_BOOKMARK, preset.c_str()).c_str(), ImVec2(-1, 0))) {
|
||||||
LoadWorkspacePreset(preset);
|
LoadWorkspacePreset(preset);
|
||||||
|
|||||||
@@ -402,24 +402,22 @@ void DrawMenu(Menu& menu) {
|
|||||||
if (!each_item.subitems.empty()) {
|
if (!each_item.subitems.empty()) {
|
||||||
if (ImGui::BeginMenu(each_item.name.c_str())) {
|
if (ImGui::BeginMenu(each_item.name.c_str())) {
|
||||||
for (const auto& each_subitem : each_item.subitems) {
|
for (const auto& each_subitem : each_item.subitems) {
|
||||||
if (ImGui::MenuItem(each_subitem.name.c_str(),
|
if (each_subitem.name == kSeparator) {
|
||||||
|
ImGui::Separator();
|
||||||
|
} else if (ImGui::MenuItem(each_subitem.name.c_str(),
|
||||||
each_subitem.shortcut.c_str())) {
|
each_subitem.shortcut.c_str())) {
|
||||||
if (each_subitem.callback) each_subitem.callback();
|
if (each_subitem.callback) each_subitem.callback();
|
||||||
} else if (each_subitem.name == kSeparator) {
|
|
||||||
ImGui::Separator();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
} else if (each_item.name == kSeparator) {
|
|
||||||
ImGui::Separator();
|
|
||||||
} else {
|
} 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.shortcut.c_str(),
|
||||||
each_item.enabled_condition())) {
|
each_item.enabled_condition())) {
|
||||||
if (each_item.callback) each_item.callback();
|
if (each_item.callback) each_item.callback();
|
||||||
} else if (each_item.name == kSeparator) {
|
|
||||||
ImGui::Separator();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -469,9 +467,9 @@ bool InputHexByteCustom(const char* label, uint8_t* data, float input_width) {
|
|||||||
snprintf(buf, sizeof(buf), "%02X", *data);
|
snprintf(buf, sizeof(buf), "%02X", *data);
|
||||||
|
|
||||||
ImGui::SetNextItemWidth(input_width);
|
ImGui::SetNextItemWidth(input_width);
|
||||||
bool changed = ImGui::InputText(label, buf, sizeof(buf),
|
bool changed = ImGui::InputText(
|
||||||
ImGuiInputTextFlags_CharsHexadecimal |
|
label, buf, sizeof(buf),
|
||||||
ImGuiInputTextFlags_AutoSelectAll);
|
ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_AutoSelectAll);
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
unsigned int temp;
|
unsigned int temp;
|
||||||
@@ -492,9 +490,9 @@ bool InputHexWordCustom(const char* label, uint16_t* data, float input_width) {
|
|||||||
snprintf(buf, sizeof(buf), "%04X", *data);
|
snprintf(buf, sizeof(buf), "%04X", *data);
|
||||||
|
|
||||||
ImGui::SetNextItemWidth(input_width);
|
ImGui::SetNextItemWidth(input_width);
|
||||||
bool changed = ImGui::InputText(label, buf, sizeof(buf),
|
bool changed = ImGui::InputText(
|
||||||
ImGuiInputTextFlags_CharsHexadecimal |
|
label, buf, sizeof(buf),
|
||||||
ImGuiInputTextFlags_AutoSelectAll);
|
ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_AutoSelectAll);
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
unsigned int temp;
|
unsigned int temp;
|
||||||
|
|||||||
Reference in New Issue
Block a user