yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
layout_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_LAYOUT_LAYOUT_MANAGER_H_
2#define YAZE_APP_EDITOR_LAYOUT_LAYOUT_MANAGER_H_
3
4#include <string>
5#include <unordered_map>
6#include <unordered_set>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "absl/status/statusor.h"
11#include "app/editor/editor.h"
13#include "imgui/imgui.h"
14
15namespace yaze {
16namespace editor {
17
18// Forward declaration
19class WorkspaceWindowManager;
20class UserSettings;
21
26enum class LayoutType {
32 kScreen,
33 kMusic,
34 kSprite,
39};
40
46
51 std::string id; // Stable id (e.g. "code", "debug")
52 std::string label; // UI-facing label
53 std::string description; // Short profile summary
54 std::string preset_name; // Backing LayoutPresets name
55 bool open_agent_chat = false;
56};
57
74 public:
75 LayoutManager() = default;
76 ~LayoutManager() = default;
77
83 window_manager_ = manager;
84 }
85
91
97 void InitializeEditorLayout(EditorType type, ImGuiID dockspace_id);
98
107 void RebuildLayout(EditorType type, ImGuiID dockspace_id);
108
119 bool DockDefaultPositionOnFirstOpen(size_t session_id,
120 const std::string& panel_id);
121
132 bool DockPresetPositionOnPanelOpen(size_t session_id,
133 const std::string& panel_id);
134
140 void SaveCurrentLayout(const std::string& name, bool persist = true);
141
146 void LoadLayout(const std::string& name);
147
153 void CaptureTemporarySessionLayout(size_t session_id);
154
159 bool RestoreTemporarySessionLayout(size_t session_id,
160 bool clear_after_restore = false);
161
166
171
179 bool SaveNamedSnapshot(const std::string& name, size_t session_id);
180
184 bool RestoreNamedSnapshot(const std::string& name, size_t session_id,
185 bool remove_after_restore = false);
186
190 bool DeleteNamedSnapshot(const std::string& name);
191
195 std::vector<std::string> ListNamedSnapshots(size_t session_id) const;
196
200 bool HasNamedSnapshot(const std::string& name) const;
201
207 bool DeleteLayout(const std::string& name);
208
212 static std::vector<LayoutProfile> GetBuiltInProfiles();
213
222 bool ApplyBuiltInProfile(const std::string& profile_id, size_t session_id,
223 EditorType editor_type,
224 LayoutProfile* out_profile = nullptr);
225
230 std::vector<std::string> GetSavedLayoutNames() const;
231
237 bool HasLayout(const std::string& name) const;
238
242 void LoadLayoutsFromDisk();
243
248 void SetProjectLayoutKey(const std::string& key);
249
253 void UseGlobalLayouts();
254
259
265
271 bool IsLayoutInitialized(EditorType type) const;
272
278
283
289
294
299
303 bool IsRebuildRequested() const { return rebuild_requested_; }
304
309
315 std::string GetWindowTitle(const std::string& card_id) const;
316
317 // ==========================================================================
318 // DockTree integration (Layout Designer)
319 // ==========================================================================
320
347 absl::Status ApplyDockTree(const layout_designer::DockTree& tree,
348 ImGuiID dockspace_id);
349
363 void SetMainDockspaceId(ImGuiID id) { main_dockspace_id_ = id; }
364
370 ImGuiID GetMainDockspaceId() const { return main_dockspace_id_; }
371
390
427 absl::Status MaybeReapplyStartupLayout(UserSettings* settings);
428
445 absl::StatusOr<layout_designer::DockTree> CaptureDockTree(
446 ImGuiID dockspace_id) const;
447
448 private:
449 // DockBuilder layout implementations for each editor type
450 void BuildLayoutFromPreset(EditorType type, ImGuiID dockspace_id);
452 void RefreshLazyDefaultDockingContext(EditorType type, ImGuiID dockspace_id);
454 bool DockPresetPositionOnFirstOpen(size_t session_id,
455 const std::string& panel_id,
456 bool include_default_visible);
457 void MarkLazyDefaultDockAttempted(const std::string& panel_id);
459
460 void LoadLayoutsFromDiskInternal(LayoutScope scope, bool merge);
461 void SaveLayoutsToDisk(LayoutScope scope) const;
462
463 // Deprecated individual builders - kept for compatibility or as wrappers
464 void BuildOverworldLayout(ImGuiID dockspace_id);
465 void BuildDungeonLayout(ImGuiID dockspace_id);
466 void BuildGraphicsLayout(ImGuiID dockspace_id);
467 void BuildPaletteLayout(ImGuiID dockspace_id);
468 void BuildScreenLayout(ImGuiID dockspace_id);
469 void BuildMusicLayout(ImGuiID dockspace_id);
470 void BuildSpriteLayout(ImGuiID dockspace_id);
471 void BuildMessageLayout(ImGuiID dockspace_id);
472 void BuildAssemblyLayout(ImGuiID dockspace_id);
473 void BuildSettingsLayout(ImGuiID dockspace_id);
474 void BuildEmulatorLayout(ImGuiID dockspace_id);
475
476 // Track which layouts have been initialized
477 std::unordered_map<EditorType, bool> layouts_initialized_;
478
479 // Panel manager for window title lookups
481
482 // Current layout type
484
485 // Rebuild flag
486 bool rebuild_requested_ = false;
487
488 // Last used dockspace ID (for rebuild operations)
490
491 // Main dockspace ID captured from the authoritative scope (see
492 // `SetMainDockspaceId`). 0 until the controller has rendered at least
493 // one DockSpaceWindow frame.
495
496 // True after `MaybeReapplyStartupLayout` has fired for this session
497 // (whether successfully or with a logged error). Guards the one-shot
498 // semantics across the per-frame call cadence.
500
501 // Set by `MaybeReapplyStartupLayout` after a successful apply, then
502 // consumed by the very next `InitializeEditorLayout` call (any
503 // editor type). Phase 8.2 review (2026-04-25): without this flag the
504 // first editor activation post-startup would blow away the
505 // freshly-reapplied custom layout via lazy preset init. The flag is
506 // intentionally global-one-shot rather than per-editor because at
507 // startup we don't know which editor the user will activate first;
508 // the very first lazy init is always the dangerous one.
510
511 // Current editor type being displayed
513
514 // Default presets may omit hidden panels from the initial dock tree. Keep
515 // enough state to create their preferred region lazily on first open.
517 bool enabled = false;
518 bool compact = false;
520 size_t session_id = 0;
521 ImGuiID dockspace = 0;
522 ImGuiID center = 0;
523 ImGuiID left = 0;
524 ImGuiID right = 0;
525 ImGuiID bottom = 0;
526 ImGuiID top = 0;
527 ImGuiID left_top = 0;
528 ImGuiID left_bottom = 0;
529 ImGuiID right_top = 0;
530 ImGuiID right_bottom = 0;
531 float left_ratio = 0.17f;
532 float right_ratio = 0.24f;
533 float bottom_ratio = 0.22f;
534 float top_ratio = 0.12f;
535 float vertical_split = 0.52f;
536 std::unordered_set<std::string> attempted_panels;
537 };
539 std::unordered_map<
540 size_t, std::unordered_map<EditorType, std::unordered_set<std::string>>>
542
543 // Saved layouts (panel visibility state)
544 std::unordered_map<std::string, std::unordered_map<std::string, bool>>
546
547 // In-memory temporary session snapshot (never persisted).
550 std::unordered_map<std::string, bool> temp_session_visibility_;
551 std::unordered_map<std::string, bool> temp_session_pinned_;
553
554 // Multi-slot named session snapshots (in-memory only, never persisted).
555 // The user-supplied name is the stable key; duplicate saves overwrite.
557 size_t session_id = 0;
558 std::unordered_map<std::string, bool> visibility;
559 std::unordered_map<std::string, bool> pinned;
560 std::string imgui_layout;
561 };
562 std::unordered_map<std::string, SessionSnapshot> named_snapshots_;
563
564 // Saved ImGui docking layouts (INI data)
565 std::unordered_map<std::string, std::string> saved_imgui_layouts_;
566
567 // Saved pinned panel state for layouts
568 std::unordered_map<std::string, std::unordered_map<std::string, bool>>
570
571 // Layout scope tracking
572 std::unordered_map<std::string, LayoutScope> layout_scopes_;
573
574 // Project storage key for project-scoped layouts
576};
577
578} // namespace editor
579} // namespace yaze
580
581#endif // YAZE_APP_EDITOR_LAYOUT_LAYOUT_MANAGER_H_
Manages ImGui DockBuilder layouts for each editor type.
void SetLayoutType(LayoutType type)
Set the current layout type for rebuild.
void DockOpenPresetPanels(EditorType type)
void LoadLayout(const std::string &name)
Load a saved layout by name.
std::string GetWindowTitle(const std::string &card_id) const
Get window title for a card ID from registry.
bool RestoreNamedSnapshot(const std::string &name, size_t session_id, bool remove_after_restore=false)
Restore a named snapshot by name.
void BuildScreenLayout(ImGuiID dockspace_id)
void BuildPaletteLayout(ImGuiID dockspace_id)
bool DockPresetPositionOnPanelOpen(size_t session_id, const std::string &panel_id)
Rebind any preset panel when a visibility event opens it.
WorkspaceWindowManager * window_manager() const
Get the window manager.
WorkspaceWindowManager * window_manager_
void ProtectRestoredLayoutFromDefaultInitialization()
void BuildDungeonLayout(ImGuiID dockspace_id)
void CaptureTemporarySessionLayout(size_t session_id)
Capture the current workspace as a temporary session layout.
void SetProjectLayoutKey(const std::string &key)
Set the active project layout key (enables project scope)
bool DeleteNamedSnapshot(const std::string &name)
Delete a named snapshot. Returns true if an entry was removed.
bool SaveNamedSnapshot(const std::string &name, size_t session_id)
Capture the current workspace under a named, session-scoped slot.
std::unordered_map< std::string, std::unordered_map< std::string, bool > > saved_layouts_
std::unordered_map< size_t, std::unordered_map< EditorType, std::unordered_set< std::string > > > lazy_default_dock_attempts_
void SaveLayoutsToDisk(LayoutScope scope) const
void BuildGraphicsLayout(ImGuiID dockspace_id)
absl::Status ApplyDockTree(const layout_designer::DockTree &tree, ImGuiID dockspace_id)
Apply a DockTree to the given dockspace.
void RebuildLayout(EditorType type, ImGuiID dockspace_id)
Force rebuild of layout for a specific editor type.
std::unordered_map< std::string, SessionSnapshot > named_snapshots_
void BuildEmulatorLayout(ImGuiID dockspace_id)
void LoadLayoutsFromDisk()
Load layouts for the active scope (global + optional project)
void UseGlobalLayouts()
Clear project scope and return to global layouts only.
void BuildAssemblyLayout(ImGuiID dockspace_id)
LazyDefaultDockState lazy_default_dock_state_
void ClearInitializationFlags()
Clear all initialization flags (for testing)
bool HasTemporarySessionLayout() const
Whether a temporary session layout is available.
bool startup_reapply_pending_protection_for_test() const
void BuildMessageLayout(ImGuiID dockspace_id)
void set_current_editor_type_for_test(EditorType type)
bool DeleteLayout(const std::string &name)
Delete a saved layout by name.
bool HasNamedSnapshot(const std::string &name) const
Whether a named snapshot with the given name exists.
absl::StatusOr< layout_designer::DockTree > CaptureDockTree(ImGuiID dockspace_id) const
Capture the current docking state into a DockTree.
std::unordered_map< std::string, std::string > saved_imgui_layouts_
void reset_startup_layout_consumed_for_test()
Test-only: reset the one-shot startup-reapply guard so a single test fixture can drive MaybeReapplySt...
std::vector< std::string > GetSavedLayoutNames() const
Get list of all saved layout names.
std::unordered_map< EditorType, bool > layouts_initialized_
void RefreshLazyDefaultDockingContext(EditorType type, ImGuiID dockspace_id)
void LoadLayoutsFromDiskInternal(LayoutScope scope, bool merge)
bool IsLayoutInitialized(EditorType type) const
Check if a layout has been initialized for an editor.
LayoutType GetLayoutType() const
Get the current layout type.
bool RestoreTemporarySessionLayout(size_t session_id, bool clear_after_restore=false)
Restore the temporary session layout if one has been captured.
void BuildSettingsLayout(ImGuiID dockspace_id)
std::unordered_map< std::string, std::unordered_map< std::string, bool > > saved_pinned_layouts_
void ResetToDefaultLayout(EditorType type)
Reset the layout for an editor to its default.
void SetMainDockspaceId(ImGuiID id)
Record the ImGui ID of the main dockspace from its authoring scope.
LayoutScope GetActiveScope() const
Get the active layout scope.
void BuildOverworldLayout(ImGuiID dockspace_id)
void ClearRebuildRequest()
Clear rebuild request flag.
void ClearTemporarySessionLayout()
Clear temporary session layout snapshot state.
void MarkLayoutInitialized(EditorType type)
Mark a layout as initialized.
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.
void SetWindowManager(WorkspaceWindowManager *manager)
Set the window manager for window title lookups.
static std::vector< LayoutProfile > GetBuiltInProfiles()
Get built-in layout profiles.
bool DockDefaultPositionOnFirstOpen(size_t session_id, const std::string &panel_id)
Dock a hidden-by-default panel at its preset position on first open.
void InitializeEditorLayout(EditorType type, ImGuiID dockspace_id)
Initialize the default layout for a specific editor type.
bool IsRebuildRequested() const
Check if rebuild was requested.
bool HasLayout(const std::string &name) const
Check if a layout exists.
std::unordered_map< std::string, LayoutScope > layout_scopes_
void BuildLayoutFromPreset(EditorType type, ImGuiID dockspace_id)
void BuildSpriteLayout(ImGuiID dockspace_id)
bool startup_layout_consumed_for_test() const
bool ApplyBuiltInProfile(const std::string &profile_id, size_t session_id, EditorType editor_type, LayoutProfile *out_profile=nullptr)
Apply a built-in layout profile by profile ID.
std::vector< std::string > ListNamedSnapshots(size_t session_id) const
List all named snapshots for the given session.
std::unordered_map< std::string, bool > temp_session_pinned_
void BuildMusicLayout(ImGuiID dockspace_id)
absl::Status MaybeReapplyStartupLayout(UserSettings *settings)
One-shot startup hook that re-applies the user's last applied named layout, if any.
bool DockPresetPositionOnFirstOpen(size_t session_id, const std::string &panel_id, bool include_default_visible)
void MarkLazyDefaultDockAttempted(const std::string &panel_id)
ImGuiID GetMainDockspaceId() const
Get the cached main dockspace ID.
std::unordered_map< std::string, bool > temp_session_visibility_
Manages user preferences and settings persistence.
Central registry for all editor cards with session awareness and dependency injection.
LayoutScope
Storage scope for saved layouts.
LayoutType
Predefined layout types for different editor workflows.
std::unordered_set< std::string > attempted_panels
std::unordered_map< std::string, bool > visibility
std::unordered_map< std::string, bool > pinned
Built-in workflow-oriented layout profiles.