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, ...)
69 IM_FMTARGS(2);
70
71// Render text with a SemanticColor from the current theme.
72void ThemedText(const char* text, SemanticColor color);
73
74// Render formatted text with a SemanticColor from the current theme.
75void ThemedTextF(SemanticColor color, const char* fmt, ...)
76 IM_FMTARGS(2);
77
78// ============================================================================
79// Button Color Sets
80// ============================================================================
81
82// Pre-computed 3-color set for styled buttons (button, hovered, active).
84 ImVec4 button;
85 ImVec4 hovered;
86 ImVec4 active;
87};
88
93
94// ============================================================================
95// Themed Separator
96// ============================================================================
97
98// Draw a separator using the theme's separator/border color.
99void ThemedSeparator();
100
101// ============================================================================
102// Layout Helpers
103// ============================================================================
104
105// Label + widget field pattern
106void BeginField(const char* label, float label_width = 0.0f);
107void EndField();
108
109// Property table pattern (common in editors)
110bool BeginPropertyTable(const char* id, int columns = 2,
111 ImGuiTableFlags extra_flags = 0);
112void EndPropertyTable();
113
114// Property row helpers
115void PropertyRow(const char* label, const char* value);
116void PropertyRow(const char* label, int value);
117void PropertyRowHex(const char* label, uint8_t value);
118void PropertyRowHex(const char* label, uint16_t value);
119
120// Section headers with icons
121void SectionHeader(const char* icon, const char* label,
122 const ImVec4& color = ImVec4(1, 1, 1, 1));
123
124// ============================================================================
125// Common Widget Patterns
126// ============================================================================
127
128// Button with icon
129bool IconButton(const char* icon, const char* label,
130 const ImVec2& size = ImVec2(0, 0));
131
132// Icon-only button (AgentUI style)
133bool IconButton(const char* icon, const char* tooltip = nullptr);
134
135// Colored button for status actions
137bool ColoredButton(const char* label, ButtonType type,
138 const ImVec2& size = ImVec2(0, 0));
139
140// Styled button with custom color (AgentUI style)
141bool StyledButton(const char* label, const ImVec4& color,
142 const ImVec2& size = ImVec2(0, 0));
143
144// Toggle button with visual state
145bool ToggleIconButton(const char* icon_on, const char* icon_off, bool* state,
146 const char* tooltip = nullptr);
147
148// Toggle button that looks like a regular button but stays pressed
149bool ToggleButton(const char* label, bool active,
150 const ImVec2& size = ImVec2(0, 0));
151
152// Help marker with tooltip
153void HelpMarker(const char* desc);
154
155// Separator with text
156void SeparatorText(const char* label);
157
158// Status badge (pill-shaped colored label)
159void StatusBadge(const char* text, ButtonType type = ButtonType::Default);
160
161// ============================================================================
162// Editor-Specific Patterns
163// ============================================================================
164
165// Toolset table (horizontal button bar)
166void BeginToolset(const char* id);
167void EndToolset();
168void ToolsetButton(const char* icon, bool selected, const char* tooltip,
169 std::function<void()> on_click);
170
171// Canvas container patterns
172void BeginCanvasContainer(const char* id, bool scrollable = true);
173void EndCanvasContainer();
174
175// Tab pattern for editor modes
176bool EditorTabItem(const char* icon, const char* label, bool* p_open = nullptr);
177
178// Modal confirmation dialog
179bool ConfirmationDialog(const char* id, const char* title, const char* message,
180 const char* confirm_text = "OK",
181 const char* cancel_text = "Cancel");
182
183// ============================================================================
184// Visual Indicators
185// ============================================================================
186
187// Status indicator dot + label
188void StatusIndicator(const char* label, bool active,
189 const char* tooltip = nullptr);
190
191// Provider badge (AgentUI style)
192void RenderProviderBadge(const char* provider);
193
194// ROM version badge
195void RomVersionBadge(const char* version, bool is_vanilla);
196
197// Locked/Unlocked indicator
198void LockIndicator(bool locked, const char* label);
199
200// ============================================================================
201// Spacing and Alignment
202// ============================================================================
203
204void VerticalSpacing(float pixels = 8.0f);
205void HorizontalSpacing(float pixels = 8.0f);
206void CenterText(const char* text);
207void RightAlign(float width);
208
209// ============================================================================
210// Animation Helpers
211// ============================================================================
212
213// Pulsing alpha animation (for loading indicators, etc.)
214float GetPulseAlpha(float speed = 1.0f);
215
216// Fade-in animation (for panel transitions)
217float GetFadeIn(float duration = 0.3f);
218
219// Apply pulsing effect to next widget
220void PushPulseEffect(float speed = 1.0f);
221void PopPulseEffect();
222
223// Loading spinner (animated circle)
224void LoadingSpinner(const char* label = nullptr, float radius = 10.0f);
225
226// ============================================================================
227// Responsive Layout Helpers
228// ============================================================================
229
230// Get responsive width based on available space
231float GetResponsiveWidth(float min_width, float max_width, float ratio = 0.5f);
232
233// Auto-fit table columns
234void SetupResponsiveColumns(int count, float min_col_width = 100.0f);
235
236// Responsive two-column layout
237void BeginTwoColumns(const char* id, float split_ratio = 0.6f);
238void SwitchColumn();
239void EndTwoColumns();
240
241// ============================================================================
242// Input Helpers (complement existing gui::InputHex functions)
243// ============================================================================
244
245// Labeled hex input with automatic formatting
246bool LabeledInputHex(const char* label, uint8_t* value);
247bool LabeledInputHex(const char* label, uint16_t* value);
248
249// Combo with icon
250bool IconCombo(const char* icon, const char* label, int* current,
251 const char* const items[], int count);
252
253// Helper to create consistent card titles
254std::string MakePanelTitle(const std::string& title);
255
256} // namespace gui
257} // namespace yaze
258
259#endif // YAZE_APP_GUI_UI_HELPERS_H
void RightAlign(float width)
void VerticalSpacing(float pixels)
void EndCanvasContainer()
void BeginToolset(const char *id)
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:48
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:98
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:78
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)
void EndToolset()
ImVec4 GetSpriteColor()
Definition ui_helpers.cc:93
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:88
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:73
void ColoredTextF(const ImVec4 &color, const char *fmt,...)
ImVec4 GetErrorColor()
Definition ui_helpers.cc:58
void ToolsetButton(const char *icon, bool selected, const char *tooltip, std::function< void()> on_click)
ImVec4 GetWarningColor()
Definition ui_helpers.cc:53
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:63
float GetFadeIn(float duration)
float GetPulseAlpha(float speed)
void PushPulseEffect(float speed)
ImVec4 GetExitColor()
Definition ui_helpers.cc:83
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:68
ImVec4 GetCustomRomColor()
ButtonColorSet GetPrimaryButtonColors()
ImVec4 ResolveSemanticColor(SemanticColor color)
Definition ui_helpers.cc:19