feat: Refactor editor structure and enhance multi-session support

- Moved `menu_builder.cc` to a new `ui` directory for better organization.
- Updated `EditorManager` to generate unique ImGui IDs for multi-session support, ensuring separate window handling.
- Added session ID management in `EditorContext` for improved child panel identification.
- Introduced a new `MenuBuilder` class for streamlined ImGui menu creation, enhancing UI maintainability.
This commit is contained in:
scawful
2025-10-05 02:09:50 -04:00
parent 46b5f1f288
commit 20b8251724
6 changed files with 28 additions and 7 deletions

View File

@@ -28,6 +28,11 @@ struct EditorContext {
HistoryManager history_manager;
PopupManager* popup_manager = nullptr;
ShortcutManager shortcut_manager;
// Session identification for multi-session support
// Used by child panels to create unique ImGui IDs
size_t session_id = 0;
// Cross-session shared clipboard for editor data transfers
struct SharedClipboard {
// Overworld tile16 selection payload

View File

@@ -1,7 +1,7 @@
set(
YAZE_APP_EDITOR_SRC
app/editor/editor_manager.cc
app/editor/menu_builder.cc
app/editor/ui/menu_builder.cc
app/editor/ui/editor_selection_dialog.cc
app/editor/ui/welcome_screen.cc
app/editor/ui/background_renderer.cc

View File

@@ -992,18 +992,31 @@ absl::Status EditorManager::Update() {
}
}
// Generate unique window titles for multi-session support
// Generate unique window titles and IDs for multi-session support
std::string window_title =
GenerateUniqueEditorTitle(editor->type(), session_idx);
// Create truly unique ImGui ID combining session index and editor type
// This ensures ImGui treats them as completely separate windows
ImGui::PushID(static_cast<int>(session_idx * 100 + static_cast<int>(editor->type())));
if (ImGui::Begin(window_title.c_str(), editor->active())) {
// Set window to maximize on first open
if (ImGui::IsWindowAppearing()) {
ImGui::SetNextWindowSize(ImGui::GetMainViewport()->WorkSize, ImGuiCond_Appearing);
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->WorkPos, ImGuiCond_Appearing);
}
if (ImGui::Begin(window_title.c_str(), editor->active(),
ImGuiWindowFlags_None)) { // Allow full docking
// Temporarily switch context for this editor's update
Rom* prev_rom = current_rom_;
EditorSet* prev_editor_set = current_editor_set_;
size_t prev_session_id = context_.session_id;
current_rom_ = &session.rom;
current_editor_set_ = &session.editors;
current_editor_ = editor;
context_.session_id = session_idx; // Set session ID for child panels
status_ = editor->Update();
@@ -1034,8 +1047,10 @@ absl::Status EditorManager::Update() {
// Restore context
current_rom_ = prev_rom;
current_editor_set_ = prev_editor_set;
context_.session_id = prev_session_id; // Restore previous session ID
}
ImGui::End();
ImGui::PopID(); // Pop the unique ID for this session+editor combination
}
}
}

View File

@@ -13,6 +13,7 @@
#include "app/core/project.h"
#include "app/editor/code/assembly_editor.h"
#include "app/editor/code/memory_editor.h"
#include "app/editor/code/memory_editor_enhanced.h"
#include "app/editor/code/project_file_editor.h"
#include "app/editor/dungeon/dungeon_editor_v2.h"
#include "app/editor/graphics/graphics_editor.h"

View File

@@ -1,4 +1,4 @@
#include "app/editor/menu_builder.h"
#include "app/editor/ui/menu_builder.h"
#include "absl/strings/str_cat.h"

View File

@@ -1,5 +1,5 @@
#ifndef YAZE_APP_EDITOR_MENU_BUILDER_H_
#define YAZE_APP_EDITOR_MENU_BUILDER_H_
#ifndef YAZE_APP_EDITOR_UI_MENU_BUILDER_H_
#define YAZE_APP_EDITOR_UI_MENU_BUILDER_H_
#include <functional>
#include <string>
@@ -116,4 +116,4 @@ class MenuBuilder {
} // namespace editor
} // namespace yaze
#endif // YAZE_APP_EDITOR_MENU_BUILDER_H_
#endif // YAZE_APP_EDITOR_UI_MENU_BUILDER_H_