6#include "absl/strings/str_format.h"
13#include "imgui/imgui.h"
14#include "imgui/imgui_internal.h"
36 float viewport_width,
float activity_bar_width,
float left_side_panel_width,
37 float right_sidebar_width,
float right_sidebar_budget_width,
38 float min_canvas_width) {
39 const float activity = std::max(0.0f, activity_bar_width);
40 const float left_panel = std::max(0.0f, left_side_panel_width);
41 const float right_panel = std::max(0.0f, right_sidebar_width);
42 const float right_budget = right_sidebar_budget_width >= 0.0f
43 ? right_sidebar_budget_width
45 const float desired_left = activity + left_panel;
47 if (viewport_width > 0.0f && viewport_width - desired_left - right_budget <
48 std::max(0.0f, min_canvas_width)) {
50 .left_offset = activity,
52 .side_panels_overlay = left_panel > 0.0f || right_panel > 0.0f,
57 .left_offset = desired_left,
58 .right_offset = right_panel,
59 .side_panels_overlay =
false,
65 float viewport_width = 0.0f;
66 if (ImGui::GetCurrentContext()) {
67 const ImGuiViewport* viewport = ImGui::GetMainViewport();
68 viewport_width = viewport ? viewport->WorkSize.x : 0.0f;
71 float activity_width = 0.0f;
72 float left_panel_width = 0.0f;
73 const bool show_left_chrome =
77 if (show_left_chrome) {
85 const float right_sidebar_width =
87 const float right_sidebar_budget_width =
91 left_panel_width, right_sidebar_width,
92 right_sidebar_budget_width);
117 if (ImGui::GetCurrentContext()) {
118 static const char kEmptyIni[] =
"\n";
119 ImGui::LoadIniSettingsFromMemory(kEmptyIni,
sizeof(kEmptyIni) - 1);
124 std::filesystem::remove(*ini_path, ec);
126 LOG_WARN(
"LayoutCoordinator",
"Failed to remove ImGui ini: %s",
127 ec.message().c_str());
135 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
136 if (imgui_ctx && imgui_ctx->WithinFrameScope) {
137 ImGuiID dockspace_id = ImGui::GetID(
"MainDockSpace");
142 LOG_INFO(
"LayoutCoordinator",
"Emulator layout reset complete");
147 LOG_INFO(
"LayoutCoordinator",
"Layout reset queued for next frame");
160 if (preset_name ==
"Minimal") {
162 }
else if (preset_name ==
"Developer") {
164 }
else if (preset_name ==
"Designer") {
166 }
else if (preset_name ==
"Modder") {
168 }
else if (preset_name ==
"Overworld Expert") {
170 }
else if (preset_name ==
"Dungeon Expert") {
172 }
else if (preset_name ==
"Testing") {
174 }
else if (preset_name ==
"Audio") {
177 LOG_WARN(
"LayoutCoordinator",
"Unknown layout preset: %s",
178 preset_name.c_str());
199 LOG_INFO(
"LayoutCoordinator",
"Applied layout preset: %s",
200 preset_name.c_str());
256 LOG_INFO(
"LayoutCoordinator",
"Reset editor layout to defaults for type %d",
257 static_cast<int>(editor_type));
269 bool is_emulator_visible) {
275 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
276 if (!imgui_ctx || !imgui_ctx->WithinFrameScope) {
280 ImGuiID dockspace_id = ImGui::GetID(
"MainDockSpace");
284 if (is_emulator_visible) {
287 rebuild_type = current_editor_type;
293 LOG_INFO(
"LayoutCoordinator",
"Layout rebuilt for editor type %d",
294 static_cast<int>(rebuild_type));
312 ImGuiID dockspace_id = ImGui::GetID(
"MainDockSpace");
313 layout_manager_->InitializeEditorLayout(type, dockspace_id);
328 std::vector<std::function<void()>> actions_to_execute;
330 const int processed_count =
static_cast<int>(actions_to_execute.size());
332 for (
auto& action : actions_to_execute) {
336 if (processed_count > 0) {
338 processed_count, std::memory_order_relaxed) -
static std::string GetEditorCategory(EditorType type)
bool RestorePreviousEditorLayout(EditorType type)
std::vector< std::function< void()> > deferred_actions_
void QueueDeferredAction(std::function< void()> action)
Queue an action to be executed on the next frame.
LayoutManager * layout_manager_
static std::string DefaultLayoutBackupName(EditorType type)
void ProcessDeferredActions()
Process all queued deferred actions.
WorkspaceChromeBudget GetWorkspaceChromeBudget() const
float GetBottomLayoutOffset() const
Get the bottom margin needed for status bar.
UICoordinator * ui_coordinator_
static WorkspaceChromeBudget ResolveWorkspaceChromeBudget(float viewport_width, float activity_bar_width, float left_side_panel_width, float right_sidebar_width, float right_sidebar_budget_width=-1.0f, float min_canvas_width=640.0f)
bool HasPreviousEditorLayout(EditorType type) const
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_
ToastManager * toast_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 LoadLayout(const std::string &name)
Load a saved layout by name.
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 DeleteLayout(const std::string &name)
Delete a saved layout by name.
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 SaveCurrentLayout(const std::string &name, bool persist=true)
Save the current layout with a custom name.
void RequestRebuild()
Request a layout rebuild on next frame.
bool IsRebuildRequested() const
Check if rebuild was requested.
bool HasLayout(const std::string &name) const
Check if a layout exists.
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 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 GetExpandedDrawerWidth() const
float GetDrawerWidth() const
float GetHeight() const
Get the height of the status bar.
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f, std::string action_label={}, std::function< void()> on_action=nullptr)
bool IsEmulatorVisible() const
bool ShouldShowActivityBar() const
bool IsPanelSidebarVisible() const
void ResetToDefaults(size_t session_id)
void HideAll(size_t session_id)
bool IsSidebarExpanded() const
float GetActiveSidePanelWidth(float viewport_width) const
static constexpr float GetSidebarWidth()
bool OpenWindow(size_t session_id, const std::string &base_window_id)
bool IsSidebarVisible() const
#define LOG_WARN(category, format,...)
#define LOG_INFO(category, format,...)
All dependencies required by LayoutCoordinator.
ToastManager * toast_manager
UICoordinator * ui_coordinator
LayoutManager * layout_manager
WorkspaceWindowManager * window_manager
RightDrawerManager * right_drawer_manager
Defines default panel visibility for an editor type.
std::vector< std::string > default_visible_panels