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 "absl/strings/str_format.h"
9#include "imgui/imgui.h"
10#include "imgui/imgui_internal.h"
11#include "util/log.h"
12
13namespace yaze {
14namespace editor {
15
24
25// ==========================================================================
26// Layout Offset Calculations
27// ==========================================================================
28
30 // Global UI toggle override
32 return 0.0f;
33 }
34
35 // Check startup surface state - Activity Bar hidden on cold start
37 return 0.0f;
38 }
39
40 // Check Activity Bar visibility
42 return 0.0f;
43 }
44
45 // Base width = Activity Bar
46 float width = PanelManager::GetSidebarWidth(); // 48px
47
48 // Add Side Panel width if expanded
51 }
52
53 return width;
54}
55
59
63
64// ==========================================================================
65// Layout Operations
66// ==========================================================================
67
69 if (!layout_manager_) {
70 return;
71 }
72
75
76 // Force immediate rebuild for active context
77 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
78 if (imgui_ctx && imgui_ctx->WithinFrameScope) {
79 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
80
81 // Determine which layout to rebuild based on emulator visibility
84 LOG_INFO("LayoutCoordinator", "Emulator layout reset complete");
85 }
86 // Note: Current editor check would need to be passed in or stored
87 } else {
88 // Not in frame scope - rebuild will happen on next tick via RequestRebuild()
89 LOG_INFO("LayoutCoordinator", "Layout reset queued for next frame");
90 }
91}
92
93void LayoutCoordinator::ApplyLayoutPreset(const std::string& preset_name,
94 size_t session_id) {
95 if (!panel_manager_) {
96 return;
97 }
98
99 PanelLayoutPreset preset;
100
101 // Get the preset by name
102 if (preset_name == "Minimal") {
104 } else if (preset_name == "Developer") {
106 } else if (preset_name == "Designer") {
108 } else if (preset_name == "Modder") {
110 } else if (preset_name == "Overworld Expert") {
112 } else if (preset_name == "Dungeon Expert") {
114 } else if (preset_name == "Testing") {
116 } else if (preset_name == "Audio") {
118 } else {
119 LOG_WARN("LayoutCoordinator", "Unknown layout preset: %s",
120 preset_name.c_str());
121 if (toast_manager_) {
122 toast_manager_->Show(absl::StrFormat("Unknown preset: %s", preset_name),
124 }
125 return;
126 }
127
128 // Hide all panels first
130
131 // Show only the panels defined in the preset
132 for (const auto& panel_id : preset.default_visible_panels) {
133 panel_manager_->ShowPanel(session_id, panel_id);
134 }
135
136 // Request a dock rebuild so the preset positions are applied
137 if (layout_manager_) {
139 }
140
141 LOG_INFO("LayoutCoordinator", "Applied layout preset: %s",
142 preset_name.c_str());
143 if (toast_manager_) {
144 toast_manager_->Show(absl::StrFormat("Layout: %s", preset_name),
146 }
147}
148
150 size_t session_id) {
151 if (!panel_manager_) {
152 if (toast_manager_) {
153 toast_manager_->Show("No active editor to reset", ToastType::kWarning);
154 }
155 return;
156 }
157
158 // Get the default preset for the current editor
159 auto preset = LayoutPresets::GetDefaultPreset(editor_type);
160
161 // Reset panels to defaults
162 panel_manager_->ResetToDefaults(session_id, editor_type);
163
164 // Rebuild dock layout for this editor on next frame
165 if (layout_manager_) {
168 }
169
170 LOG_INFO("LayoutCoordinator", "Reset editor layout to defaults for type %d",
171 static_cast<int>(editor_type));
172 if (toast_manager_) {
173 toast_manager_->Show("Layout reset to defaults", ToastType::kSuccess);
174 }
175}
176
177// ==========================================================================
178// Layout Rebuild Handling
179// ==========================================================================
180
182 bool is_emulator_visible) {
184 return;
185 }
186
187 // Only rebuild if we're in a valid ImGui frame with dockspace
188 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
189 if (!imgui_ctx || !imgui_ctx->WithinFrameScope) {
190 return;
191 }
192
193 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
194
195 // Determine which editor layout to rebuild
196 EditorType rebuild_type = EditorType::kUnknown;
197 if (is_emulator_visible) {
198 rebuild_type = EditorType::kEmulator;
199 } else if (current_editor_type != EditorType::kUnknown) {
200 rebuild_type = current_editor_type;
201 }
202
203 // Execute rebuild if we have a valid editor type
204 if (rebuild_type != EditorType::kUnknown) {
205 layout_manager_->RebuildLayout(rebuild_type, dockspace_id);
206 LOG_INFO("LayoutCoordinator", "Layout rebuilt for editor type %d",
207 static_cast<int>(rebuild_type));
208 }
209
211}
212
214 if (!layout_manager_) {
215 return;
216 }
217
219 return;
220 }
221
222 // Defer layout initialization to ensure we are in the correct scope
223 QueueDeferredAction([this, type]() {
225 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
226 layout_manager_->InitializeEditorLayout(type, dockspace_id);
227 }
228 });
229}
230
231void LayoutCoordinator::QueueDeferredAction(std::function<void()> action) {
232 deferred_actions_.push_back(std::move(action));
233}
234
236 if (deferred_actions_.empty()) {
237 return;
238 }
239
240 std::vector<std::function<void()>> actions_to_execute;
241 actions_to_execute.swap(deferred_actions_);
242
243 for (auto& action : actions_to_execute) {
244 action();
245 }
246}
247
248} // namespace editor
249} // 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.
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 GetDungeonExpertPreset()
Get the "dungeon expert" workspace preset.
static PanelLayoutPreset GetTestingPreset()
Get the "testing" workspace preset (QA focused)
static PanelLayoutPreset GetDesignerPreset()
Get the "designer" workspace preset (visual-focused)
static PanelLayoutPreset GetAudioPreset()
Get the "audio" workspace preset (music focused)
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 GetOverworldExpertPreset()
Get the "overworld expert" workspace preset.
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)
static constexpr float GetSidePanelWidth()
float GetPanelWidth() const
Get the width of the panel when expanded.
float GetHeight() const
Get the height of the status bar.
Definition status_bar.h:152
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f)
#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