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
6
#include "
app/editor/layout/layout_designer/dock_tree.h
"
7
#include "
app/editor/layout/layout_designer/tree_undo_stack.h
"
8
#include "
app/editor/system/workspace/editor_panel.h
"
9
#include "
app/gui/core/icons.h
"
10
#include "imgui/imgui.h"
11
#include "imgui/imgui_internal.h"
12
13
namespace
yaze
{
14
namespace
editor {
15
namespace
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.
21
class
LayoutDesignerPanel
:
public
WindowContent
{
22
public
:
23
LayoutDesignerPanel
();
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
35
WindowLifecycle
GetWindowLifecycle
()
const override
{
36
return
WindowLifecycle::CrossEditor
;
37
}
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_
; }
57
DockNodeId
selected_id_for_test
()
const
{
return
selected_id_
; }
58
bool
has_active_drag_for_test
()
const
{
59
return
drag_
.
split_id
!=
kInvalidDockNodeId
;
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.
65
void
set_selected_id_for_test
(
DockNodeId
id
) {
selected_id_
= id; }
66
void
set_drag_id_for_test
(
DockNodeId
id
) {
drag_
.
split_id
= id; }
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
{
76
DockNodeId
split_id
=
kInvalidDockNodeId
;
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.
89
void
DrawPropertiesColumn
();
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.
98
void
SaveCurrentTreeToNamedLayouts
();
99
void
LoadNamedLayoutIntoTree
(
const
std::string& name);
100
void
ApplyCurrentTreeToLiveDockspace
();
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
107
DockTree
tree_
;
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.
112
DockNodeId
selected_id_
=
kInvalidDockNodeId
;
113
ActiveDrag
drag_
;
114
std::string
palette_query_
;
115
TreeUndoStack
undo_
;
116
117
// Popup state. `*_popup_open_` flags drive one-shot OpenPopup calls
118
// next frame; the text buffers back the inline editors.
119
bool
open_popup_requested_
=
false
;
120
bool
save_as_popup_requested_
=
false
;
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_
yaze::editor::WindowContent
Base interface for all logical window content components.
Definition
editor_panel.h:90
yaze::editor::layout_designer::LayoutDesignerPanel
Definition
layout_designer_panel.h:21
yaze::editor::layout_designer::LayoutDesignerPanel::Draw
void Draw(bool *p_open) override
Draw the panel content.
Definition
layout_designer_panel.cc:352
yaze::editor::layout_designer::LayoutDesignerPanel::open_selection_
std::string open_selection_
Definition
layout_designer_panel.h:123
yaze::editor::layout_designer::LayoutDesignerPanel::set_drag_id_for_test
void set_drag_id_for_test(DockNodeId id)
Definition
layout_designer_panel.h:66
yaze::editor::layout_designer::LayoutDesignerPanel::ApplyCurrentTreeToLiveDockspace
void ApplyCurrentTreeToLiveDockspace()
Definition
layout_designer_panel.cc:156
yaze::editor::layout_designer::LayoutDesignerPanel::SaveCurrentTreeToNamedLayouts
void SaveCurrentTreeToNamedLayouts()
Definition
layout_designer_panel.cc:79
yaze::editor::layout_designer::LayoutDesignerPanel::selected_id_
DockNodeId selected_id_
Definition
layout_designer_panel.h:112
yaze::editor::layout_designer::LayoutDesignerPanel::GetId
std::string GetId() const override
Unique identifier for this panel.
Definition
layout_designer_panel.h:25
yaze::editor::layout_designer::LayoutDesignerPanel::status_message_
std::string status_message_
Definition
layout_designer_panel.h:125
yaze::editor::layout_designer::LayoutDesignerPanel::LayoutDesignerPanel
LayoutDesignerPanel()
Definition
layout_designer_panel.cc:66
yaze::editor::layout_designer::LayoutDesignerPanel::save_as_buffer_
std::string save_as_buffer_
Definition
layout_designer_panel.h:121
yaze::editor::layout_designer::LayoutDesignerPanel::palette_query_
std::string palette_query_
Definition
layout_designer_panel.h:114
yaze::editor::layout_designer::LayoutDesignerPanel::DrawOpenPopup
void DrawOpenPopup()
Definition
layout_designer_panel.cc:273
yaze::editor::layout_designer::LayoutDesignerPanel::tree_
DockTree tree_
Definition
layout_designer_panel.h:107
yaze::editor::layout_designer::LayoutDesignerPanel::undo_
TreeUndoStack undo_
Definition
layout_designer_panel.h:115
yaze::editor::layout_designer::LayoutDesignerPanel::LoadNamedLayoutIntoTree
void LoadNamedLayoutIntoTree(const std::string &name)
Definition
layout_designer_panel.cc:106
yaze::editor::layout_designer::LayoutDesignerPanel::DrawFileRow
void DrawFileRow()
Definition
layout_designer_panel.cc:208
yaze::editor::layout_designer::LayoutDesignerPanel::GetIcon
std::string GetIcon() const override
Material Design icon for this panel.
Definition
layout_designer_panel.h:27
yaze::editor::layout_designer::LayoutDesignerPanel::status_is_error_
bool status_is_error_
Definition
layout_designer_panel.h:126
yaze::editor::layout_designer::LayoutDesignerPanel::undo_for_test
const TreeUndoStack & undo_for_test() const
Definition
layout_designer_panel.h:61
yaze::editor::layout_designer::LayoutDesignerPanel::save_as_popup_requested_
bool save_as_popup_requested_
Definition
layout_designer_panel.h:120
yaze::editor::layout_designer::LayoutDesignerPanel::ReplaceTree
void ReplaceTree(DockTree new_tree)
Definition
layout_designer_panel.cc:72
yaze::editor::layout_designer::LayoutDesignerPanel::SaveOrSaveAs
void SaveOrSaveAs()
Definition
layout_designer_panel.cc:195
yaze::editor::layout_designer::LayoutDesignerPanel::tree_for_test
const DockTree & tree_for_test() const
Definition
layout_designer_panel.h:56
yaze::editor::layout_designer::LayoutDesignerPanel::open_popup_requested_
bool open_popup_requested_
Definition
layout_designer_panel.h:119
yaze::editor::layout_designer::LayoutDesignerPanel::DrawPropertiesColumn
void DrawPropertiesColumn()
Definition
layout_designer_panel.cc:555
yaze::editor::layout_designer::LayoutDesignerPanel::selected_id_for_test
DockNodeId selected_id_for_test() const
Definition
layout_designer_panel.h:57
yaze::editor::layout_designer::LayoutDesignerPanel::GetEditorCategory
std::string GetEditorCategory() const override
Editor category this panel belongs to.
Definition
layout_designer_panel.h:33
yaze::editor::layout_designer::LayoutDesignerPanel::GetWindowLifecycle
WindowLifecycle GetWindowLifecycle() const override
Get the lifecycle category for this window.
Definition
layout_designer_panel.h:35
yaze::editor::layout_designer::LayoutDesignerPanel::GetDisplayName
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
Definition
layout_designer_panel.h:26
yaze::editor::layout_designer::LayoutDesignerPanel::has_active_drag_for_test
bool has_active_drag_for_test() const
Definition
layout_designer_panel.h:58
yaze::editor::layout_designer::LayoutDesignerPanel::DrawSaveAsPopup
void DrawSaveAsPopup()
Definition
layout_designer_panel.cc:325
yaze::editor::layout_designer::LayoutDesignerPanel::PushUndoSnapshot
void PushUndoSnapshot()
Definition
layout_designer_panel.cc:68
yaze::editor::layout_designer::LayoutDesignerPanel::set_selected_id_for_test
void set_selected_id_for_test(DockNodeId id)
Definition
layout_designer_panel.h:65
yaze::editor::layout_designer::LayoutDesignerPanel::drag_
ActiveDrag drag_
Definition
layout_designer_panel.h:113
yaze::editor::layout_designer::TreeUndoStack
Definition
tree_undo_stack.h:18
dock_tree.h
icons.h
ICON_MD_DASHBOARD_CUSTOMIZE
#define ICON_MD_DASHBOARD_CUSTOMIZE
Definition
icons.h:518
yaze::editor::layout_designer::kInvalidDockNodeId
constexpr DockNodeId kInvalidDockNodeId
Definition
dock_tree.h:22
yaze::editor::layout_designer::DockNodeId
std::uint64_t DockNodeId
Definition
dock_tree.h:21
yaze::editor::WindowLifecycle
WindowLifecycle
Defines lifecycle behavior for editor windows.
Definition
editor_panel.h:25
yaze::editor::WindowLifecycle::CrossEditor
@ CrossEditor
User can pin to persist across editors.
yaze
Definition
patch_export_usage.cc:8
yaze::editor::layout_designer::DockTree
Definition
dock_tree.h:108
yaze::editor::layout_designer::LayoutDesignerPanel::ActiveDrag
Definition
layout_designer_panel.h:75
yaze::editor::layout_designer::LayoutDesignerPanel::ActiveDrag::start_ratio
float start_ratio
Definition
layout_designer_panel.h:77
yaze::editor::layout_designer::LayoutDesignerPanel::ActiveDrag::start_mouse
ImVec2 start_mouse
Definition
layout_designer_panel.h:78
yaze::editor::layout_designer::LayoutDesignerPanel::ActiveDrag::split_id
DockNodeId split_id
Definition
layout_designer_panel.h:76
yaze::editor::layout_designer::LayoutDesignerPanel::ActiveDrag::start_rect
ImRect start_rect
Definition
layout_designer_panel.h:79
tree_undo_stack.h
editor_panel.h
src
app
editor
layout
layout_designer
layout_designer_panel.h
Generated by
1.10.0