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:
116 static constexpr float kWindowPadding = 10.0f;
117
118 enum class Position {
119 Free, // Floating window
120 Right, // Docked to right side
121 Left, // Docked to left side
122 Bottom, // Docked to bottom
123 Top, // Docked to top
124 Center, // Docked to center
125 Floating, // Floating but position saved
126 };
127
128 explicit PanelWindow(const char* title, const char* icon = nullptr);
129 PanelWindow(const char* title, const char* icon, bool* p_open);
130
131 // Debug: Reset frame tracking (call once per frame from main loop)
132 static void ResetFrameTracking() {
133 last_frame_count_ = ImGui::GetFrameCount();
135 }
136
137 // Debug: Check if any panel was rendered twice this frame
139 static const std::string& GetDuplicatePanelName() {
141 }
142
143 private:
145 static std::vector<std::string> panels_begun_this_frame_;
147 static std::string duplicate_panel_name_;
148
149 public:
150 // Set panel properties
151 void SetDefaultSize(float width, float height);
152 void SetPosition(Position pos);
153 void SetStableId(const std::string& stable_id);
154 void SetMinimizable(bool minimizable) { minimizable_ = minimizable; }
155 void SetClosable(bool closable) { closable_ = closable; }
156 void SetHeadless(bool headless) { headless_ = headless; }
157 void SetDockingAllowed(bool allowed) { docking_allowed_ = allowed; }
158 void SetIconCollapsible(bool collapsible) { icon_collapsible_ = collapsible; }
159 void SetPinnable(bool pinnable) { pinnable_ = pinnable; }
160 void SetSaveSettings(bool save) { save_settings_ = save; }
161 void SetStartOffset(const ImVec2& offset) {
162 start_offset_ = offset;
163 start_offset_set_ = true;
164 }
165
166 // Custom Title Bar Buttons (e.g., Pin, Help, Settings)
167 // These will be drawn in the window header or top-right corner.
168 void AddHeaderButton(const char* icon, const char* tooltip,
169 std::function<void()> callback);
170
173
174 // Begin drawing the panel
175 bool Begin(bool* p_open = nullptr);
176
177 // End drawing
178 void End();
179
180 // Minimize/maximize
181 void SetMinimized(bool minimized) { minimized_ = minimized; }
182 bool IsMinimized() const { return minimized_; }
183
184 // Pin management
185 void SetPinned(bool pinned) { pinned_ = pinned; }
186 bool IsPinned() const { return pinned_; }
187 void SetPinChangedCallback(std::function<void(bool)> callback) {
188 on_pin_changed_ = std::move(callback);
189 }
190
191 // Focus the panel window (bring to front and set focused)
192 void Focus();
193 bool IsFocused() const { return focused_; }
194
195 // Get the window name for ImGui operations
196 const char* GetWindowName() const { return window_name_.c_str(); }
197
198 private:
199 std::string title_;
200 std::string icon_;
201 std::string window_name_; // Full window name with icon
202 std::string stable_id_;
204 bool default_size_set_ = false;
206 bool minimizable_ = true;
207 bool closable_ = true;
208 bool minimized_ = false;
209 bool first_draw_ = true;
210 bool focused_ = false;
211 bool* p_open_ = nullptr;
212 bool imgui_begun_ = false; // Track if ImGui::Begin() was called
213
214 // UX enhancements
215 bool headless_ = false; // Minimal chrome, no title bar
216 bool docking_allowed_ = true; // Allow docking
217 bool icon_collapsible_ = false; // Can collapse to floating icon
218 bool collapsed_to_icon_ = false; // Currently collapsed
219 ImVec2 saved_icon_pos_ = ImVec2(10, 100); // Position when collapsed to icon
220 ImVec2 start_offset_ = ImVec2(0, 0);
221 bool start_offset_set_ = false;
222
223 // Pinning support
224 bool pinnable_ = false;
225 bool pinned_ = false;
226 std::function<void(bool)> on_pin_changed_;
227
228 // Settings persistence
230 true; // If false, uses ImGuiWindowFlags_NoSavedSettings
231 bool force_undock_ = false;
232
233 // Header buttons
235 std::string icon;
236 std::string tooltip;
237 std::function<void()> callback;
238 };
239 std::vector<HeaderButton> header_buttons_;
240
242 void DrawHeaderButtons();
243 void UpdateWindowName();
244
245 std::optional<StyleVarGuard> panel_var_guard_;
246 std::optional<StyleColorGuard> panel_color_guard_;
247};
248
261 public:
262 EditorLayout() = default;
263
264 // Begin the editor layout
265 void Begin();
266
267 // End the editor layout
268 void End();
269
270 // Get toolbar reference
272
273 // Begin main canvas area
274 void BeginMainCanvas();
275 void EndMainCanvas();
276
277 // Register a panel (for layout management)
278 void RegisterPanel(PanelWindow* panel);
279
280 private:
282 std::vector<PanelWindow*> panels_;
283 bool in_layout_ = false;
284};
285
286} // namespace gui
287} // namespace yaze
288
289#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 constexpr float kWindowPadding
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)