yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
ui_helpers.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_UI_HELPERS_H
2#define YAZE_APP_GUI_UI_HELPERS_H
3
4#include <functional>
5#include <string>
6
7#include "imgui/imgui.h"
8
9namespace yaze {
10namespace gui {
11
12// A collection of helper functions and widgets to standardize UI development
13// and reduce boilerplate ImGui code across all editors.
14
15// ============================================================================
16// Theme and Semantic Colors
17// ============================================================================
18
19// Semantic color enum for type-safe theme color access.
20enum class SemanticColor {
21 Primary,
24 Error,
25 Warning,
26 Success,
27 Info,
30};
31
32// Resolve a SemanticColor to an ImVec4 from the current theme.
34
35// Gets a color from the current theme
36ImVec4 GetThemeColor(ImGuiCol idx);
37
38// Semantic colors from current theme
39ImVec4 GetSuccessColor();
40ImVec4 GetWarningColor();
41ImVec4 GetErrorColor();
42ImVec4 GetInfoColor();
43ImVec4 GetAccentColor();
44ImVec4 GetDisabledColor();
45
46// Entity/Map marker colors (for overworld, dungeon)
47ImVec4 GetEntranceColor();
48ImVec4 GetExitColor();
49ImVec4 GetItemColor();
50ImVec4 GetSpriteColor();
51ImVec4 GetSelectedColor();
52ImVec4 GetLockedColor();
53
54// Status colors
55ImVec4 GetVanillaRomColor();
56ImVec4 GetCustomRomColor();
57ImVec4 GetModifiedColor();
58
59// ============================================================================
60// Colored Text Shortcuts
61// ============================================================================
62// Replace PushStyleColor(ImGuiCol_Text, c); Text(...); PopStyleColor();
63
64// Render text with an explicit ImVec4 color.
65void ColoredText(const char* text, const ImVec4& color);
66
67// Render formatted text with an explicit ImVec4 color.
68void ColoredTextF(const ImVec4& color, const char* fmt, ...) IM_FMTARGS(2);
69
70// Render text with a SemanticColor from the current theme.
71void ThemedText(const char* text, SemanticColor color);
72
73// Render formatted text with a SemanticColor from the current theme.
74void ThemedTextF(SemanticColor color, const char* fmt, ...) IM_FMTARGS(2);
75
76// ============================================================================
77// Button Color Sets
78// ============================================================================
79
80// Pre-computed 3-color set for styled buttons (button, hovered, active).
82 ImVec4 button;
83 ImVec4 hovered;
84 ImVec4 active;
85};
86
91
92// ============================================================================
93// Themed Separator
94// ============================================================================
95
96// Draw a separator using the theme's separator/border color.
97void ThemedSeparator();
98
99// ============================================================================
100// Layout Helpers
101// ============================================================================
102
103// Label + widget field pattern
104void BeginField(const char* label, float label_width = 0.0f);
105void EndField();
106
107// Property table pattern (common in editors)
108bool BeginPropertyTable(const char* id, int columns = 2,
109 ImGuiTableFlags extra_flags = 0);
110void EndPropertyTable();
111
112// Property row helpers
113void PropertyRow(const char* label, const char* value);
114void PropertyRow(const char* label, int value);
115void PropertyRowHex(const char* label, uint8_t value);
116void PropertyRowHex(const char* label, uint16_t value);
117
118// Section headers with icons
119void SectionHeader(const char* icon, const char* label,
120 const ImVec4& color = ImVec4(1, 1, 1, 1));
121
122// ============================================================================
123// Common Widget Patterns
124// ============================================================================
125
126// Button with icon
127bool IconButton(const char* icon, const char* label,
128 const ImVec2& size = ImVec2(0, 0));
129
130// Icon-only button (AgentUI style)
131bool IconButton(const char* icon, const char* tooltip = nullptr);
132
133// Colored button for status actions
135bool ColoredButton(const char* label, ButtonType type,
136 const ImVec2& size = ImVec2(0, 0));
137
138// Styled button with custom color (AgentUI style)
139bool StyledButton(const char* label, const ImVec4& color,
140 const ImVec2& size = ImVec2(0, 0));
141
142// Toggle button with visual state
143bool ToggleIconButton(const char* icon_on, const char* icon_off, bool* state,
144 const char* tooltip = nullptr);
145
146// Toggle button that looks like a regular button but stays pressed
147bool ToggleButton(const char* label, bool active,
148 const ImVec2& size = ImVec2(0, 0));
149
150// Help marker with tooltip
151void HelpMarker(const char* desc);
152
153// Separator with text
154void SeparatorText(const char* label);
155
156// Status badge (pill-shaped colored label)
157void StatusBadge(const char* text, ButtonType type = ButtonType::Default);
158
159// ============================================================================
160// Editor-Specific Patterns
161// ============================================================================
162
163// Canvas container patterns
164void BeginCanvasContainer(const char* id, bool scrollable = true);
165void EndCanvasContainer();
166
167// Tab pattern for editor modes
168bool EditorTabItem(const char* icon, const char* label, bool* p_open = nullptr);
169
170// Modal confirmation dialog
171bool ConfirmationDialog(const char* id, const char* title, const char* message,
172 const char* confirm_text = "OK",
173 const char* cancel_text = "Cancel");
174
175// ============================================================================
176// Visual Indicators
177// ============================================================================
178
179// Status indicator dot + label
180void StatusIndicator(const char* label, bool active,
181 const char* tooltip = nullptr);
182
183// Provider badge (AgentUI style)
184void RenderProviderBadge(const char* provider);
185
186// ROM version badge
187void RomVersionBadge(const char* version, bool is_vanilla);
188
189// Locked/Unlocked indicator
190void LockIndicator(bool locked, const char* label);
191
192// ============================================================================
193// Spacing and Alignment
194// ============================================================================
195
196void VerticalSpacing(float pixels = 8.0f);
197void HorizontalSpacing(float pixels = 8.0f);
198void CenterText(const char* text);
199void RightAlign(float width);
200
201// ============================================================================
202// Animation Helpers
203// ============================================================================
204
205// Pulsing alpha animation (for loading indicators, etc.)
206float GetPulseAlpha(float speed = 1.0f);
207
208// Fade-in animation (for panel transitions)
209float GetFadeIn(float duration = 0.3f);
210
211// Apply pulsing effect to next widget
212void PushPulseEffect(float speed = 1.0f);
213void PopPulseEffect();
214
215// Loading spinner (animated circle)
216void LoadingSpinner(const char* label = nullptr, float radius = 10.0f);
217
218// ============================================================================
219// Responsive Layout Helpers
220// ============================================================================
221
222// Get responsive width based on available space
223float GetResponsiveWidth(float min_width, float max_width, float ratio = 0.5f);
224
225// Auto-fit table columns
226void SetupResponsiveColumns(int count, float min_col_width = 100.0f);
227
228// Responsive two-column layout
229void BeginTwoColumns(const char* id, float split_ratio = 0.6f);
230void SwitchColumn();
231void EndTwoColumns();
232
233// ============================================================================
234// Input Helpers (complement existing gui::InputHex functions)
235// ============================================================================
236
237// Labeled hex input with automatic formatting
238bool LabeledInputHex(const char* label, uint8_t* value);
239bool LabeledInputHex(const char* label, uint16_t* value);
240
241// Combo with icon
242bool IconCombo(const char* icon, const char* label, int* current,
243 const char* const items[], int count);
244
245// Helper to create consistent card titles
246std::string MakePanelTitle(const std::string& title);
247
248} // namespace gui
249} // namespace yaze
250
251#endif // YAZE_APP_GUI_UI_HELPERS_H
void RightAlign(float width)
void VerticalSpacing(float pixels)
void EndCanvasContainer()
std::string MakePanelTitle(const std::string &title)
ImVec4 GetVanillaRomColor()
void EndPropertyTable()
void PropertyRow(const char *label, const char *value)
void ColoredText(const char *text, const ImVec4 &color)
ButtonColorSet GetWarningButtonColors()
ButtonColorSet GetDangerButtonColors()
bool ToggleIconButton(const char *icon_on, const char *icon_off, bool *state, const char *tooltip)
ImVec4 GetSuccessColor()
Definition ui_helpers.cc:49
void BeginField(const char *label, float label_width)
void SeparatorText(const char *label)
void EndField()
ImVec4 GetLockedColor()
void StatusIndicator(const char *label, bool active, const char *tooltip)
ImVec4 GetSelectedColor()
Definition ui_helpers.cc:99
void BeginTwoColumns(const char *id, float split_ratio)
void RomVersionBadge(const char *version, bool is_vanilla)
bool EditorTabItem(const char *icon, const char *label, bool *p_open)
ImVec4 GetEntranceColor()
Definition ui_helpers.cc:79
void CenterText(const char *text)
bool LabeledInputHex(const char *label, uint8_t *value)
void SectionHeader(const char *icon, const char *label, const ImVec4 &color)
void LockIndicator(bool locked, const char *label)
bool IconButton(const char *icon, const char *label, const ImVec2 &size)
ImVec4 GetSpriteColor()
Definition ui_helpers.cc:94
void PropertyRowHex(const char *label, uint8_t value)
bool ToggleButton(const char *label, bool active, const ImVec2 &size)
float GetResponsiveWidth(float min_width, float max_width, float ratio)
void SwitchColumn()
void SetupResponsiveColumns(int count, float min_col_width)
ButtonColorSet GetSuccessButtonColors()
bool ColoredButton(const char *label, ButtonType type, const ImVec2 &size)
bool BeginPropertyTable(const char *id, int columns, ImGuiTableFlags extra_flags)
void BeginCanvasContainer(const char *id, bool scrollable)
ImVec4 GetItemColor()
Definition ui_helpers.cc:89
bool IconCombo(const char *icon, const char *label, int *current, const char *const items[], int count)
void LoadingSpinner(const char *label, float radius)
ImVec4 GetDisabledColor()
Definition ui_helpers.cc:74
void ColoredTextF(const ImVec4 &color, const char *fmt,...)
ImVec4 GetErrorColor()
Definition ui_helpers.cc:59
ImVec4 GetWarningColor()
Definition ui_helpers.cc:54
bool ConfirmationDialog(const char *id, const char *title, const char *message, const char *confirm_text, const char *cancel_text)
void EndTwoColumns()
ImVec4 GetModifiedColor()
bool StyledButton(const char *label, const ImVec4 &color, const ImVec2 &size)
void PopPulseEffect()
ImVec4 GetInfoColor()
Definition ui_helpers.cc:64
float GetFadeIn(float duration)
float GetPulseAlpha(float speed)
void PushPulseEffect(float speed)
ImVec4 GetExitColor()
Definition ui_helpers.cc:84
void ThemedSeparator()
void HelpMarker(const char *desc)
Color GetThemeColor(const std::string &color_name)
void RenderProviderBadge(const char *provider)
void StatusBadge(const char *text, ButtonType type)
void ThemedText(const char *text, SemanticColor color)
void HorizontalSpacing(float pixels)
void ThemedTextF(SemanticColor color, const char *fmt,...)
ImVec4 GetAccentColor()
Definition ui_helpers.cc:69
ImVec4 GetCustomRomColor()
ButtonColorSet GetPrimaryButtonColors()
ImVec4 ResolveSemanticColor(SemanticColor color)
Definition ui_helpers.cc:20