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