yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
layout_designer_window.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_LAYOUT_DESIGNER_LAYOUT_DESIGNER_WINDOW_H_
2#define YAZE_APP_EDITOR_LAYOUT_DESIGNER_LAYOUT_DESIGNER_WINDOW_H_
3
4#include <memory>
5#include <string>
6#include <vector>
7#include <optional>
8
13
14#define IMGUI_DEFINE_MATH_OPERATORS
15#include "imgui/imgui.h"
16
17namespace yaze { namespace editor { class LayoutManager; class EditorManager; } }
18
19namespace yaze {
20namespace editor {
21namespace layout_designer {
22
27enum class DesignMode {
28 PanelLayout, // Design panel/window layout
29 WidgetDesign // Design internal panel widgets
30};
31
44 public:
47 PanelManager* panel_manager,
48 yaze::editor::EditorManager* editor_manager)
49 : layout_manager_(layout_manager),
50 editor_manager_(editor_manager),
51 panel_manager_(panel_manager) {}
52
57 void Initialize(PanelManager* panel_manager, yaze::editor::LayoutManager* layout_manager = nullptr, yaze::editor::EditorManager* editor_manager = nullptr);
58
62 void Open();
63
67 void Close();
68
72 bool IsOpen() const { return is_open_; }
73
77 void Draw();
78
82 void NewLayout();
83
87 void LoadLayout(const std::string& filepath);
88
92 void SaveLayout(const std::string& filepath);
93
97 void ImportFromRuntime();
98
103 void ImportPanelDesign(const std::string& panel_id);
104
108 void ExportCode(const std::string& filepath);
109
113 void PreviewLayout();
114
115 private:
116 // Panel palette
118 std::string id;
119 std::string name;
120 std::string icon;
121 std::string category;
122 std::string description;
124 };
125
126 // UI Components
127 void DrawMenuBar();
128 void DrawToolbar();
129 void DrawPalette();
130 void DrawCanvas();
131 void DrawProperties();
132 void DrawTreeView();
133 void DrawCodePreview();
134
135 // Widget Design Mode UI
136 void DrawWidgetPalette();
137 void DrawWidgetCanvas();
139 void DrawWidgetTree();
141
142 // Theme UI
143 void DrawThemeProperties();
144
145 // Canvas interaction
147 void DrawDockNode(DockNode* node, const ImVec2& pos, const ImVec2& size);
148 void DrawDropZones(const ImVec2& pos, const ImVec2& size, DockNode* target_node);
149 bool IsMouseOverRect(const ImVec2& rect_min, const ImVec2& rect_max) const;
150 ImGuiDir GetDropZone(const ImVec2& mouse_pos, const ImVec2& rect_min,
151 const ImVec2& rect_max) const;
152 void ResetDropState();
153 std::optional<PalettePanel> ResolvePanelById(const std::string& panel_id) const;
154 void AddPanelToTarget(const PalettePanel& panel);
155
156 // Properties
157 void DrawPanelProperties(LayoutPanel* panel);
158 void DrawNodeProperties(DockNode* node);
159
160 // Code generation
161 std::string GenerateDockBuilderCode() const;
162 std::string GenerateLayoutPresetCode() const;
163
164 // Tree View
165 void DrawDockNodeTree(DockNode* node, int& node_index);
166
167 // Edit operations
168 void DeleteNode(DockNode* node);
169 void DeletePanel(LayoutPanel* panel);
170
171 // Undo/Redo
172 void PushUndoState();
173 void Undo();
174 void Redo();
175
176 // Undo/Redo stacks
177 std::vector<std::unique_ptr<LayoutDefinition>> undo_stack_;
178 std::vector<std::unique_ptr<LayoutDefinition>> redo_stack_;
179 static constexpr size_t kMaxUndoSteps = 50;
180
181 std::vector<PalettePanel> GetAvailablePanels() const;
182 void RefreshPanelCache();
183 bool MatchesSearchFilter(const PalettePanel& panel) const;
184
185 // State
186 bool is_open_ = false;
187 bool show_code_preview_ = false;
188 bool show_tree_view_ = true;
189
190 // Design mode
192
193 // Current layout being edited
194 std::unique_ptr<LayoutDefinition> current_layout_;
195
196 // Widget design state
197 std::unique_ptr<PanelDesign> current_panel_design_;
198 std::string selected_panel_for_design_; // Panel ID to design widgets for
199
200 // Theme properties
203 bool show_theme_panel_ = false;
204
205 // Selection state (Panel Layout Mode)
209
210 // Selection state (Widget Design Mode)
212
213 // Drag and drop state
214 bool is_dragging_panel_ = false;
218 ImGuiDir drop_direction_ = ImGuiDir_None;
220
221 // Preview/application hooks
224 // Panel manager reference (for importing panels)
226
227 // Search filter for palette
228 char search_filter_[256] = "";
229 std::string selected_category_filter_ = "All";
230
231 // Widget palette search
232 char widget_search_filter_[256] = "";
233 std::string selected_widget_category_ = "All";
234
235 // Panel cache
236 mutable std::vector<PalettePanel> panel_cache_;
237 mutable bool panel_cache_dirty_ = true;
238
239 // Canvas state
240 ImVec2 canvas_scroll_ = ImVec2(0, 0);
241 float canvas_zoom_ = 1.0f;
242};
243
244} // namespace layout_designer
245} // namespace editor
246} // namespace yaze
247
248#endif // YAZE_APP_EDITOR_LAYOUT_DESIGNER_LAYOUT_DESIGNER_WINDOW_H_
The EditorManager controls the main editor window and manages the various editor classes.
Manages ImGui DockBuilder layouts for each editor type.
Central registry for all editor cards with session awareness and dependency injection.
Main window for the WYSIWYG layout designer.
std::vector< std::unique_ptr< LayoutDefinition > > redo_stack_
void PreviewLayout()
Apply current layout to the application (live preview)
LayoutDesignerWindow(yaze::editor::LayoutManager *layout_manager, PanelManager *panel_manager, yaze::editor::EditorManager *editor_manager)
void DrawDropZones(const ImVec2 &pos, const ImVec2 &size, DockNode *target_node)
void Draw()
Draw the designer window (call every frame)
void ImportPanelDesign(const std::string &panel_id)
Import a specific panel's design from runtime.
void ExportCode(const std::string &filepath)
Export layout as C++ code.
bool IsOpen() const
Check if designer window is open.
void ImportFromRuntime()
Import layout from current runtime state.
bool MatchesSearchFilter(const PalettePanel &panel) const
void LoadLayout(const std::string &filepath)
Load a layout from JSON file.
bool IsMouseOverRect(const ImVec2 &rect_min, const ImVec2 &rect_max) const
ImGuiDir GetDropZone(const ImVec2 &mouse_pos, const ImVec2 &rect_min, const ImVec2 &rect_max) const
void DrawDockNode(DockNode *node, const ImVec2 &pos, const ImVec2 &size)
void SaveLayout(const std::string &filepath)
Save current layout to JSON file.
std::vector< std::unique_ptr< LayoutDefinition > > undo_stack_
void Initialize(PanelManager *panel_manager, yaze::editor::LayoutManager *layout_manager=nullptr, yaze::editor::EditorManager *editor_manager=nullptr)
Initialize the designer with manager references.
std::optional< PalettePanel > ResolvePanelById(const std::string &panel_id) const
UI panel for editing theme properties in the layout designer.
DesignMode
Design mode for the layout designer.
Represents a dock node in the layout tree.
Represents a single panel in a layout.
Encapsulates ImGui style properties for visual design.
Defines a widget instance in a panel layout.