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#include "app/gfx/types/snes_color.h" // For SnesColor
6
7namespace yaze {
8namespace gui {
9
10bool ThemedIconButton(const char* icon, const char* tooltip,
11 const ImVec2& size, bool is_active,
12 bool is_disabled) {
13 const auto& theme = ThemeManager::Get().GetCurrentTheme();
14
15 ImVec4 bg_color = is_active ? ConvertColorToImVec4(theme.button_active)
16 : ConvertColorToImVec4(theme.button);
17 ImVec4 text_color = is_disabled ? ConvertColorToImVec4(theme.text_disabled)
18 : (is_active ? ConvertColorToImVec4(theme.text_primary)
19 : ConvertColorToImVec4(theme.text_secondary));
20
21 ImGui::PushStyleColor(ImGuiCol_Button, bg_color);
22 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.button_hovered));
23 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.button_active));
24 ImGui::PushStyleColor(ImGuiCol_Text, text_color);
25
26 bool clicked = ImGui::Button(icon, size);
27
28 ImGui::PopStyleColor(4);
29
30 if (tooltip && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
31 ImGui::SetTooltip("%s", tooltip);
32 }
33
34 return clicked;
35}
36
37bool TransparentIconButton(const char* icon, const ImVec2& size,
38 const char* tooltip, bool is_active,
39 const ImVec4& active_color) {
40 const auto& theme = ThemeManager::Get().GetCurrentTheme();
41
42 // Transparent background
43 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
44 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.header_hovered));
45 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.header_active));
46
47 // Text color based on state
48 // If active and custom color provided (alpha > 0), use that; otherwise use theme.primary
49 ImVec4 text_color;
50 if (is_active) {
51 if (active_color.w > 0.0f) {
52 text_color = active_color; // Use category-specific color
53 } else {
54 text_color = ConvertColorToImVec4(theme.primary); // Default to theme primary
55 }
56 } else {
57 text_color = ConvertColorToImVec4(theme.text_secondary);
58 }
59 ImGui::PushStyleColor(ImGuiCol_Text, text_color);
60
61 bool clicked = ImGui::Button(icon, size);
62
63 ImGui::PopStyleColor(4);
64
65 if (tooltip && ImGui::IsItemHovered()) {
66 ImGui::SetTooltip("%s", tooltip);
67 }
68
69 return clicked;
70}
71
72bool ThemedButton(const char* label, const ImVec2& size) {
73 // Standard button uses ImGui style colors which are already set by ThemeManager::ApplyTheme
74 return ImGui::Button(label, size);
75}
76
77bool PrimaryButton(const char* label, const ImVec2& size) {
78 const auto& theme = ThemeManager::Get().GetCurrentTheme();
79
80 ImGui::PushStyleColor(ImGuiCol_Button, ConvertColorToImVec4(theme.primary));
81 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.button_hovered)); // Should ideally be a lighter primary
82 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.button_active));
83 ImGui::PushStyleColor(ImGuiCol_Text, ConvertColorToImVec4(theme.text_primary)); // OnPrimary
84
85 bool clicked = ImGui::Button(label, size);
86
87 ImGui::PopStyleColor(4);
88 return clicked;
89}
90
91bool DangerButton(const char* label, const ImVec2& size) {
92 const auto& theme = ThemeManager::Get().GetCurrentTheme();
93
94 ImGui::PushStyleColor(ImGuiCol_Button, ConvertColorToImVec4(theme.error));
95 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.button_hovered));
96 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.button_active));
97 ImGui::PushStyleColor(ImGuiCol_Text, ConvertColorToImVec4(theme.text_primary));
98
99 bool clicked = ImGui::Button(label, size);
100
101 ImGui::PopStyleColor(4);
102 return clicked;
103}
104
105void SectionHeader(const char* label) {
106 const auto& theme = ThemeManager::Get().GetCurrentTheme();
107 ImGui::PushStyleColor(ImGuiCol_Text, ConvertColorToImVec4(theme.primary));
108 ImGui::Text("%s", label);
109 ImGui::PopStyleColor();
110 ImGui::Separator();
111}
112
113// Stub for PaletteColorButton since it requires SnesColor which might need more includes
114// For now, we assume it was defined elsewhere or we need to implement it if we overwrote it.
115// Based on palette_group_card.cc usage, it seems it was expected.
116// I'll implement a basic version.
117bool PaletteColorButton(const char* id, const gfx::SnesColor& color,
118 bool is_selected, bool is_modified,
119 const ImVec2& size) {
120 ImVec4 col = ConvertSnesColorToImVec4(color);
121 bool clicked = ImGui::ColorButton(id, col, ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker, size);
122
123 if (is_selected) {
124 ImGui::GetWindowDrawList()->AddRect(
125 ImGui::GetItemRectMin(), ImGui::GetItemRectMax(),
126 IM_COL32(255, 255, 255, 255), 0.0f, 0, 2.0f);
127 }
128 if (is_modified) {
129 // Draw a small dot or indicator
130 }
131 return clicked;
132}
133
134void PanelHeader(const char* title, const char* icon, bool* p_open) {
135 const auto& theme = ThemeManager::Get().GetCurrentTheme();
136 const float header_height = 44.0f;
137 const float padding = 12.0f;
138
139 // Header background
140 ImVec2 header_min = ImGui::GetCursorScreenPos();
141 ImVec2 header_max = ImVec2(header_min.x + ImGui::GetWindowWidth(),
142 header_min.y + header_height);
143
144 ImDrawList* draw_list = ImGui::GetWindowDrawList();
145 draw_list->AddRectFilled(header_min, header_max,
146 ImGui::GetColorU32(ConvertColorToImVec4(theme.header)));
147
148 // Bottom border
149 draw_list->AddLine(ImVec2(header_min.x, header_max.y),
150 ImVec2(header_max.x, header_max.y),
151 ImGui::GetColorU32(ConvertColorToImVec4(theme.border)), 1.0f);
152
153 // Content positioning
154 ImGui::SetCursorPosX(padding);
155 ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (header_height - ImGui::GetTextLineHeight()) * 0.5f);
156
157 // Icon
158 if (icon) {
159 ImGui::PushStyleColor(ImGuiCol_Text, ConvertColorToImVec4(theme.primary));
160 ImGui::Text("%s", icon);
161 ImGui::PopStyleColor();
162 ImGui::SameLine();
163 }
164
165 // Title
166 ImGui::PushStyleColor(ImGuiCol_Text, ConvertColorToImVec4(theme.text_primary));
167 ImGui::Text("%s", title);
168 ImGui::PopStyleColor();
169
170 // Close button
171 if (p_open) {
172 const float button_size = 28.0f;
173 ImGui::SameLine(ImGui::GetWindowWidth() - button_size - padding);
174 ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 4.0f);
175
176 if (TransparentIconButton(ICON_MD_CLOSE, ImVec2(button_size, button_size), "Close")) {
177 *p_open = false;
178 }
179 }
180
181 // Move cursor past header
182 ImGui::SetCursorPosY(header_height + 8.0f);
183}
184
185} // namespace gui
186} // namespace yaze
SNES Color container.
Definition snes_color.h:110
const Theme & GetCurrentTheme() const
static ThemeManager & Get()
#define ICON_MD_CLOSE
Definition icons.h:418
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:23
bool ThemedButton(const char *label, const ImVec2 &size)
Draw a standard text button with theme colors.
bool TransparentIconButton(const char *icon, const ImVec2 &size, const char *tooltip, bool is_active, const ImVec4 &active_color)
Draw a transparent icon button (hover effect only).
void PanelHeader(const char *title, const char *icon, bool *p_open)
Draw a panel header with consistent styling.
bool DangerButton(const char *label, const ImVec2 &size)
Draw a danger action button (error color).
void SectionHeader(const char *icon, const char *label, const ImVec4 &color)
bool ThemedIconButton(const char *icon, const char *tooltip, const ImVec2 &size, bool is_active, bool is_disabled)
Draw a standard icon button with theme-aware colors.
IMGUI_API bool PaletteColorButton(const char *id, const gfx::SnesColor &color, bool is_selected, bool is_modified, const ImVec2 &size, ImGuiColorEditFlags flags)
Definition color.cc:449
ImVec4 ConvertSnesColorToImVec4(const gfx::SnesColor &color)
Convert SnesColor to standard ImVec4 for display.
Definition color.cc:19
bool PrimaryButton(const char *label, const ImVec2 &size)
Draw a primary action button (accented color).