yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
layout_designer_panel.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_LAYOUT_LAYOUT_DESIGNER_LAYOUT_DESIGNER_PANEL_H_
2#define YAZE_APP_EDITOR_LAYOUT_LAYOUT_DESIGNER_LAYOUT_DESIGNER_PANEL_H_
3
4#include <string>
5
10#include "imgui/imgui.h"
11#include "imgui/imgui_internal.h"
12
13namespace yaze {
14namespace editor {
15namespace layout_designer {
16
17// Phase 3 scaffolding for the WYSIWYG layout designer. Registers a
18// cross-editor System panel with a three-column body (palette | canvas |
19// properties) and a disabled File action row. No tree state, selection,
20// persistence, or drag-drop yet — those arrive in Phases 4–8.
22 public:
24
25 std::string GetId() const override { return "layout.designer"; }
26 std::string GetDisplayName() const override { return "Layout Designer"; }
27 std::string GetIcon() const override { return ICON_MD_DASHBOARD_CUSTOMIZE; }
28 // Matches the other cross-editor shell panels (About, Settings). The
29 // workspace manager treats category strings literally (exact match vs
30 // active_category or else draws only when pinned) — see the rev-17
31 // migration in user_settings.cc which force-pins this panel so "Show"
32 // is sufficient from any editor.
33 std::string GetEditorCategory() const override { return "Settings"; }
34
38
39 void Draw(bool* p_open) override;
40
41 // Replace the currently-edited tree wholesale. Any op that swaps `tree_`
42 // (New, Open, apply-from-elsewhere) MUST go through this helper. Selection
43 // and active drag are stored by stable `DockNodeId` (Phase 8.5), so a
44 // wholesale swap technically *could* leave them set and FindNode would
45 // gracefully return nullptr — but the cleared semantics match user
46 // intent (a freshly-loaded layout shouldn't carry the previous one's
47 // cursor) and the empty-state branches in Draw are simpler. Undo history
48 // is cleared because its snapshots reference the replaced tree's
49 // identity (and mid-session undo across Load boundaries is confusing
50 // UX — users can undo *within* a loaded layout, not across loads).
51 void ReplaceTree(DockTree new_tree);
52
53 // Test-only accessors. The live Draw path is the only production
54 // mutator of `selected_id_`/`drag_`; tests need to observe both to verify
55 // the tree-swap invariant holds.
56 const DockTree& tree_for_test() const { return tree_; }
60 }
61 const TreeUndoStack& undo_for_test() const { return undo_; }
62 // Test-only setters so ReplaceTree's clear behavior can be exercised
63 // without standing up an ImGui context. Production callers should rely
64 // on Draw() to set selection/drag via mouse input.
67
68 private:
69 // Active drag state for split-boundary resize. `split_id` is
70 // `kInvalidDockNodeId` between drags; while non-zero, the panel is
71 // mid-drag and all other input is ignored until the mouse button
72 // releases. The mid-drag writeback resolves the id back to a mutable
73 // `DockNode*` via `tree_.FindNode(...)` each frame so the drag survives
74 // any concurrent tree mutation that preserves the split node.
75 struct ActiveDrag {
77 float start_ratio = 0.0f;
78 ImVec2 start_mouse{0.0f, 0.0f};
79 ImRect start_rect{};
80 };
81
82 // Undo/redo helpers. Callers push BEFORE mutating `tree_`; the
83 // stack clears on any new push so the redo branch follows the mutation
84 // that replaced it.
85 void PushUndoSnapshot();
86
87 // Properties column body — split into its own method to keep Draw()
88 // focused on layout/input routing.
90
91 // File row / popup bodies.
92 void DrawFileRow();
93 void DrawOpenPopup();
94 void DrawSaveAsPopup();
95
96 // Named-layout persistence (all operate on Context::user_settings()).
97 // No-ops with logged warnings when user_settings is unavailable.
99 void LoadNamedLayoutIntoTree(const std::string& name);
101
102 // Save routing — if the tree still carries the seed "Untitled" name
103 // (or no name), open Save As so the user commits to a real name
104 // instead of blindly writing an "Untitled" entry.
105 void SaveOrSaveAs();
106
108 // Stable id of the currently-selected node, or `kInvalidDockNodeId`.
109 // Phase 8.5: replaced raw `const DockNode*` so undo/redo and other
110 // structure-preserving mutations stop dropping the user's cursor —
111 // selection now follows the logical node rather than its address.
114 std::string palette_query_;
116
117 // Popup state. `*_popup_open_` flags drive one-shot OpenPopup calls
118 // next frame; the text buffers back the inline editors.
121 std::string save_as_buffer_;
122 std::string
123 open_selection_; // Which named layout the Open popup has highlighted.
124 // Transient status line below the File row. Cleared each frame.
125 std::string status_message_;
126 bool status_is_error_ = false;
127};
128
129} // namespace layout_designer
130} // namespace editor
131} // namespace yaze
132
133#endif // YAZE_APP_EDITOR_LAYOUT_LAYOUT_DESIGNER_LAYOUT_DESIGNER_PANEL_H_
Base interface for all logical window content components.
void Draw(bool *p_open) override
Draw the panel content.
std::string GetId() const override
Unique identifier for this panel.
std::string GetIcon() const override
Material Design icon for this panel.
std::string GetEditorCategory() const override
Editor category this panel belongs to.
WindowLifecycle GetWindowLifecycle() const override
Get the lifecycle category for this window.
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
#define ICON_MD_DASHBOARD_CUSTOMIZE
Definition icons.h:518
constexpr DockNodeId kInvalidDockNodeId
Definition dock_tree.h:22
WindowLifecycle
Defines lifecycle behavior for editor windows.
@ CrossEditor
User can pin to persist across editors.