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 "imgui/imgui.h"
5#include <string>
6#include <functional>
7
8namespace yaze {
9namespace gui {
10
11// A collection of helper functions and widgets to standardize UI development
12// and reduce boilerplate ImGui code across all editors.
13
14// ============================================================================
15// Theme and Semantic Colors
16// ============================================================================
17
18// Gets a color from the current theme
19ImVec4 GetThemeColor(ImGuiCol idx);
20
21// Semantic colors from current theme
22ImVec4 GetSuccessColor();
23ImVec4 GetWarningColor();
24ImVec4 GetErrorColor();
25ImVec4 GetInfoColor();
26ImVec4 GetAccentColor();
27
28// Entity/Map marker colors (for overworld, dungeon)
29ImVec4 GetEntranceColor();
30ImVec4 GetExitColor();
31ImVec4 GetItemColor();
32ImVec4 GetSpriteColor();
33ImVec4 GetSelectedColor();
34ImVec4 GetLockedColor();
35
36// Status colors
37ImVec4 GetVanillaRomColor();
38ImVec4 GetCustomRomColor();
39ImVec4 GetModifiedColor();
40
41// ============================================================================
42// Layout Helpers
43// ============================================================================
44
45// Label + widget field pattern
46void BeginField(const char* label, float label_width = 0.0f);
47void EndField();
48
49// Property table pattern (common in editors)
50bool BeginPropertyTable(const char* id, int columns = 2,
51 ImGuiTableFlags extra_flags = 0);
52void EndPropertyTable();
53
54// Property row helpers
55void PropertyRow(const char* label, const char* value);
56void PropertyRow(const char* label, int value);
57void PropertyRowHex(const char* label, uint8_t value);
58void PropertyRowHex(const char* label, uint16_t value);
59
60// Section headers with icons
61void SectionHeader(const char* icon, const char* label,
62 const ImVec4& color = ImVec4(1, 1, 1, 1));
63
64// ============================================================================
65// Common Widget Patterns
66// ============================================================================
67
68// Button with icon
69bool IconButton(const char* icon, const char* label,
70 const ImVec2& size = ImVec2(0, 0));
71
72// Colored button for status actions
74bool ColoredButton(const char* label, ButtonType type,
75 const ImVec2& size = ImVec2(0, 0));
76
77// Toggle button with visual state
78bool ToggleIconButton(const char* icon_on, const char* icon_off,
79 bool* state, const char* tooltip = nullptr);
80
81// Help marker with tooltip
82void HelpMarker(const char* desc);
83
84// Separator with text
85void SeparatorText(const char* label);
86
87// Status badge (pill-shaped colored label)
88void StatusBadge(const char* text, ButtonType type = ButtonType::Default);
89
90// ============================================================================
91// Editor-Specific Patterns
92// ============================================================================
93
94// Toolset table (horizontal button bar)
95void BeginToolset(const char* id);
96void EndToolset();
97void ToolsetButton(const char* icon, bool selected, const char* tooltip,
98 std::function<void()> on_click);
99
100// Canvas container patterns
101void BeginCanvasContainer(const char* id, bool scrollable = true);
102void EndCanvasContainer();
103
104// Tab pattern for editor modes
105bool EditorTabItem(const char* icon, const char* label, bool* p_open = nullptr);
106
107// Modal confirmation dialog
108bool ConfirmationDialog(const char* id, const char* title, const char* message,
109 const char* confirm_text = "OK",
110 const char* cancel_text = "Cancel");
111
112// ============================================================================
113// Visual Indicators
114// ============================================================================
115
116// Status indicator dot + label
117void StatusIndicator(const char* label, bool active,
118 const char* tooltip = nullptr);
119
120// ROM version badge
121void RomVersionBadge(const char* version, bool is_vanilla);
122
123// Locked/Unlocked indicator
124void LockIndicator(bool locked, const char* label);
125
126// ============================================================================
127// Spacing and Alignment
128// ============================================================================
129
130void VerticalSpacing(float pixels = 8.0f);
131void HorizontalSpacing(float pixels = 8.0f);
132void CenterText(const char* text);
133void RightAlign(float width);
134
135// ============================================================================
136// Animation Helpers
137// ============================================================================
138
139// Pulsing alpha animation (for loading indicators, etc.)
140float GetPulseAlpha(float speed = 1.0f);
141
142// Fade-in animation (for panel transitions)
143float GetFadeIn(float duration = 0.3f);
144
145// Apply pulsing effect to next widget
146void PushPulseEffect(float speed = 1.0f);
147void PopPulseEffect();
148
149// Loading spinner (animated circle)
150void LoadingSpinner(const char* label = nullptr, float radius = 10.0f);
151
152// ============================================================================
153// Responsive Layout Helpers
154// ============================================================================
155
156// Get responsive width based on available space
157float GetResponsiveWidth(float min_width, float max_width, float ratio = 0.5f);
158
159// Auto-fit table columns
160void SetupResponsiveColumns(int count, float min_col_width = 100.0f);
161
162// Responsive two-column layout
163void BeginTwoColumns(const char* id, float split_ratio = 0.6f);
164void SwitchColumn();
165void EndTwoColumns();
166
167// ============================================================================
168// Input Helpers (complement existing gui::InputHex functions)
169// ============================================================================
170
171// Labeled hex input with automatic formatting
172bool LabeledInputHex(const char* label, uint8_t* value);
173bool LabeledInputHex(const char* label, uint16_t* value);
174
175// Combo with icon
176bool IconCombo(const char* icon, const char* label, int* current,
177 const char* const items[], int count);
178
179} // namespace gui
180} // namespace yaze
181
182#endif // YAZE_APP_GUI_UI_HELPERS_H
void RightAlign(float width)
void VerticalSpacing(float pixels)
void EndCanvasContainer()
void BeginToolset(const char *id)
ImVec4 GetVanillaRomColor()
Definition ui_helpers.cc:76
void EndPropertyTable()
void PropertyRow(const char *label, const char *value)
bool ToggleIconButton(const char *icon_on, const char *icon_off, bool *state, const char *tooltip)
ImVec4 GetSuccessColor()
Definition ui_helpers.cc:20
void BeginField(const char *label, float label_width)
Definition ui_helpers.cc:93
void SeparatorText(const char *label)
void EndField()
ImVec4 GetLockedColor()
Definition ui_helpers.cc:71
void StatusIndicator(const char *label, bool active, const char *tooltip)
ImVec4 GetSelectedColor()
Definition ui_helpers.cc:66
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:46
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:61
void PropertyRowHex(const char *label, uint8_t value)
float GetResponsiveWidth(float min_width, float max_width, float ratio)
void SwitchColumn()
void SetupResponsiveColumns(int count, float min_col_width)
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:56
bool IconCombo(const char *icon, const char *label, int *current, const char *const items[], int count)
void LoadingSpinner(const char *label, float radius)
ImVec4 GetThemeColor(ImGuiCol idx)
Definition ui_helpers.cc:16
ImVec4 GetErrorColor()
Definition ui_helpers.cc:30
void ToolsetButton(const char *icon, bool selected, const char *tooltip, std::function< void()> on_click)
ImVec4 GetWarningColor()
Definition ui_helpers.cc:25
bool ConfirmationDialog(const char *id, const char *title, const char *message, const char *confirm_text, const char *cancel_text)
void EndTwoColumns()
ImVec4 GetModifiedColor()
Definition ui_helpers.cc:84
void PopPulseEffect()
ImVec4 GetInfoColor()
Definition ui_helpers.cc:35
float GetFadeIn(float duration)
float GetPulseAlpha(float speed)
void PushPulseEffect(float speed)
ImVec4 GetExitColor()
Definition ui_helpers.cc:51
void HelpMarker(const char *desc)
void StatusBadge(const char *text, ButtonType type)
void HorizontalSpacing(float pixels)
ImVec4 GetAccentColor()
Definition ui_helpers.cc:40
ImVec4 GetCustomRomColor()
Definition ui_helpers.cc:80
Main namespace for the application.