yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
themed_widgets.cc
Go to the documentation of this file.
2
5
6namespace yaze {
7namespace gui {
8
9// ============================================================================
10// Buttons
11// ============================================================================
12
13bool ThemedButton(const char* label, const ImVec2& size) {
14 const auto& theme = GetTheme();
15 ImGui::PushStyleColor(ImGuiCol_Button, ConvertColorToImVec4(theme.button));
16 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.button_hovered));
17 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.button_active));
18
19 bool result = ImGui::Button(label, size);
20
21 ImGui::PopStyleColor(3);
22 return result;
23}
24
25bool ThemedIconButton(const char* icon, const char* tooltip) {
26 bool result = ThemedButton(icon, ImVec2(LayoutHelpers::GetStandardWidgetHeight(),
28 if (tooltip && ImGui::IsItemHovered()) {
30 ImGui::Text("%s", tooltip);
32 }
33 return result;
34}
35
36bool PrimaryButton(const char* label, const ImVec2& size) {
37 const auto& theme = GetTheme();
38 ImGui::PushStyleColor(ImGuiCol_Button, ConvertColorToImVec4(theme.accent));
39 ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
40 ImVec4(theme.accent.red * 1.2f, theme.accent.green * 1.2f,
41 theme.accent.blue * 1.2f, theme.accent.alpha));
42 ImGui::PushStyleColor(ImGuiCol_ButtonActive,
43 ImVec4(theme.accent.red * 0.8f, theme.accent.green * 0.8f,
44 theme.accent.blue * 0.8f, theme.accent.alpha));
45
46 bool result = ImGui::Button(label, size);
47
48 ImGui::PopStyleColor(3);
49 return result;
50}
51
52bool DangerButton(const char* label, const ImVec2& size) {
53 const auto& theme = GetTheme();
54 ImGui::PushStyleColor(ImGuiCol_Button, ConvertColorToImVec4(theme.error));
55 ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
56 ImVec4(theme.error.red * 1.2f, theme.error.green * 1.2f,
57 theme.error.blue * 1.2f, theme.error.alpha));
58 ImGui::PushStyleColor(ImGuiCol_ButtonActive,
59 ImVec4(theme.error.red * 0.8f, theme.error.green * 0.8f,
60 theme.error.blue * 0.8f, theme.error.alpha));
61
62 bool result = ImGui::Button(label, size);
63
64 ImGui::PopStyleColor(3);
65 return result;
66}
67
68// ============================================================================
69// Headers & Sections
70// ============================================================================
71
72void SectionHeader(const char* label) {
74}
75
76bool ThemedCollapsingHeader(const char* label, ImGuiTreeNodeFlags flags) {
77 const auto& theme = GetTheme();
78 ImGui::PushStyleColor(ImGuiCol_Header, ConvertColorToImVec4(theme.header));
79 ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ConvertColorToImVec4(theme.header_hovered));
80 ImGui::PushStyleColor(ImGuiCol_HeaderActive, ConvertColorToImVec4(theme.header_active));
81
82 bool result = ImGui::CollapsingHeader(label, flags);
83
84 ImGui::PopStyleColor(3);
85 return result;
86}
87
88// ============================================================================
89// Cards & Panels
90// ============================================================================
91
92void ThemedCard(const char* label, std::function<void()> content, const ImVec2& size) {
93 BeginThemedPanel(label, size);
94 content();
96}
97
98void BeginThemedPanel(const char* label, const ImVec2& size) {
99 const auto& theme = GetTheme();
100
101 ImGui::PushStyleColor(ImGuiCol_ChildBg, ConvertColorToImVec4(theme.surface));
102 ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, theme.window_rounding);
103 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,
106
107 ImGui::BeginChild(label, size, true);
108}
109
111 ImGui::EndChild();
112 ImGui::PopStyleVar(2);
113 ImGui::PopStyleColor(1);
114}
115
116// ============================================================================
117// Inputs
118// ============================================================================
119
120bool ThemedInputText(const char* label, char* buf, size_t buf_size,
121 ImGuiInputTextFlags flags) {
122 const auto& theme = GetTheme();
123 ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
124 ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
125 ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ConvertColorToImVec4(theme.frame_bg_active));
126
127 ImGui::SetNextItemWidth(LayoutHelpers::GetStandardInputWidth());
128 bool result = ImGui::InputText(label, buf, buf_size, flags);
129
130 ImGui::PopStyleColor(3);
131 return result;
132}
133
134bool ThemedInputInt(const char* label, int* v, int step, int step_fast,
135 ImGuiInputTextFlags flags) {
136 const auto& theme = GetTheme();
137 ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
138 ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
139 ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ConvertColorToImVec4(theme.frame_bg_active));
140
141 ImGui::SetNextItemWidth(LayoutHelpers::GetStandardInputWidth());
142 bool result = ImGui::InputInt(label, v, step, step_fast, flags);
143
144 ImGui::PopStyleColor(3);
145 return result;
146}
147
148bool ThemedInputFloat(const char* label, float* v, float step, float step_fast,
149 const char* format, ImGuiInputTextFlags flags) {
150 const auto& theme = GetTheme();
151 ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
152 ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
153 ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ConvertColorToImVec4(theme.frame_bg_active));
154
155 ImGui::SetNextItemWidth(LayoutHelpers::GetStandardInputWidth());
156 bool result = ImGui::InputFloat(label, v, step, step_fast, format, flags);
157
158 ImGui::PopStyleColor(3);
159 return result;
160}
161
162bool ThemedCheckbox(const char* label, bool* v) {
163 const auto& theme = GetTheme();
164 ImGui::PushStyleColor(ImGuiCol_CheckMark, ConvertColorToImVec4(theme.check_mark));
165
166 bool result = ImGui::Checkbox(label, v);
167
168 ImGui::PopStyleColor(1);
169 return result;
170}
171
172bool ThemedCombo(const char* label, int* current_item, const char* const items[],
173 int items_count, int popup_max_height_in_items) {
174 const auto& theme = GetTheme();
175 ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
176 ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
177 ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ConvertColorToImVec4(theme.frame_bg_active));
178
179 ImGui::SetNextItemWidth(LayoutHelpers::GetStandardInputWidth());
180 bool result = ImGui::Combo(label, current_item, items, items_count,
181 popup_max_height_in_items);
182
183 ImGui::PopStyleColor(3);
184 return result;
185}
186
187// ============================================================================
188// Tables
189// ============================================================================
190
191bool BeginThemedTable(const char* str_id, int columns, ImGuiTableFlags flags,
192 const ImVec2& outer_size, float inner_width) {
193 return LayoutHelpers::BeginTableWithTheming(str_id, columns, flags, outer_size, inner_width);
194}
195
199
200// ============================================================================
201// Tooltips & Help
202// ============================================================================
203
204void ThemedHelpMarker(const char* desc) {
206}
207
209 const auto& theme = GetTheme();
210 ImGui::PushStyleColor(ImGuiCol_PopupBg, ConvertColorToImVec4(theme.popup_bg));
211 ImGui::BeginTooltip();
212}
213
215 ImGui::EndTooltip();
216 ImGui::PopStyleColor(1);
217}
218
219// ============================================================================
220// Status & Feedback
221// ============================================================================
222
223void ThemedStatusText(const char* text, StatusType type) {
224 const auto& theme = GetTheme();
225 ImVec4 color;
226
227 switch (type) {
229 color = ConvertColorToImVec4(theme.success);
230 break;
232 color = ConvertColorToImVec4(theme.warning);
233 break;
235 color = ConvertColorToImVec4(theme.error);
236 break;
238 color = ConvertColorToImVec4(theme.info);
239 break;
240 }
241
242 ImGui::TextColored(color, "%s", text);
243}
244
245void ThemedProgressBar(float fraction, const ImVec2& size, const char* overlay) {
246 const auto& theme = GetTheme();
247 ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ConvertColorToImVec4(theme.accent));
248
249 ImGui::ProgressBar(fraction, size, overlay);
250
251 ImGui::PopStyleColor(1);
252}
253
254// ============================================================================
255// Palette Editor Widgets
256// ============================================================================
257// NOTE: PaletteColorButton moved to color.cc
258
260 bool show_snes_format,
261 bool show_hex_format) {
262 auto col = color.rgb();
263 int r = static_cast<int>(col.x);
264 int g = static_cast<int>(col.y);
265 int b = static_cast<int>(col.z);
266
267 // RGB values
268 ImGui::Text("RGB (0-255):");
269 ImGui::SameLine();
270 ImGui::Text("(%d, %d, %d)", r, g, b);
271 if (ImGui::IsItemClicked()) {
272 char buf[64];
273 snprintf(buf, sizeof(buf), "(%d, %d, %d)", r, g, b);
274 ImGui::SetClipboardText(buf);
275 }
276
277 // SNES BGR555 value
278 if (show_snes_format) {
279 ImGui::Text("SNES BGR555:");
280 ImGui::SameLine();
281 ImGui::Text("$%04X", color.snes());
282 if (ImGui::IsItemClicked()) {
283 char buf[16];
284 snprintf(buf, sizeof(buf), "$%04X", color.snes());
285 ImGui::SetClipboardText(buf);
286 }
287 }
288
289 // Hex value
290 if (show_hex_format) {
291 ImGui::Text("Hex:");
292 ImGui::SameLine();
293 ImGui::Text("#%02X%02X%02X", r, g, b);
294 if (ImGui::IsItemClicked()) {
295 char buf[16];
296 snprintf(buf, sizeof(buf), "#%02X%02X%02X", r, g, b);
297 ImGui::SetClipboardText(buf);
298 }
299 }
300
301 ImGui::TextDisabled("(Click any value to copy)");
302}
303
304void ModifiedBadge(bool is_modified, const char* text) {
305 if (!is_modified) return;
306
307 const auto& theme = GetTheme();
308 ImVec4 color = ConvertColorToImVec4(theme.warning);
309
310 if (text) {
311 ImGui::TextColored(color, "%s", text);
312 } else {
313 ImGui::TextColored(color, "Modified");
314 }
315}
316
317// ============================================================================
318// Utility
319// ============================================================================
320
322 const auto& theme = GetTheme();
323 ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
324 ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
325 ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ConvertColorToImVec4(theme.frame_bg_active));
326 ImGui::PushStyleColor(ImGuiCol_Button, ConvertColorToImVec4(theme.button));
327 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.button_hovered));
328 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.button_active));
329}
330
332 ImGui::PopStyleColor(6);
333}
334
335} // namespace gui
336} // namespace yaze
SNES Color container.
Definition snes_color.h:109
constexpr ImVec4 rgb() const
Get RGB values (WARNING: stored as 0-255 in ImVec4)
Definition snes_color.h:182
constexpr uint16_t snes() const
Get SNES 15-bit color.
Definition snes_color.h:192
static void SectionHeader(const char *label)
static float GetPanelPadding()
static void HelpMarker(const char *desc)
static float GetStandardInputWidth()
static float GetStandardWidgetHeight()
static bool BeginTableWithTheming(const char *str_id, int columns, ImGuiTableFlags flags=0, const ImVec2 &outer_size=ImVec2(0, 0), float inner_width=0.0f)
void ThemedHelpMarker(const char *desc)
Themed help marker with tooltip.
bool ThemedCheckbox(const char *label, bool *v)
Themed checkbox.
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:21
bool ThemedButton(const char *label, const ImVec2 &size)
Theme-aware widget library.
void ThemedCard(const char *label, std::function< void()> content, const ImVec2 &size)
Themed card with rounded corners and shadow.
void ColorInfoPanel(const yaze::gfx::SnesColor &color, bool show_snes_format, bool show_hex_format)
Display color information with copy-to-clipboard functionality.
void BeginThemedPanel(const char *label, const ImVec2 &size)
Begin themed panel (manual version of ThemedCard)
void ModifiedBadge(bool is_modified, const char *text)
Modified indicator badge (displayed as text with icon)
bool BeginThemedTable(const char *str_id, int columns, ImGuiTableFlags flags, const ImVec2 &outer_size, float inner_width)
Begin themed table with automatic styling.
bool ThemedInputFloat(const char *label, float *v, float step, float step_fast, const char *format, ImGuiInputTextFlags flags)
Themed float input.
void ThemedStatusText(const char *text, StatusType type)
Themed status text (success, warning, error, info)
bool DangerButton(const char *label, const ImVec2 &size)
Danger/destructive action button (uses error color)
const EnhancedTheme & GetTheme()
Get current theme (shortcut)
void BeginThemedTooltip()
Begin themed tooltip.
void SectionHeader(const char *icon, const char *label, const ImVec4 &color)
void EndThemedTooltip()
End themed tooltip.
void PushThemedWidgetColors()
Apply theme colors to next widget.
bool PrimaryButton(const char *label, const ImVec2 &size)
Primary action button (uses accent color)
void PopThemedWidgetColors()
Restore previous colors.
bool ThemedCombo(const char *label, int *current_item, const char *const items[], int items_count, int popup_max_height_in_items)
Themed combo box.
bool ThemedInputText(const char *label, char *buf, size_t buf_size, ImGuiInputTextFlags flags)
Themed text input.
void EndThemedPanel()
End themed panel.
void ThemedProgressBar(float fraction, const ImVec2 &size, const char *overlay)
Themed progress bar.
void EndThemedTable()
End themed table.
bool ThemedCollapsingHeader(const char *label, ImGuiTreeNodeFlags flags)
Collapsible section with themed header.
bool ThemedIconButton(const char *icon, const char *tooltip)
Themed button with icon (Material Design Icons)
bool ThemedInputInt(const char *label, int *v, int step, int step_fast, ImGuiInputTextFlags flags)
Themed integer input.
Main namespace for the application.
Definition controller.cc:20