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
50 float viewport_width = 0.0f;
51 if (ImGui::GetCurrentContext()) {
52 const ImGuiViewport* viewport = ImGui::GetMainViewport();
53 viewport_width = viewport ? viewport->WorkSize.x : 0.0f;
54 }
55 width += PanelManager::GetSidePanelWidthForViewport(viewport_width);
56 }
57
58 return width;
59}
60
64
68
69// ==========================================================================
70// Layout Operations
71// ==========================================================================
72
74 if (!layout_manager_) {
75 return;
76 }
77
80
81 // Force immediate rebuild for active context
82 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
83 if (imgui_ctx && imgui_ctx->WithinFrameScope) {
84 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
85
86 // Determine which layout to rebuild based on emulator visibility
89 LOG_INFO("LayoutCoordinator", "Emulator layout reset complete");
90 }
91 // Note: Current editor check would need to be passed in or stored
92 } else {
93 // Not in frame scope - rebuild will happen on next tick via RequestRebuild()
94 LOG_INFO("LayoutCoordinator", "Layout reset queued for next frame");
95 }
96}
97
98void LayoutCoordinator::ApplyLayoutPreset(const std::string& preset_name,
99 size_t session_id) {
100 if (!panel_manager_) {
101 return;
102 }
103
104 PanelLayoutPreset preset;
105
106 // Get the preset by name
107 if (preset_name == "Minimal") {
109 } else if (preset_name == "Developer") {
111 } else if (preset_name == "Designer") {
113 } else if (preset_name == "Modder") {
115 } else if (preset_name == "Overworld Expert") {
117 } else if (preset_name == "Dungeon Expert") {
119 } else if (preset_name == "Testing") {
121 } else if (preset_name == "Audio") {
123 } else {
124 LOG_WARN("LayoutCoordinator", "Unknown layout preset: %s",
125 preset_name.c_str());
126 if (toast_manager_) {
127 toast_manager_->Show(absl::StrFormat("Unknown preset: %s", preset_name),
129 }
130 return;
131 }
132
133 // Hide all panels first
135
136 // Show only the panels defined in the preset
137 for (const auto& panel_id : preset.default_visible_panels) {
138 panel_manager_->ShowPanel(session_id, panel_id);
139 }
140
141 // Request a dock rebuild so the preset positions are applied
142 if (layout_manager_) {
144 }
145
146 LOG_INFO("LayoutCoordinator", "Applied layout preset: %s",
147 preset_name.c_str());
148 if (toast_manager_) {
149 toast_manager_->Show(absl::StrFormat("Layout: %s", preset_name),
151 }
152}
153
155 size_t session_id) {
156 if (!panel_manager_) {
157 if (toast_manager_) {
158 toast_manager_->Show("No active editor to reset", ToastType::kWarning);
159 }
160 return;
161 }
162
163 // Get the default preset for the current editor
164 auto preset = LayoutPresets::GetDefaultPreset(editor_type);
165
166 // Reset panels to defaults
167 panel_manager_->ResetToDefaults(session_id, editor_type);
168
169 // Rebuild dock layout for this editor on next frame
170 if (layout_manager_) {
173 }
174
175 LOG_INFO("LayoutCoordinator", "Reset editor layout to defaults for type %d",
176 static_cast<int>(editor_type));
177 if (toast_manager_) {
178 toast_manager_->Show("Layout reset to defaults", ToastType::kSuccess);
179 }
180}
181
182// ==========================================================================
183// Layout Rebuild Handling
184// ==========================================================================
185
187 bool is_emulator_visible) {
189 return;
190 }
191
192 // Only rebuild if we're in a valid ImGui frame with dockspace
193 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
194 if (!imgui_ctx || !imgui_ctx->WithinFrameScope) {
195 return;
196 }
197
198 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
199
200 // Determine which editor layout to rebuild
201 EditorType rebuild_type = EditorType::kUnknown;
202 if (is_emulator_visible) {
203 rebuild_type = EditorType::kEmulator;
204 } else if (current_editor_type != EditorType::kUnknown) {
205 rebuild_type = current_editor_type;
206 }
207
208 // Execute rebuild if we have a valid editor type
209 if (rebuild_type != EditorType::kUnknown) {
210 layout_manager_->RebuildLayout(rebuild_type, dockspace_id);
211 LOG_INFO("LayoutCoordinator", "Layout rebuilt for editor type %d",
212 static_cast<int>(rebuild_type));
213 }
214
216}
217
219 if (!layout_manager_) {
220 return;
221 }
222
224 return;
225 }
226
227 // Defer layout initialization to ensure we are in the correct scope
228 QueueDeferredAction([this, type]() {
230 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
231 layout_manager_->InitializeEditorLayout(type, dockspace_id);
232 }
233 });
234}
235
236void LayoutCoordinator::QueueDeferredAction(std::function<void()> action) {
237 deferred_actions_.push_back(std::move(action));
238}
239
241 if (deferred_actions_.empty()) {
242 return;
243 }
244
245 std::vector<std::function<void()>> actions_to_execute;
246 actions_to_execute.swap(deferred_actions_);
247
248 for (auto& action : actions_to_execute) {
249 action();
250 }
251}
252
253} // namespace editor
254} // 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)
static float GetSidePanelWidthForViewport(float viewport_width)
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 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