feat(editor): reorganize palette editor structure and enhance linking

- Moved palette_editor and palette_group_card files to a dedicated palette directory for better organization.
- Updated CMake configuration to link the new palette editor files and added support for the yaze_agent library when not in minimal build.
- Refactored include paths in various editor files to reflect the new structure, ensuring proper linkage and modularity.

Benefits:
- Improved code organization and maintainability by grouping related files.
- Enhanced functionality with the integration of AI features through the yaze_agent library.
This commit is contained in:
scawful
2025-10-12 08:05:56 -04:00
parent ea9e8d2498
commit 4fe23b9af2
12 changed files with 1809 additions and 119 deletions

View File

@@ -1,14 +1,16 @@
#include "app/gui/themed_widgets.h"
#include "app/gui/color.h"
#include "app/gfx/snes_color.h"
namespace yaze {
namespace gui {
namespace themed {
// ============================================================================
// Buttons
// ============================================================================
bool Button(const char* label, const ImVec2& size) {
bool ThemedButton(const char* label, const ImVec2& size) {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_Button, ConvertColorToImVec4(theme.button));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.button_hovered));
@@ -20,13 +22,13 @@ bool Button(const char* label, const ImVec2& size) {
return result;
}
bool IconButton(const char* icon, const char* tooltip) {
bool result = Button(icon, ImVec2(LayoutHelpers::GetStandardWidgetHeight(),
LayoutHelpers::GetStandardWidgetHeight()));
bool ThemedIconButton(const char* icon, const char* tooltip) {
bool result = ThemedButton(icon, ImVec2(LayoutHelpers::GetStandardWidgetHeight(),
LayoutHelpers::GetStandardWidgetHeight()));
if (tooltip && ImGui::IsItemHovered()) {
BeginTooltip();
BeginThemedTooltip();
ImGui::Text("%s", tooltip);
EndTooltip();
EndThemedTooltip();
}
return result;
}
@@ -67,11 +69,11 @@ bool DangerButton(const char* label, const ImVec2& size) {
// Headers & Sections
// ============================================================================
void Header(const char* label) {
void SectionHeader(const char* label) {
LayoutHelpers::SectionHeader(label);
}
bool CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags) {
bool ThemedCollapsingHeader(const char* label, ImGuiTreeNodeFlags flags) {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_Header, ConvertColorToImVec4(theme.header));
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ConvertColorToImVec4(theme.header_hovered));
@@ -87,13 +89,13 @@ bool CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags) {
// Cards & Panels
// ============================================================================
void Card(const char* label, std::function<void()> content, const ImVec2& size) {
BeginPanel(label, size);
void ThemedCard(const char* label, std::function<void()> content, const ImVec2& size) {
BeginThemedPanel(label, size);
content();
EndPanel();
EndThemedPanel();
}
void BeginPanel(const char* label, const ImVec2& size) {
void BeginThemedPanel(const char* label, const ImVec2& size) {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_ChildBg, ConvertColorToImVec4(theme.surface));
@@ -105,7 +107,7 @@ void BeginPanel(const char* label, const ImVec2& size) {
ImGui::BeginChild(label, size, true);
}
void EndPanel() {
void EndThemedPanel() {
ImGui::EndChild();
ImGui::PopStyleVar(2);
ImGui::PopStyleColor(1);
@@ -115,8 +117,8 @@ void EndPanel() {
// Inputs
// ============================================================================
bool InputText(const char* label, char* buf, size_t buf_size,
ImGuiInputTextFlags flags) {
bool ThemedInputText(const char* label, char* buf, size_t buf_size,
ImGuiInputTextFlags flags) {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
@@ -129,8 +131,8 @@ bool InputText(const char* label, char* buf, size_t buf_size,
return result;
}
bool InputInt(const char* label, int* v, int step, int step_fast,
ImGuiInputTextFlags flags) {
bool ThemedInputInt(const char* label, int* v, int step, int step_fast,
ImGuiInputTextFlags flags) {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
@@ -143,8 +145,8 @@ bool InputInt(const char* label, int* v, int step, int step_fast,
return result;
}
bool InputFloat(const char* label, float* v, float step, float step_fast,
const char* format, ImGuiInputTextFlags flags) {
bool ThemedInputFloat(const char* label, float* v, float step, float step_fast,
const char* format, ImGuiInputTextFlags flags) {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
@@ -157,7 +159,7 @@ bool InputFloat(const char* label, float* v, float step, float step_fast,
return result;
}
bool Checkbox(const char* label, bool* v) {
bool ThemedCheckbox(const char* label, bool* v) {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_CheckMark, ConvertColorToImVec4(theme.check_mark));
@@ -167,8 +169,8 @@ bool Checkbox(const char* label, bool* v) {
return result;
}
bool Combo(const char* label, int* current_item, const char* const items[],
int items_count, int popup_max_height_in_items) {
bool ThemedCombo(const char* label, int* current_item, const char* const items[],
int items_count, int popup_max_height_in_items) {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
@@ -186,12 +188,12 @@ bool Combo(const char* label, int* current_item, const char* const items[],
// Tables
// ============================================================================
bool BeginTable(const char* str_id, int columns, ImGuiTableFlags flags,
const ImVec2& outer_size, float inner_width) {
bool BeginThemedTable(const char* str_id, int columns, ImGuiTableFlags flags,
const ImVec2& outer_size, float inner_width) {
return LayoutHelpers::BeginTableWithTheming(str_id, columns, flags, outer_size, inner_width);
}
void EndTable() {
void EndThemedTable() {
LayoutHelpers::EndTable();
}
@@ -199,17 +201,17 @@ void EndTable() {
// Tooltips & Help
// ============================================================================
void HelpMarker(const char* desc) {
void ThemedHelpMarker(const char* desc) {
LayoutHelpers::HelpMarker(desc);
}
void BeginTooltip() {
void BeginThemedTooltip() {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_PopupBg, ConvertColorToImVec4(theme.popup_bg));
ImGui::BeginTooltip();
}
void EndTooltip() {
void EndThemedTooltip() {
ImGui::EndTooltip();
ImGui::PopStyleColor(1);
}
@@ -218,7 +220,7 @@ void EndTooltip() {
// Status & Feedback
// ============================================================================
void StatusText(const char* text, StatusType type) {
void ThemedStatusText(const char* text, StatusType type) {
const auto& theme = GetTheme();
ImVec4 color;
@@ -240,7 +242,7 @@ void StatusText(const char* text, StatusType type) {
ImGui::TextColored(color, "%s", text);
}
void ProgressBar(float fraction, const ImVec2& size, const char* overlay) {
void ThemedProgressBar(float fraction, const ImVec2& size, const char* overlay) {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ConvertColorToImVec4(theme.accent));
@@ -249,11 +251,117 @@ void ProgressBar(float fraction, const ImVec2& size, const char* overlay) {
ImGui::PopStyleColor(1);
}
// ============================================================================
// Palette Editor Widgets
// ============================================================================
bool PaletteColorButton(const char* label, const yaze::gfx::SnesColor& color,
bool is_selected, bool is_modified,
const ImVec2& size) {
const auto& theme = GetTheme();
int style_count = 0;
// Draw modified indicator with warning border
if (is_modified) {
ImGui::PushStyleColor(ImGuiCol_Border, ConvertColorToImVec4(theme.warning));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f);
style_count++;
}
// Draw selection border (overrides modified if both)
if (is_selected) {
ImGui::PushStyleColor(ImGuiCol_Border, ConvertColorToImVec4(theme.accent));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 3.0f);
if (is_modified) {
ImGui::PopStyleVar(); // Remove modified border style
ImGui::PopStyleColor(); // Remove modified border color
}
style_count = 1; // Override count
}
// Convert SNES color to ImGui format
ImVec4 col = ConvertSnesColorToImVec4(color);
// Draw color button
bool clicked = ImGui::ColorButton(label, col,
ImGuiColorEditFlags_NoAlpha |
ImGuiColorEditFlags_NoPicker |
ImGuiColorEditFlags_NoTooltip,
size);
// Cleanup styles
if (style_count > 0) {
ImGui::PopStyleVar();
ImGui::PopStyleColor();
}
return clicked;
}
void ColorInfoPanel(const yaze::gfx::SnesColor& color,
bool show_snes_format,
bool show_hex_format) {
auto col = color.rgb();
int r = static_cast<int>(col.x);
int g = static_cast<int>(col.y);
int b = static_cast<int>(col.z);
// RGB values
ImGui::Text("RGB (0-255):");
ImGui::SameLine();
ImGui::Text("(%d, %d, %d)", r, g, b);
if (ImGui::IsItemClicked()) {
char buf[64];
snprintf(buf, sizeof(buf), "(%d, %d, %d)", r, g, b);
ImGui::SetClipboardText(buf);
}
// SNES BGR555 value
if (show_snes_format) {
ImGui::Text("SNES BGR555:");
ImGui::SameLine();
ImGui::Text("$%04X", color.snes());
if (ImGui::IsItemClicked()) {
char buf[16];
snprintf(buf, sizeof(buf), "$%04X", color.snes());
ImGui::SetClipboardText(buf);
}
}
// Hex value
if (show_hex_format) {
ImGui::Text("Hex:");
ImGui::SameLine();
ImGui::Text("#%02X%02X%02X", r, g, b);
if (ImGui::IsItemClicked()) {
char buf[16];
snprintf(buf, sizeof(buf), "#%02X%02X%02X", r, g, b);
ImGui::SetClipboardText(buf);
}
}
ImGui::TextDisabled("(Click any value to copy)");
}
void ModifiedBadge(bool is_modified, const char* text) {
if (!is_modified) return;
const auto& theme = GetTheme();
ImVec4 color = ConvertColorToImVec4(theme.warning);
if (text) {
ImGui::TextColored(color, "%s", text);
} else {
ImGui::TextColored(color, "Modified");
}
}
// ============================================================================
// Utility
// ============================================================================
void PushWidgetColors() {
void PushThemedWidgetColors() {
const auto& theme = GetTheme();
ImGui::PushStyleColor(ImGuiCol_FrameBg, ConvertColorToImVec4(theme.frame_bg));
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ConvertColorToImVec4(theme.frame_bg_hovered));
@@ -263,10 +371,9 @@ void PushWidgetColors() {
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.button_active));
}
void PopWidgetColors() {
void PopThemedWidgetColors() {
ImGui::PopStyleColor(6);
}
} // namespace themed
} // namespace gui
} // namespace yaze

View File

@@ -10,27 +10,26 @@ namespace yaze {
namespace gui {
/**
* @brief Opt-in themed widget library for gradual migration
* @brief Theme-aware widget library
*
* All widgets automatically use the current theme from ThemeManager.
* Editors can opt-in by using these widgets instead of raw ImGui calls.
* All widgets in this file automatically use the current theme from ThemeManager.
* These are drop-in replacements for standard ImGui widgets with automatic theming.
*
* Usage:
* ```cpp
* using namespace yaze::gui::themed;
* using namespace yaze::gui;
*
* if (Button("Save")) {
* if (ThemedButton("Save")) {
* // Button uses theme colors automatically
* }
*
* Header("Settings"); // Themed section header
* SectionHeader("Settings"); // Themed section header
*
* Card("Properties", [&]() {
* ThemedCard("Properties", [&]() {
* // Content inside themed card
* });
* ```
*/
namespace themed {
// ============================================================================
// Buttons
@@ -39,12 +38,12 @@ namespace themed {
/**
* @brief Themed button with automatic color application
*/
bool Button(const char* label, const ImVec2& size = ImVec2(0, 0));
bool ThemedButton(const char* label, const ImVec2& size = ImVec2(0, 0));
/**
* @brief Themed button with icon (Material Design Icons)
*/
bool IconButton(const char* icon, const char* tooltip = nullptr);
bool ThemedIconButton(const char* icon, const char* tooltip = nullptr);
/**
* @brief Primary action button (uses accent color)
@@ -63,12 +62,12 @@ bool DangerButton(const char* label, const ImVec2& size = ImVec2(0, 0));
/**
* @brief Themed section header with accent color
*/
void Header(const char* label);
void SectionHeader(const char* label);
/**
* @brief Collapsible section with themed header
*/
bool CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0);
bool ThemedCollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0);
// ============================================================================
// Cards & Panels
@@ -80,18 +79,18 @@ bool CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0);
* @param content Callback function to render card content
* @param size Card size (0, 0 for auto-size)
*/
void Card(const char* label, std::function<void()> content,
const ImVec2& size = ImVec2(0, 0));
void ThemedCard(const char* label, std::function<void()> content,
const ImVec2& size = ImVec2(0, 0));
/**
* @brief Begin themed panel (manual version of Card)
* @brief Begin themed panel (manual version of ThemedCard)
*/
void BeginPanel(const char* label, const ImVec2& size = ImVec2(0, 0));
void BeginThemedPanel(const char* label, const ImVec2& size = ImVec2(0, 0));
/**
* @brief End themed panel
*/
void EndPanel();
void EndThemedPanel();
// ============================================================================
// Inputs
@@ -100,32 +99,32 @@ void EndPanel();
/**
* @brief Themed text input
*/
bool InputText(const char* label, char* buf, size_t buf_size,
ImGuiInputTextFlags flags = 0);
bool ThemedInputText(const char* label, char* buf, size_t buf_size,
ImGuiInputTextFlags flags = 0);
/**
* @brief Themed integer input
*/
bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100,
ImGuiInputTextFlags flags = 0);
bool ThemedInputInt(const char* label, int* v, int step = 1, int step_fast = 100,
ImGuiInputTextFlags flags = 0);
/**
* @brief Themed float input
*/
bool InputFloat(const char* label, float* v, float step = 0.0f,
float step_fast = 0.0f, const char* format = "%.3f",
ImGuiInputTextFlags flags = 0);
bool ThemedInputFloat(const char* label, float* v, float step = 0.0f,
float step_fast = 0.0f, const char* format = "%.3f",
ImGuiInputTextFlags flags = 0);
/**
* @brief Themed checkbox
*/
bool Checkbox(const char* label, bool* v);
bool ThemedCheckbox(const char* label, bool* v);
/**
* @brief Themed combo box
*/
bool Combo(const char* label, int* current_item, const char* const items[],
int items_count, int popup_max_height_in_items = -1);
bool ThemedCombo(const char* label, int* current_item, const char* const items[],
int items_count, int popup_max_height_in_items = -1);
// ============================================================================
// Tables
@@ -134,14 +133,14 @@ bool Combo(const char* label, int* current_item, const char* const items[],
/**
* @brief Begin themed table with automatic styling
*/
bool BeginTable(const char* str_id, int columns, ImGuiTableFlags flags = 0,
const ImVec2& outer_size = ImVec2(0, 0),
float inner_width = 0.0f);
bool BeginThemedTable(const char* str_id, int columns, ImGuiTableFlags flags = 0,
const ImVec2& outer_size = ImVec2(0, 0),
float inner_width = 0.0f);
/**
* @brief End themed table
*/
void EndTable();
void EndThemedTable();
// ============================================================================
// Tooltips & Help
@@ -150,17 +149,17 @@ void EndTable();
/**
* @brief Themed help marker with tooltip
*/
void HelpMarker(const char* desc);
void ThemedHelpMarker(const char* desc);
/**
* @brief Begin themed tooltip
*/
void BeginTooltip();
void BeginThemedTooltip();
/**
* @brief End themed tooltip
*/
void EndTooltip();
void EndThemedTooltip();
// ============================================================================
// Status & Feedback
@@ -170,13 +169,47 @@ enum class StatusType { kSuccess, kWarning, kError, kInfo };
/**
* @brief Themed status text (success, warning, error, info)
*/
void StatusText(const char* text, StatusType type);
void ThemedStatusText(const char* text, StatusType type);
/**
* @brief Themed progress bar
*/
void ProgressBar(float fraction, const ImVec2& size = ImVec2(-1, 0),
const char* overlay = nullptr);
void ThemedProgressBar(float fraction, const ImVec2& size = ImVec2(-1, 0),
const char* overlay = nullptr);
// ============================================================================
// Palette Editor Widgets
// ============================================================================
/**
* @brief Palette color button with modified and selection indicators
* @param label Widget ID
* @param color SNES color to display
* @param is_selected Whether this color is currently selected
* @param is_modified Whether this color has unsaved changes
* @param size Button size (default 24x24)
* @return true if clicked
*/
bool PaletteColorButton(const char* label, const yaze::gfx::SnesColor& color,
bool is_selected, bool is_modified,
const ImVec2& size = ImVec2(24, 24));
/**
* @brief Display color information with copy-to-clipboard functionality
* @param color SNES color to display info for
* @param show_snes_format Show SNES $xxxx format
* @param show_hex_format Show #xxxxxx hex format
*/
void ColorInfoPanel(const yaze::gfx::SnesColor& color,
bool show_snes_format = true,
bool show_hex_format = true);
/**
* @brief Modified indicator badge (displayed as text with icon)
* @param is_modified Whether to show the badge
* @param text Optional text to display after badge
*/
void ModifiedBadge(bool is_modified, const char* text = nullptr);
// ============================================================================
// Utility
@@ -192,14 +225,13 @@ inline const EnhancedTheme& GetTheme() {
/**
* @brief Apply theme colors to next widget
*/
void PushWidgetColors();
void PushThemedWidgetColors();
/**
* @brief Restore previous colors
*/
void PopWidgetColors();
void PopThemedWidgetColors();
} // namespace themed
} // namespace gui
} // namespace yaze