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 <vector>
7
8#include "absl/status/status.h"
9#include "absl/status/statusor.h"
10#include "app/editor/editor.h"
12#include "imgui/imgui.h"
13
14namespace yaze {
15namespace editor {
16
17// Forward declaration
18class WorkspaceWindowManager;
19class UserSettings;
20
25enum class LayoutType {
31 kScreen,
32 kMusic,
33 kSprite,
38};
39
45
50 std::string id; // Stable id (e.g. "code", "debug")
51 std::string label; // UI-facing label
52 std::string description; // Short profile summary
53 std::string preset_name; // Backing LayoutPresets name
54 bool open_agent_chat = false;
55};
56
73 public:
74 LayoutManager() = default;
75 ~LayoutManager() = default;
76
82 window_manager_ = manager;
83 }
84
90
96 void InitializeEditorLayout(EditorType type, ImGuiID dockspace_id);
97
106 void RebuildLayout(EditorType type, ImGuiID dockspace_id);
107
113 void SaveCurrentLayout(const std::string& name, bool persist = true);
114
119 void LoadLayout(const std::string& name);
120
126 void CaptureTemporarySessionLayout(size_t session_id);
127
132 bool RestoreTemporarySessionLayout(size_t session_id,
133 bool clear_after_restore = false);
134
139
144
152 bool SaveNamedSnapshot(const std::string& name, size_t session_id);
153
157 bool RestoreNamedSnapshot(const std::string& name, size_t session_id,
158 bool remove_after_restore = false);
159
163 bool DeleteNamedSnapshot(const std::string& name);
164
168 std::vector<std::string> ListNamedSnapshots(size_t session_id) const;
169
173 bool HasNamedSnapshot(const std::string& name) const;
174
180 bool DeleteLayout(const std::string& name);
181
185 static std::vector<LayoutProfile> GetBuiltInProfiles();
186
195 bool ApplyBuiltInProfile(const std::string& profile_id, size_t session_id,
196 EditorType editor_type,
197 LayoutProfile* out_profile = nullptr);
198
203 std::vector<std::string> GetSavedLayoutNames() const;
204
210 bool HasLayout(const std::string& name) const;
211
215 void LoadLayoutsFromDisk();
216
221 void SetProjectLayoutKey(const std::string& key);
222
226 void UseGlobalLayouts();
227
232
238
244 bool IsLayoutInitialized(EditorType type) const;
245
251
256
262
267
272
276 bool IsRebuildRequested() const { return rebuild_requested_; }
277
282
288 std::string GetWindowTitle(const std::string& card_id) const;
289
290 // ==========================================================================
291 // DockTree integration (Layout Designer)
292 // ==========================================================================
293
320 absl::Status ApplyDockTree(const layout_designer::DockTree& tree,
321 ImGuiID dockspace_id);
322
336 void SetMainDockspaceId(ImGuiID id) { main_dockspace_id_ = id; }
337
343 ImGuiID GetMainDockspaceId() const { return main_dockspace_id_; }
344
363
400 absl::Status MaybeReapplyStartupLayout(UserSettings* settings);
401
418 absl::StatusOr<layout_designer::DockTree> CaptureDockTree(
419 ImGuiID dockspace_id) const;
420
421 private:
422 // DockBuilder layout implementations for each editor type
423 void BuildLayoutFromPreset(EditorType type, ImGuiID dockspace_id);
424
425 void LoadLayoutsFromDiskInternal(LayoutScope scope, bool merge);
426 void SaveLayoutsToDisk(LayoutScope scope) const;
427
428 // Deprecated individual builders - kept for compatibility or as wrappers
429 void BuildOverworldLayout(ImGuiID dockspace_id);
430 void BuildDungeonLayout(ImGuiID dockspace_id);
431 void BuildGraphicsLayout(ImGuiID dockspace_id);
432 void BuildPaletteLayout(ImGuiID dockspace_id);
433 void BuildScreenLayout(ImGuiID dockspace_id);
434 void BuildMusicLayout(ImGuiID dockspace_id);
435 void BuildSpriteLayout(ImGuiID dockspace_id);
436 void BuildMessageLayout(ImGuiID dockspace_id);
437 void BuildAssemblyLayout(ImGuiID dockspace_id);
438 void BuildSettingsLayout(ImGuiID dockspace_id);
439 void BuildEmulatorLayout(ImGuiID dockspace_id);
440
441 // Track which layouts have been initialized
442 std::unordered_map<EditorType, bool> layouts_initialized_;
443
444 // Panel manager for window title lookups
446
447 // Current layout type
449
450 // Rebuild flag
451 bool rebuild_requested_ = false;
452
453 // Last used dockspace ID (for rebuild operations)
455
456 // Main dockspace ID captured from the authoritative scope (see
457 // `SetMainDockspaceId`). 0 until the controller has rendered at least
458 // one DockSpaceWindow frame.
460
461 // True after `MaybeReapplyStartupLayout` has fired for this session
462 // (whether successfully or with a logged error). Guards the one-shot
463 // semantics across the per-frame call cadence.
465
466 // Set by `MaybeReapplyStartupLayout` after a successful apply, then
467 // consumed by the very next `InitializeEditorLayout` call (any
468 // editor type). Phase 8.2 review (2026-04-25): without this flag the
469 // first editor activation post-startup would blow away the
470 // freshly-reapplied custom layout via lazy preset init. The flag is
471 // intentionally global-one-shot rather than per-editor because at
472 // startup we don't know which editor the user will activate first;
473 // the very first lazy init is always the dangerous one.
475
476 // Current editor type being displayed
478
479 // Saved layouts (panel visibility state)
480 std::unordered_map<std::string, std::unordered_map<std::string, bool>>
482
483 // In-memory temporary session snapshot (never persisted).
486 std::unordered_map<std::string, bool> temp_session_visibility_;
487 std::unordered_map<std::string, bool> temp_session_pinned_;
489
490 // Multi-slot named session snapshots (in-memory only, never persisted).
491 // The user-supplied name is the stable key; duplicate saves overwrite.
493 size_t session_id = 0;
494 std::unordered_map<std::string, bool> visibility;
495 std::unordered_map<std::string, bool> pinned;
496 std::string imgui_layout;
497 };
498 std::unordered_map<std::string, SessionSnapshot> named_snapshots_;
499
500 // Saved ImGui docking layouts (INI data)
501 std::unordered_map<std::string, std::string> saved_imgui_layouts_;
502
503 // Saved pinned panel state for layouts
504 std::unordered_map<std::string, std::unordered_map<std::string, bool>>
506
507 // Layout scope tracking
508 std::unordered_map<std::string, LayoutScope> layout_scopes_;
509
510 // Project storage key for project-scoped layouts
512};
513
514} // namespace editor
515} // namespace yaze
516
517#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 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)
WorkspaceWindowManager * window_manager() const
Get the window manager.
WorkspaceWindowManager * window_manager_
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_
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)
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 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.
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.
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_map< std::string, bool > visibility
std::unordered_map< std::string, bool > pinned
Built-in workflow-oriented layout profiles.