yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
layout_coordinator.cc
Go to the documentation of this file.
2
3#include <filesystem>
4
5#include "absl/strings/str_format.h"
11#include "imgui/imgui.h"
12#include "imgui/imgui_internal.h"
13#include "util/log.h"
14#include "util/platform_paths.h"
15
16namespace yaze {
17namespace editor {
18
27
28// ==========================================================================
29// Layout Offset Calculations
30// ==========================================================================
31
33 // Global UI toggle override
35 return 0.0f;
36 }
37
38 // Check startup surface state - Activity Bar hidden on cold start
40 return 0.0f;
41 }
42
43 // Check Activity Bar visibility
45 return 0.0f;
46 }
47
48 // Base width = Activity Bar
49 float width = PanelManager::GetSidebarWidth(); // 48px
50
51 // Add Side Panel width if expanded
53 float viewport_width = 0.0f;
54 if (ImGui::GetCurrentContext()) {
55 const ImGuiViewport* viewport = ImGui::GetMainViewport();
56 viewport_width = viewport ? viewport->WorkSize.x : 0.0f;
57 }
58 width += panel_manager_->GetActiveSidePanelWidth(viewport_width);
59 }
60
61 return width;
62}
63
67
71
72// ==========================================================================
73// Layout Operations
74// ==========================================================================
75
77 if (!layout_manager_) {
78 return;
79 }
80
81 if (ImGui::GetCurrentContext()) {
82 static const char kEmptyIni[] = "\n";
83 ImGui::LoadIniSettingsFromMemory(kEmptyIni, sizeof(kEmptyIni) - 1);
84 }
85
86 if (auto ini_path = util::PlatformPaths::GetImGuiIniPath(); ini_path.ok()) {
87 std::error_code ec;
88 std::filesystem::remove(*ini_path, ec);
89 if (ec) {
90 LOG_WARN("LayoutCoordinator", "Failed to remove ImGui ini: %s",
91 ec.message().c_str());
92 }
93 }
94
97
98 // Force immediate rebuild for active context
99 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
100 if (imgui_ctx && imgui_ctx->WithinFrameScope) {
101 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
102
103 // Determine which layout to rebuild based on emulator visibility
106 LOG_INFO("LayoutCoordinator", "Emulator layout reset complete");
107 }
108 // Note: Current editor check would need to be passed in or stored
109 } else {
110 // Not in frame scope - rebuild will happen on next tick via RequestRebuild()
111 LOG_INFO("LayoutCoordinator", "Layout reset queued for next frame");
112 }
113}
114
115void LayoutCoordinator::ApplyLayoutPreset(const std::string& preset_name,
116 size_t session_id) {
117 if (!panel_manager_) {
118 return;
119 }
120
121 PanelLayoutPreset preset;
122
123 // Get the preset by name
124 if (preset_name == "Minimal") {
126 } else if (preset_name == "Developer") {
128 } else if (preset_name == "Designer") {
130 } else if (preset_name == "Modder") {
132 } else if (preset_name == "Overworld Expert") {
134 } else if (preset_name == "Dungeon Expert") {
136 } else if (preset_name == "Testing") {
138 } else if (preset_name == "Audio") {
140 } else {
141 LOG_WARN("LayoutCoordinator", "Unknown layout preset: %s",
142 preset_name.c_str());
143 if (toast_manager_) {
144 toast_manager_->Show(absl::StrFormat("Unknown preset: %s", preset_name),
146 }
147 return;
148 }
149
150 // Hide all panels first
152
153 // Show only the panels defined in the preset
154 for (const auto& panel_id : preset.default_visible_panels) {
155 panel_manager_->ShowPanel(session_id, panel_id);
156 }
157
158 // Request a dock rebuild so the preset positions are applied
159 if (layout_manager_) {
161 }
162
163 LOG_INFO("LayoutCoordinator", "Applied layout preset: %s",
164 preset_name.c_str());
165 if (toast_manager_) {
166 toast_manager_->Show(absl::StrFormat("Layout: %s", preset_name),
168 }
169}
170
172 size_t session_id) {
173 if (!panel_manager_) {
174 if (toast_manager_) {
175 toast_manager_->Show("No active editor to reset", ToastType::kWarning);
176 }
177 return;
178 }
179
180 // Get the default preset for the current editor
181 auto preset = LayoutPresets::GetDefaultPreset(editor_type);
182
183 // Reset panels to defaults
184 panel_manager_->ResetToDefaults(session_id, editor_type);
185
186 // Rebuild dock layout for this editor on next frame
187 if (layout_manager_) {
190 }
191
192 LOG_INFO("LayoutCoordinator", "Reset editor layout to defaults for type %d",
193 static_cast<int>(editor_type));
194 if (toast_manager_) {
195 toast_manager_->Show("Layout reset to defaults", ToastType::kSuccess);
196 }
197}
198
199// ==========================================================================
200// Layout Rebuild Handling
201// ==========================================================================
202
204 bool is_emulator_visible) {
206 return;
207 }
208
209 // Only rebuild if we're in a valid ImGui frame with dockspace
210 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
211 if (!imgui_ctx || !imgui_ctx->WithinFrameScope) {
212 return;
213 }
214
215 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
216
217 // Determine which editor layout to rebuild
218 EditorType rebuild_type = EditorType::kUnknown;
219 if (is_emulator_visible) {
220 rebuild_type = EditorType::kEmulator;
221 } else if (current_editor_type != EditorType::kUnknown) {
222 rebuild_type = current_editor_type;
223 }
224
225 // Execute rebuild if we have a valid editor type
226 if (rebuild_type != EditorType::kUnknown) {
227 layout_manager_->RebuildLayout(rebuild_type, dockspace_id);
228 LOG_INFO("LayoutCoordinator", "Layout rebuilt for editor type %d",
229 static_cast<int>(rebuild_type));
230 }
231
233}
234
236 if (!layout_manager_) {
237 return;
238 }
239
241 return;
242 }
243
244 // Defer layout initialization to ensure we are in the correct scope
245 QueueDeferredAction([this, type]() {
247 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
248 layout_manager_->InitializeEditorLayout(type, dockspace_id);
249 }
250 });
251}
252
253void LayoutCoordinator::QueueDeferredAction(std::function<void()> action) {
254 deferred_actions_.push_back(std::move(action));
255 pending_deferred_actions_.fetch_add(1, std::memory_order_relaxed);
256}
257
259 if (deferred_actions_.empty()) {
260 return;
261 }
262
263 std::vector<std::function<void()>> actions_to_execute;
264 actions_to_execute.swap(deferred_actions_);
265 const int processed_count = static_cast<int>(actions_to_execute.size());
266
267 for (auto& action : actions_to_execute) {
268 action();
269 }
270
271 if (processed_count > 0) {
272 const int remaining = pending_deferred_actions_.fetch_sub(
273 processed_count, std::memory_order_relaxed) -
274 processed_count;
275 if (remaining < 0) {
276 pending_deferred_actions_.store(0, std::memory_order_relaxed);
277 }
278 }
279}
280
281} // namespace editor
282} // namespace yaze
std::vector< std::function< void()> > deferred_actions_
void QueueDeferredAction(std::function< void()> action)
Queue an action to be executed on the next frame.
void ProcessDeferredActions()
Process all queued deferred actions.
float GetBottomLayoutOffset() const
Get the bottom margin needed for status bar.
void ResetWorkspaceLayout()
Reset the workspace layout to defaults.
void ProcessLayoutRebuild(EditorType current_editor_type, bool is_emulator_visible)
Process pending layout rebuild requests.
std::atomic< int > pending_deferred_actions_
void InitializeEditorLayout(EditorType type)
Initialize layout for an editor type on first activation.
float GetRightLayoutOffset() const
Get the right margin needed for panels.
void ResetCurrentEditorLayout(EditorType editor_type, size_t session_id)
Reset current editor layout to its default configuration.
void ApplyLayoutPreset(const std::string &preset_name, size_t session_id)
Apply a named layout preset.
void Initialize(const Dependencies &deps)
Initialize with all dependencies.
float GetLeftLayoutOffset() const
Get the left margin needed for sidebar (Activity Bar + Side Panel)
void RebuildLayout(EditorType type, ImGuiID dockspace_id)
Force rebuild of layout for a specific editor type.
void ClearInitializationFlags()
Clear all initialization flags (for testing)
bool IsLayoutInitialized(EditorType type) const
Check if a layout has been initialized for an editor.
void ResetToDefaultLayout(EditorType type)
Reset the layout for an editor to its default.
void ClearRebuildRequest()
Clear rebuild request flag.
void RequestRebuild()
Request a layout rebuild on next frame.
bool IsRebuildRequested() const
Check if rebuild was requested.
static PanelLayoutPreset GetLogicDebuggerPreset()
Get the "logic debugger" workspace preset (QA and debug focused)
static PanelLayoutPreset GetDungeonMasterPreset()
Get the "dungeon master" workspace preset.
static PanelLayoutPreset GetAudioEngineerPreset()
Get the "audio engineer" workspace preset (music focused)
static PanelLayoutPreset GetDesignerPreset()
Get the "designer" workspace preset (visual-focused)
static PanelLayoutPreset GetOverworldArtistPreset()
Get the "overworld artist" workspace preset.
static PanelLayoutPreset GetDefaultPreset(EditorType type)
Get the default layout preset for an editor type.
static PanelLayoutPreset GetModderPreset()
Get the "modder" workspace preset (full-featured)
static PanelLayoutPreset GetMinimalPreset()
Get the "minimal" workspace preset (minimal cards)
static PanelLayoutPreset GetDeveloperPreset()
Get the "developer" workspace preset (debug-focused)
bool ShowPanel(size_t session_id, const std::string &base_card_id)
void HideAll(size_t session_id)
static constexpr float GetSidebarWidth()
void ResetToDefaults(size_t session_id)
float GetActiveSidePanelWidth(float viewport_width) const
float GetPanelWidth() const
Get the width of the panel when expanded.
float GetHeight() const
Get the height of the status bar.
Definition status_bar.cc:20
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f)
static absl::StatusOr< std::filesystem::path > GetImGuiIniPath()
Get the ImGui ini path for YAZE.
#define LOG_WARN(category, format,...)
Definition log.h:107
#define LOG_INFO(category, format,...)
Definition log.h:105
All dependencies required by LayoutCoordinator.
Defines default panel visibility for an editor type.
std::vector< std::string > default_visible_panels