yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
editor_layout.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_EDITOR_LAYOUT_H
2#define YAZE_APP_GUI_EDITOR_LAYOUT_H
3
4#include <functional>
5#include <optional>
6#include <string>
7#include <vector>
8
10#include "imgui/imgui.h"
11
12namespace yaze {
13namespace gui {
14
29class Toolset {
30 public:
31 Toolset() = default;
32
33 // Begin the toolbar
34 void Begin();
35
36 // End the toolbar
37 void End();
38
39 // Add mode button group
40 void BeginModeGroup();
41 bool ModeButton(const char* icon, bool selected, const char* tooltip);
42 void EndModeGroup();
43
44 // Add separator
45 void AddSeparator();
46
47 // Add ROM version badge
48 void AddRomBadge(uint8_t version, std::function<void()> on_upgrade = nullptr);
49
50 // Add quick property (inline hex editing)
51 bool AddProperty(const char* icon, const char* label, uint8_t* value,
52 std::function<void()> on_change = nullptr);
53 bool AddProperty(const char* icon, const char* label, uint16_t* value,
54 std::function<void()> on_change = nullptr);
55
56 // Add combo selector
57 bool AddCombo(const char* icon, int* current, const char* const items[],
58 int count);
59
60 // Add toggle button
61 bool AddToggle(const char* icon, bool* state, const char* tooltip);
62
63 // Add action button
64 bool AddAction(const char* icon, const char* tooltip);
65
66 // Add collapsible settings section
67 bool BeginCollapsibleSection(const char* label, bool* p_open);
69
70 // Add v3 settings indicator
71 void AddV3StatusBadge(uint8_t version, std::function<void()> on_settings);
72
73 // Add usage statistics button
74 bool AddUsageStatsButton(const char* tooltip);
75
76 // Get button count for widget registration
77 int GetButtonCount() const { return button_count_; }
78
79 private:
80 bool in_toolbar_ = false;
81 bool in_section_ = false;
83 float current_line_width_ = 0.0f;
85 std::optional<StyleVarGuard> toolbar_var_guard_;
86 std::optional<StyleColorGuard> mode_group_color_guard_;
87};
88
113 public:
114 enum class Position {
115 Free, // Floating window
116 Right, // Docked to right side
117 Left, // Docked to left side
118 Bottom, // Docked to bottom
119 Top, // Docked to top
120 Center, // Docked to center
121 Floating, // Floating but position saved
122 };
123
124 explicit PanelWindow(const char* title, const char* icon = nullptr);
125 PanelWindow(const char* title, const char* icon, bool* p_open);
126
127 // Debug: Reset frame tracking (call once per frame from main loop)
128 static void ResetFrameTracking() {
129 last_frame_count_ = ImGui::GetFrameCount();
131 }
132
133 // Debug: Check if any panel was rendered twice this frame
135 static const std::string& GetDuplicatePanelName() { return duplicate_panel_name_; }
136
137 private:
139 static std::vector<std::string> panels_begun_this_frame_;
141 static std::string duplicate_panel_name_;
142
143 public:
144
145 // Set panel properties
146 void SetDefaultSize(float width, float height);
147 void SetPosition(Position pos);
148 void SetStableId(const std::string& stable_id);
149 void SetMinimizable(bool minimizable) { minimizable_ = minimizable; }
150 void SetClosable(bool closable) { closable_ = closable; }
151 void SetHeadless(bool headless) { headless_ = headless; }
152 void SetDockingAllowed(bool allowed) { docking_allowed_ = allowed; }
153 void SetIconCollapsible(bool collapsible) { icon_collapsible_ = collapsible; }
154 void SetPinnable(bool pinnable) { pinnable_ = pinnable; }
155 void SetSaveSettings(bool save) { save_settings_ = save; }
156 void SetStartOffset(const ImVec2& offset) {
157 start_offset_ = offset;
158 start_offset_set_ = true;
159 }
160
161 // Custom Title Bar Buttons (e.g., Pin, Help, Settings)
162 // These will be drawn in the window header or top-right corner.
163 void AddHeaderButton(const char* icon, const char* tooltip, std::function<void()> callback);
164
165 // Begin drawing the panel
166 bool Begin(bool* p_open = nullptr);
167
168 // End drawing
169 void End();
170
171 // Minimize/maximize
172 void SetMinimized(bool minimized) { minimized_ = minimized; }
173 bool IsMinimized() const { return minimized_; }
174
175 // Pin management
176 void SetPinned(bool pinned) { pinned_ = pinned; }
177 bool IsPinned() const { return pinned_; }
178 void SetPinChangedCallback(std::function<void(bool)> callback) {
179 on_pin_changed_ = std::move(callback);
180 }
181
182 // Focus the panel window (bring to front and set focused)
183 void Focus();
184 bool IsFocused() const { return focused_; }
185
186 // Get the window name for ImGui operations
187 const char* GetWindowName() const { return window_name_.c_str(); }
188
189 private:
190 std::string title_;
191 std::string icon_;
192 std::string window_name_; // Full window name with icon
193 std::string stable_id_;
195 bool default_size_set_ = false;
197 bool minimizable_ = true;
198 bool closable_ = true;
199 bool minimized_ = false;
200 bool first_draw_ = true;
201 bool focused_ = false;
202 bool* p_open_ = nullptr;
203 bool imgui_begun_ = false; // Track if ImGui::Begin() was called
204
205 // UX enhancements
206 bool headless_ = false; // Minimal chrome, no title bar
207 bool docking_allowed_ = true; // Allow docking
208 bool icon_collapsible_ = false; // Can collapse to floating icon
209 bool collapsed_to_icon_ = false; // Currently collapsed
210 ImVec2 saved_icon_pos_ = ImVec2(10, 100); // Position when collapsed to icon
211 ImVec2 start_offset_ = ImVec2(0, 0);
212 bool start_offset_set_ = false;
213
214 // Pinning support
215 bool pinnable_ = false;
216 bool pinned_ = false;
217 std::function<void(bool)> on_pin_changed_;
218
219 // Settings persistence
220 bool save_settings_ = true; // If false, uses ImGuiWindowFlags_NoSavedSettings
221
222 // Header buttons
224 std::string icon;
225 std::string tooltip;
226 std::function<void()> callback;
227 };
228 std::vector<HeaderButton> header_buttons_;
229
231 void DrawHeaderButtons();
232 void UpdateWindowName();
233
234 std::optional<StyleVarGuard> panel_var_guard_;
235 std::optional<StyleColorGuard> panel_color_guard_;
236};
237
250 public:
251 EditorLayout() = default;
252
253 // Begin the editor layout
254 void Begin();
255
256 // End the editor layout
257 void End();
258
259 // Get toolbar reference
261
262 // Begin main canvas area
263 void BeginMainCanvas();
264 void EndMainCanvas();
265
266 // Register a panel (for layout management)
267 void RegisterPanel(PanelWindow* panel);
268
269 private:
271 std::vector<PanelWindow*> panels_;
272 bool in_layout_ = false;
273};
274
275} // namespace gui
276} // namespace yaze
277
278#endif // YAZE_APP_GUI_EDITOR_LAYOUT_H
Modern layout manager for editor components.
void RegisterPanel(PanelWindow *panel)
std::vector< PanelWindow * > panels_
Draggable, dockable panel for editor sub-windows.
void SetIconCollapsible(bool collapsible)
static std::string duplicate_panel_name_
std::function< void(bool)> on_pin_changed_
std::optional< StyleVarGuard > panel_var_guard_
static void ResetFrameTracking()
void SetMinimizable(bool minimizable)
PanelWindow(const char *title, const char *icon=nullptr)
std::vector< HeaderButton > header_buttons_
void SetPinChangedCallback(std::function< void(bool)> callback)
void SetPinned(bool pinned)
void SetStartOffset(const ImVec2 &offset)
const char * GetWindowName() const
void SetSaveSettings(bool save)
void SetHeadless(bool headless)
void SetStableId(const std::string &stable_id)
void SetPinnable(bool pinnable)
static const std::string & GetDuplicatePanelName()
std::optional< StyleColorGuard > panel_color_guard_
void SetClosable(bool closable)
void SetPosition(Position pos)
bool Begin(bool *p_open=nullptr)
void AddHeaderButton(const char *icon, const char *tooltip, std::function< void()> callback)
static bool duplicate_detected_
void SetMinimized(bool minimized)
void SetDockingAllowed(bool allowed)
static std::vector< std::string > panels_begun_this_frame_
static bool HasDuplicateRendering()
void SetDefaultSize(float width, float height)
Ultra-compact toolbar that merges mode buttons with settings.
bool ModeButton(const char *icon, bool selected, const char *tooltip)
bool AddUsageStatsButton(const char *tooltip)
bool BeginCollapsibleSection(const char *label, bool *p_open)
std::optional< StyleColorGuard > mode_group_color_guard_
std::optional< StyleVarGuard > toolbar_var_guard_
bool AddProperty(const char *icon, const char *label, uint8_t *value, std::function< void()> on_change=nullptr)
bool AddAction(const char *icon, const char *tooltip)
int GetButtonCount() const
bool AddCombo(const char *icon, int *current, const char *const items[], int count)
void AddRomBadge(uint8_t version, std::function< void()> on_upgrade=nullptr)
void AddV3StatusBadge(uint8_t version, std::function< void()> on_settings)
bool AddToggle(const char *icon, bool *state, const char *tooltip)