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 <string>
6#include <vector>
7
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace gui {
12
27class Toolset {
28 public:
29 Toolset() = default;
30
31 // Begin the toolbar
32 void Begin();
33
34 // End the toolbar
35 void End();
36
37 // Add mode button group
38 void BeginModeGroup();
39 bool ModeButton(const char* icon, bool selected, const char* tooltip);
40 void EndModeGroup();
41
42 // Add separator
43 void AddSeparator();
44
45 // Add ROM version badge
46 void AddRomBadge(uint8_t version, std::function<void()> on_upgrade = nullptr);
47
48 // Add quick property (inline hex editing)
49 bool AddProperty(const char* icon, const char* label, uint8_t* value,
50 std::function<void()> on_change = nullptr);
51 bool AddProperty(const char* icon, const char* label, uint16_t* value,
52 std::function<void()> on_change = nullptr);
53
54 // Add combo selector
55 bool AddCombo(const char* icon, int* current, const char* const items[],
56 int count);
57
58 // Add toggle button
59 bool AddToggle(const char* icon, bool* state, const char* tooltip);
60
61 // Add action button
62 bool AddAction(const char* icon, const char* tooltip);
63
64 // Add collapsible settings section
65 bool BeginCollapsibleSection(const char* label, bool* p_open);
67
68 // Add v3 settings indicator
69 void AddV3StatusBadge(uint8_t version, std::function<void()> on_settings);
70
71 // Add usage statistics button
72 bool AddUsageStatsButton(const char* tooltip);
73
74 // Get button count for widget registration
75 int GetButtonCount() const { return button_count_; }
76
77 private:
78 bool in_toolbar_ = false;
79 bool in_section_ = false;
81 float current_line_width_ = 0.0f;
83};
84
109 public:
110 enum class Position {
111 Free, // Floating window
112 Right, // Docked to right side
113 Left, // Docked to left side
114 Bottom, // Docked to bottom
115 Top, // Docked to top
116 Center, // Docked to center
117 Floating, // Floating but position saved
118 };
119
120 explicit PanelWindow(const char* title, const char* icon = nullptr);
121 PanelWindow(const char* title, const char* icon, bool* p_open);
122
123 // Debug: Reset frame tracking (call once per frame from main loop)
124 static void ResetFrameTracking() {
125 last_frame_count_ = ImGui::GetFrameCount();
127 }
128
129 // Debug: Check if any panel was rendered twice this frame
131 static const std::string& GetDuplicatePanelName() { return duplicate_panel_name_; }
132
133 private:
135 static std::vector<std::string> panels_begun_this_frame_;
137 static std::string duplicate_panel_name_;
138
139 public:
140
141 // Set panel properties
142 void SetDefaultSize(float width, float height);
143 void SetPosition(Position pos);
144 void SetMinimizable(bool minimizable) { minimizable_ = minimizable; }
145 void SetClosable(bool closable) { closable_ = closable; }
146 void SetHeadless(bool headless) { headless_ = headless; }
147 void SetDockingAllowed(bool allowed) { docking_allowed_ = allowed; }
148 void SetIconCollapsible(bool collapsible) { icon_collapsible_ = collapsible; }
149 void SetPinnable(bool pinnable) { pinnable_ = pinnable; }
150 void SetSaveSettings(bool save) { save_settings_ = save; }
151
152 // Custom Title Bar Buttons (e.g., Pin, Help, Settings)
153 // These will be drawn in the window header or top-right corner.
154 void AddHeaderButton(const char* icon, const char* tooltip, std::function<void()> callback);
155
156 // Begin drawing the panel
157 bool Begin(bool* p_open = nullptr);
158
159 // End drawing
160 void End();
161
162 // Minimize/maximize
163 void SetMinimized(bool minimized) { minimized_ = minimized; }
164 bool IsMinimized() const { return minimized_; }
165
166 // Pin management
167 void SetPinned(bool pinned) { pinned_ = pinned; }
168 bool IsPinned() const { return pinned_; }
169 void SetPinChangedCallback(std::function<void(bool)> callback) {
170 on_pin_changed_ = std::move(callback);
171 }
172
173 // Focus the panel window (bring to front and set focused)
174 void Focus();
175 bool IsFocused() const { return focused_; }
176
177 // Get the window name for ImGui operations
178 const char* GetWindowName() const { return window_name_.c_str(); }
179
180 private:
181 std::string title_;
182 std::string icon_;
183 std::string window_name_; // Full window name with icon
186 bool minimizable_ = true;
187 bool closable_ = true;
188 bool minimized_ = false;
189 bool first_draw_ = true;
190 bool focused_ = false;
191 bool* p_open_ = nullptr;
192 bool imgui_begun_ = false; // Track if ImGui::Begin() was called
193
194 // UX enhancements
195 bool headless_ = false; // Minimal chrome, no title bar
196 bool docking_allowed_ = true; // Allow docking
197 bool icon_collapsible_ = false; // Can collapse to floating icon
198 bool collapsed_to_icon_ = false; // Currently collapsed
199 ImVec2 saved_icon_pos_ = ImVec2(10, 100); // Position when collapsed to icon
200
201 // Pinning support
202 bool pinnable_ = false;
203 bool pinned_ = false;
204 std::function<void(bool)> on_pin_changed_;
205
206 // Settings persistence
207 bool save_settings_ = true; // If false, uses ImGuiWindowFlags_NoSavedSettings
208
209 // Header buttons
211 std::string icon;
212 std::string tooltip;
213 std::function<void()> callback;
214 };
215 std::vector<HeaderButton> header_buttons_;
216
218 void DrawHeaderButtons();
219};
220
233 public:
234 EditorLayout() = default;
235
236 // Begin the editor layout
237 void Begin();
238
239 // End the editor layout
240 void End();
241
242 // Get toolbar reference
244
245 // Begin main canvas area
246 void BeginMainCanvas();
247 void EndMainCanvas();
248
249 // Register a panel (for layout management)
250 void RegisterPanel(PanelWindow* panel);
251
252 private:
254 std::vector<PanelWindow*> panels_;
255 bool in_layout_ = false;
256};
257
258} // namespace gui
259} // namespace yaze
260
261#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_
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)
const char * GetWindowName() const
void SetSaveSettings(bool save)
void SetHeadless(bool headless)
void SetPinnable(bool pinnable)
static const std::string & GetDuplicatePanelName()
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)
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)