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 = WorkspaceWindowManager::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 += window_manager_->GetActiveSidePanelWidth(viewport_width);
59 }
60
61 return width;
62}
63
67
72
73// ==========================================================================
74// Layout Operations
75// ==========================================================================
76
78 if (!layout_manager_) {
79 return;
80 }
81
82 if (ImGui::GetCurrentContext()) {
83 static const char kEmptyIni[] = "\n";
84 ImGui::LoadIniSettingsFromMemory(kEmptyIni, sizeof(kEmptyIni) - 1);
85 }
86
87 if (auto ini_path = util::PlatformPaths::GetImGuiIniPath(); ini_path.ok()) {
88 std::error_code ec;
89 std::filesystem::remove(*ini_path, ec);
90 if (ec) {
91 LOG_WARN("LayoutCoordinator", "Failed to remove ImGui ini: %s",
92 ec.message().c_str());
93 }
94 }
95
98
99 // Force immediate rebuild for active context
100 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
101 if (imgui_ctx && imgui_ctx->WithinFrameScope) {
102 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
103
104 // Determine which layout to rebuild based on emulator visibility
107 LOG_INFO("LayoutCoordinator", "Emulator layout reset complete");
108 }
109 // Note: Current editor check would need to be passed in or stored
110 } else {
111 // Not in frame scope - rebuild will happen on next tick via RequestRebuild()
112 LOG_INFO("LayoutCoordinator", "Layout reset queued for next frame");
113 }
114}
115
116void LayoutCoordinator::ApplyLayoutPreset(const std::string& preset_name,
117 size_t session_id) {
118 if (!window_manager_) {
119 return;
120 }
121
122 PanelLayoutPreset preset;
123
124 // Get the preset by name
125 if (preset_name == "Minimal") {
127 } else if (preset_name == "Developer") {
129 } else if (preset_name == "Designer") {
131 } else if (preset_name == "Modder") {
133 } else if (preset_name == "Overworld Expert") {
135 } else if (preset_name == "Dungeon Expert") {
137 } else if (preset_name == "Testing") {
139 } else if (preset_name == "Audio") {
141 } else {
142 LOG_WARN("LayoutCoordinator", "Unknown layout preset: %s",
143 preset_name.c_str());
144 if (toast_manager_) {
145 toast_manager_->Show(absl::StrFormat("Unknown preset: %s", preset_name),
147 }
148 return;
149 }
150
151 // Hide all panels first
153
154 // Show only the panels defined in the preset
155 for (const auto& panel_id : preset.default_visible_panels) {
156 window_manager_->OpenWindow(session_id, panel_id);
157 }
158
159 // Request a dock rebuild so the preset positions are applied
160 if (layout_manager_) {
162 }
163
164 LOG_INFO("LayoutCoordinator", "Applied layout preset: %s",
165 preset_name.c_str());
166 if (toast_manager_) {
167 toast_manager_->Show(absl::StrFormat("Layout: %s", preset_name),
169 }
170}
171
173 size_t session_id) {
174 if (!window_manager_) {
175 if (toast_manager_) {
176 toast_manager_->Show("No active editor to reset", ToastType::kWarning);
177 }
178 return;
179 }
180
181 // Get the default preset for the current editor
182 auto preset = LayoutPresets::GetDefaultPreset(editor_type);
183
184 // Reset panels to defaults
185 window_manager_->ResetToDefaults(session_id, editor_type);
186
187 // Rebuild dock layout for this editor on next frame
188 if (layout_manager_) {
191 }
192
193 LOG_INFO("LayoutCoordinator", "Reset editor layout to defaults for type %d",
194 static_cast<int>(editor_type));
195 if (toast_manager_) {
196 toast_manager_->Show("Layout reset to defaults", ToastType::kSuccess);
197 }
198}
199
200// ==========================================================================
201// Layout Rebuild Handling
202// ==========================================================================
203
205 bool is_emulator_visible) {
207 return;
208 }
209
210 // Only rebuild if we're in a valid ImGui frame with dockspace
211 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
212 if (!imgui_ctx || !imgui_ctx->WithinFrameScope) {
213 return;
214 }
215
216 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
217
218 // Determine which editor layout to rebuild
219 EditorType rebuild_type = EditorType::kUnknown;
220 if (is_emulator_visible) {
221 rebuild_type = EditorType::kEmulator;
222 } else if (current_editor_type != EditorType::kUnknown) {
223 rebuild_type = current_editor_type;
224 }
225
226 // Execute rebuild if we have a valid editor type
227 if (rebuild_type != EditorType::kUnknown) {
228 layout_manager_->RebuildLayout(rebuild_type, dockspace_id);
229 LOG_INFO("LayoutCoordinator", "Layout rebuilt for editor type %d",
230 static_cast<int>(rebuild_type));
231 }
232
234}
235
237 if (!layout_manager_) {
238 return;
239 }
240
242 return;
243 }
244
245 // Defer layout initialization to ensure we are in the correct scope
246 QueueDeferredAction([this, type]() {
248 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
249 layout_manager_->InitializeEditorLayout(type, dockspace_id);
250 }
251 });
252}
253
254void LayoutCoordinator::QueueDeferredAction(std::function<void()> action) {
255 deferred_actions_.push_back(std::move(action));
256 pending_deferred_actions_.fetch_add(1, std::memory_order_relaxed);
257}
258
260 if (deferred_actions_.empty()) {
261 return;
262 }
263
264 std::vector<std::function<void()>> actions_to_execute;
265 actions_to_execute.swap(deferred_actions_);
266 const int processed_count = static_cast<int>(actions_to_execute.size());
267
268 for (auto& action : actions_to_execute) {
269 action();
270 }
271
272 if (processed_count > 0) {
273 const int remaining = pending_deferred_actions_.fetch_sub(
274 processed_count, std::memory_order_relaxed) -
275 processed_count;
276 if (remaining < 0) {
277 pending_deferred_actions_.store(0, std::memory_order_relaxed);
278 }
279 }
280}
281
282} // namespace editor
283} // 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.
RightDrawerManager * right_drawer_manager_
WorkspaceWindowManager * window_manager_
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 drawers.
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)
float GetDrawerWidth() const
Get the width of the drawer when expanded.
bool IsEnabled() const
Definition status_bar.h:69
float GetHeight() const
Get the height of the status bar.
Definition status_bar.cc:81
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f)
float GetActiveSidePanelWidth(float viewport_width) const
bool OpenWindow(size_t session_id, const std::string &base_window_id)
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