From b08ba4d7540824a1fef17f26f8442dab7cceced3 Mon Sep 17 00:00:00 2001 From: Daniel Dada Date: Wed, 17 Dec 2025 15:49:48 +0300 Subject: [PATCH] fix: coloring --- example_config/config.toml | 2 +- example_config/palettes/dark.toml | 54 +++++++++++++++++++ example_config/palettes/light.toml | 54 +++++++++++++++++++ .../palletes}/cursed-light.toml | 0 .../palettes => extra/palletes}/cursed.toml | 0 .../palettes => extra/palletes}/nord.toml | 0 src/gui/color_table_renderer.cpp | 3 +- src/gui/preview_renderer.cpp | 4 +- src/gui/settings_window.cpp | 36 ++++++++++--- src/gui/template_editor.cpp | 32 ++++++----- src/gui/theme_applier.cpp | 19 +++++-- 11 files changed, 178 insertions(+), 26 deletions(-) create mode 100644 example_config/palettes/dark.toml create mode 100644 example_config/palettes/light.toml rename {example_config/palettes => extra/palletes}/cursed-light.toml (100%) rename {example_config/palettes => extra/palletes}/cursed.toml (100%) rename {example_config/palettes => extra/palletes}/nord.toml (100%) diff --git a/example_config/config.toml b/example_config/config.toml index 329e538..c50937c 100644 --- a/example_config/config.toml +++ b/example_config/config.toml @@ -1,5 +1,5 @@ [general] -default_theme = 'cursed' +default_theme = 'dark' palettes_path = '~/.config/clrsync/palettes' font = 'JetBrainsMono Nerd Font Mono' font_size = 14 diff --git a/example_config/palettes/dark.toml b/example_config/palettes/dark.toml new file mode 100644 index 0000000..baf452e --- /dev/null +++ b/example_config/palettes/dark.toml @@ -0,0 +1,54 @@ +[colors] +accent = '#9A8652FF' +background = '#111111FF' +base00 = '#111111FF' +base01 = '#668A51FF' +base02 = '#9A8652FF' +base03 = '#B47837FF' +base04 = '#9A5552FF' +base05 = '#AA477BFF' +base06 = '#3A898CFF' +base07 = '#B5B5B5FF' +base08 = '#AA4E4AFF' +base09 = '#A9DC86FF' +base0A = '#B6AB82FF' +base0B = '#C5916BFF' +base0C = '#AC7676FF' +base0D = '#B0779EFF' +base0E = '#849899FF' +base0F = '#D2D2D2FF' +border = '#242424FF' +border_focused = '#2E2E2EFF' +cursor = '#D2D2D2FF' +editor_background = '#111111FF' +editor_command = '#3A898CFF' +editor_comment = '#849899FF' +editor_disabled = '#849899FF' +editor_emphasis = '#A9DC86FF' +editor_error = '#AA4E4AFF' +editor_inactive = '#849899FF' +editor_line_number = '#849899FF' +editor_link = '#B0779EFF' +editor_main = '#D2D2D2FF' +editor_selected = '#242424FF' +editor_selection_inactive = '#1D1C1CFF' +editor_string = '#9A8652FF' +editor_success = '#668A51FF' +editor_warning = '#B47837FF' +error = '#AA4E4AFF' +foreground = '#D2D2D2FF' +info = '#3A898CFF' +on_background = '#D4D4D4FF' +on_error = '#D2D2D2FF' +on_info = '#D2D2D2FF' +on_success = '#D2D2D2FF' +on_surface = '#D4D4D4FF' +on_surface_variant = '#D4D4D4FF' +on_warning = '#D2D2D2FF' +success = '#668A51FF' +surface = '#111111FF' +surface_variant = '#191919FF' +warning = '#B47837FF' + +[general] +name = 'dark' \ No newline at end of file diff --git a/example_config/palettes/light.toml b/example_config/palettes/light.toml new file mode 100644 index 0000000..f3de92b --- /dev/null +++ b/example_config/palettes/light.toml @@ -0,0 +1,54 @@ +[colors] +accent = '#9A8652FF' +background = '#E0E0E0FF' +base00 = '#E0E0E0FF' +base01 = '#668A51FF' +base02 = '#9A8652FF' +base03 = '#B47837FF' +base04 = '#9A5552FF' +base05 = '#AA477BFF' +base06 = '#3A898CFF' +base07 = '#5A5A5AFF' +base08 = '#AA4E4AFF' +base09 = '#4A7A2EFF' +base0A = '#7A6A42FF' +base0B = '#A5714BFF' +base0C = '#8C5656FF' +base0D = '#90577EFF' +base0E = '#2A6A6DFF' +base0F = '#2A2A2AFF' +border = '#C5C5C5FF' +border_focused = '#B9B9B9FF' +cursor = '#2A2A2AFF' +editor_background = '#E0E0E0FF' +editor_command = '#3A898CFF' +editor_comment = '#849899FF' +editor_disabled = '#A0A0A0FF' +editor_emphasis = '#4A7A2EFF' +editor_error = '#AA4E4AFF' +editor_inactive = '#A0A0A0FF' +editor_line_number = '#9A9A95FF' +editor_link = '#90577EFF' +editor_main = '#2A2A2AFF' +editor_selected = '#C9C9C9FF' +editor_selection_inactive = '#D2D2D2FF' +editor_string = '#9A8652FF' +editor_success = '#668A51FF' +editor_warning = '#B47837FF' +error = '#AA4E4AFF' +foreground = '#2A2A2AFF' +info = '#3A898CFF' +on_background = '#2A2A2AFF' +on_error = '#FAFAF8FF' +on_info = '#FAFAF8FF' +on_success = '#FAFAF8FF' +on_surface = '#2A2A2AFF' +on_surface_variant = '#3A3A3AFF' +on_warning = '#FAFAF8FF' +success = '#668A51FF' +surface = '#E0E0E0FF' +surface_variant = '#CECECEFF' +warning = '#B47837FF' + +[general] +name = 'light' \ No newline at end of file diff --git a/example_config/palettes/cursed-light.toml b/extra/palletes/cursed-light.toml similarity index 100% rename from example_config/palettes/cursed-light.toml rename to extra/palletes/cursed-light.toml diff --git a/example_config/palettes/cursed.toml b/extra/palletes/cursed.toml similarity index 100% rename from example_config/palettes/cursed.toml rename to extra/palletes/cursed.toml diff --git a/example_config/palettes/nord.toml b/extra/palletes/nord.toml similarity index 100% rename from example_config/palettes/nord.toml rename to extra/palletes/nord.toml diff --git a/src/gui/color_table_renderer.cpp b/src/gui/color_table_renderer.cpp index 86f1e67..65b7c47 100644 --- a/src/gui/color_table_renderer.cpp +++ b/src/gui/color_table_renderer.cpp @@ -107,7 +107,8 @@ void color_table_renderer::render(const clrsync::core::palette& current, { if (current.colors().empty()) { - ImGui::TextColored(ImVec4(1.0f, 0.6f, 0.4f, 1.0f), "No palette loaded"); + ImVec4 warning_color = palette_utils::get_color(current, "warning", "accent"); + ImGui::TextColored(warning_color, "No palette loaded"); return; } diff --git a/src/gui/preview_renderer.cpp b/src/gui/preview_renderer.cpp index c583a8c..0228025 100644 --- a/src/gui/preview_renderer.cpp +++ b/src/gui/preview_renderer.cpp @@ -1,5 +1,6 @@ #include "preview_renderer.hpp" #include "theme_applier.hpp" +#include "imgui_helpers.hpp" #include "imgui.h" #include #include @@ -237,7 +238,8 @@ void preview_renderer::render(const clrsync::core::palette& current) { if (current.colors().empty()) { - ImGui::TextColored(ImVec4(1.0f, 0.3f, 0.3f, 1.0f), "Current palette is empty"); + ImVec4 error_color = palette_utils::get_color(current, "error", "accent"); + ImGui::TextColored(error_color, "Current palette is empty"); return; } diff --git a/src/gui/settings_window.cpp b/src/gui/settings_window.cpp index 3637e55..f0e0295 100644 --- a/src/gui/settings_window.cpp +++ b/src/gui/settings_window.cpp @@ -250,12 +250,36 @@ void settings_window::render_status_messages() if (!m_error_message.empty()) { ImGui::Spacing(); - auto error_color = palette_utils::get_color(m_current_palette, "error"); - ImGui::PushStyleColor(ImGuiCol_Text, error_color); - ImGui::TextWrapped("Error: %s", m_error_message.c_str()); - ImGui::PopStyleColor(); - if (ImGui::Button("Dismiss##error")) - m_error_message.clear(); + + auto error_bg_color = palette_utils::get_color(m_current_palette, "error"); + auto error_text_color = palette_utils::get_color(m_current_palette, "on_error"); + + ImGui::PushStyleColor(ImGuiCol_ChildBg, error_bg_color); + ImGui::PushStyleColor(ImGuiCol_Border, error_bg_color); + ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 4.0f); + ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f); + + if (ImGui::BeginChild("##error_box", ImVec2(0, 0), ImGuiChildFlags_AutoResizeY | ImGuiChildFlags_Borders)) + { + ImGui::PushStyleColor(ImGuiCol_Text, error_text_color); + ImGui::TextWrapped("Error: %s", m_error_message.c_str()); + ImGui::PopStyleColor(); + + ImGui::Spacing(); + + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(error_bg_color.x * 0.8f, error_bg_color.y * 0.8f, error_bg_color.z * 0.8f, error_bg_color.w)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(error_bg_color.x * 0.6f, error_bg_color.y * 0.6f, error_bg_color.z * 0.6f, error_bg_color.w)); + ImGui::PushStyleColor(ImGuiCol_Text, error_text_color); + + if (ImGui::Button("Dismiss##error")) + m_error_message.clear(); + + ImGui::PopStyleColor(3); + } + ImGui::EndChild(); + + ImGui::PopStyleVar(2); + ImGui::PopStyleColor(2); } } diff --git a/src/gui/template_editor.cpp b/src/gui/template_editor.cpp index d08f955..b790ab7 100644 --- a/src/gui/template_editor.cpp +++ b/src/gui/template_editor.cpp @@ -102,13 +102,13 @@ void template_editor::apply_current_palette(const clrsync::core::palette &pal) m_editor.SetPalette(palette); - m_autocomplete_bg_color = palette_utils::get_color(pal, "editor_background", "background"); + m_autocomplete_bg_color = palette_utils::get_color(pal, "surface", "background"); m_autocomplete_bg_color.w = 0.98f; - m_autocomplete_border_color = palette_utils::get_color(pal, "border", "editor_inactive"); - m_autocomplete_selected_color = palette_utils::get_color(pal, "editor_selected", "surface_variant"); - m_autocomplete_text_color = palette_utils::get_color(pal, "editor_main", "foreground"); - m_autocomplete_selected_text_color = palette_utils::get_color(pal, "foreground", "editor_main"); - m_autocomplete_dim_text_color = palette_utils::get_color(pal, "editor_comment", "editor_inactive"); + m_autocomplete_border_color = palette_utils::get_color(pal, "border", "surface_variant"); + m_autocomplete_selected_color = palette_utils::get_color(pal, "accent", "surface_variant"); + m_autocomplete_text_color = palette_utils::get_color(pal, "on_surface", "foreground"); + m_autocomplete_selected_text_color = palette_utils::get_color(pal, "on_surface", "foreground"); + m_autocomplete_dim_text_color = palette_utils::get_color(pal, "on_surface_variant", "editor_inactive"); } void template_editor::update_autocomplete_suggestions() @@ -433,20 +433,20 @@ void template_editor::render_controls() if (m_enabled) { ImVec4 success_color = palette_utils::get_color(m_current_palette, "success", "accent"); + ImVec4 success_on_color = palette_utils::get_color(m_current_palette, "on_success", "on_surface"); ImVec4 success_hover = ImVec4(success_color.x * 1.2f, success_color.y * 1.2f, success_color.z * 1.2f, 0.6f); - ImVec4 success_check = ImVec4(success_color.x * 1.5f, success_color.y * 1.5f, success_color.z * 1.5f, 1.0f); ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(success_color.x, success_color.y, success_color.z, 0.5f)); ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, success_hover); - ImGui::PushStyleColor(ImGuiCol_CheckMark, success_check); + ImGui::PushStyleColor(ImGuiCol_CheckMark, success_on_color); } else { ImVec4 error_color = palette_utils::get_color(m_current_palette, "error", "accent"); + ImVec4 error_on_color = palette_utils::get_color(m_current_palette, "on_error", "on_surface"); ImVec4 error_hover = ImVec4(error_color.x * 1.2f, error_color.y * 1.2f, error_color.z * 1.2f, 0.6f); - ImVec4 error_check = ImVec4(error_color.x * 1.5f, error_color.y * 1.5f, error_color.z * 1.5f, 1.0f); ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(error_color.x, error_color.y, error_color.z, 0.5f)); ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, error_hover); - ImGui::PushStyleColor(ImGuiCol_CheckMark, error_check); + ImGui::PushStyleColor(ImGuiCol_CheckMark, error_on_color); } enabled_changed = ImGui::Checkbox("Enabled", &m_enabled); @@ -569,7 +569,8 @@ void template_editor::render_controls() if (!m_validation_error.empty()) { ImGui::Spacing(); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.4f, 0.4f, 1.0f)); + ImVec4 error_color = palette_utils::get_color(m_current_palette, "error", "accent"); + ImGui::PushStyleColor(ImGuiCol_Text, error_color); ImGui::TextWrapped("%s", m_validation_error.c_str()); ImGui::PopStyleColor(); } @@ -581,7 +582,8 @@ void template_editor::render_editor() if (!m_is_editing_existing) { - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.4f, 0.8f, 0.4f, 1.0f)); + ImVec4 success_color = palette_utils::get_color(m_current_palette, "success", "accent"); + ImGui::PushStyleColor(ImGuiCol_Text, success_color); ImGui::Text(" New Template"); ImGui::PopStyleColor(); } @@ -600,7 +602,8 @@ void template_editor::render_editor() if (m_has_unsaved_changes) { ImGui::SameLine(); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.6f, 0.2f, 1.0f)); + ImVec4 warning_color = palette_utils::get_color(m_current_palette, "warning", "accent"); + ImGui::PushStyleColor(ImGuiCol_Text, warning_color); ImGui::Text("(unsaved)"); ImGui::PopStyleColor(); } @@ -705,7 +708,8 @@ void template_editor::render_template_list() if (!tmpl.enabled()) { - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.5f, 0.5f, 0.5f, 1.0f)); + ImVec4 disabled_color = palette_utils::get_color(m_current_palette, "on_surface_variant", "editor_inactive"); + ImGui::PushStyleColor(ImGuiCol_Text, disabled_color); } if (ImGui::Selectable(key.c_str(), selected)) diff --git a/src/gui/theme_applier.cpp b/src/gui/theme_applier.cpp index 4c54e83..ed8e967 100644 --- a/src/gui/theme_applier.cpp +++ b/src/gui/theme_applier.cpp @@ -63,12 +63,24 @@ void apply_to_imgui(const clrsync::core::palette& current) ImGuiStyle &style = ImGui::GetStyle(); const ImVec4 bg = getColor("background"); + const ImVec4 onBg = getColor("on_background"); const ImVec4 surface = getColor("surface"); + const ImVec4 onSurface = getColor("on_surface"); const ImVec4 surfaceVariant = getColor("surface_variant"); + const ImVec4 onSurfaceVariant = getColor("on_surface_variant"); const ImVec4 fg = getColor("foreground"); const ImVec4 fgInactive = getColor("editor_inactive"); const ImVec4 accent = getColor("accent"); const ImVec4 border = getColor("border"); + + const ImVec4 error = getColor("error"); + const ImVec4 onError = getColor("on_error"); + const ImVec4 success = getColor("success"); + const ImVec4 onSuccess = getColor("on_success"); + const ImVec4 warning = getColor("warning"); + const ImVec4 onWarning = getColor("on_warning"); + const ImVec4 info = getColor("info"); + const ImVec4 onInfo = getColor("on_info"); style.Colors[ImGuiCol_WindowBg] = bg; style.Colors[ImGuiCol_ChildBg] = surface; @@ -77,8 +89,9 @@ void apply_to_imgui(const clrsync::core::palette& current) style.Colors[ImGuiCol_Border] = border; style.Colors[ImGuiCol_BorderShadow] = ImVec4(0, 0, 0, 0); - style.Colors[ImGuiCol_Text] = fg; - style.Colors[ImGuiCol_TextDisabled] = fgInactive; + style.Colors[ImGuiCol_Text] = onSurface; + style.Colors[ImGuiCol_TextDisabled] = onSurfaceVariant; + style.Colors[ImGuiCol_TextSelectedBg] = accent; style.Colors[ImGuiCol_Header] = surfaceVariant; style.Colors[ImGuiCol_HeaderHovered] = ImVec4(accent.x, accent.y, accent.z, 0.8f); @@ -125,7 +138,7 @@ void apply_to_imgui(const clrsync::core::palette& current) ImVec4(border.x * 0.7f, border.y * 0.7f, border.z * 0.7f, border.w); style.Colors[ImGuiCol_TableRowBg] = ImVec4(0, 0, 0, 0); - style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(fg.x, fg.y, fg.z, 0.06f); + style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(onSurfaceVariant.x, onSurfaceVariant.y, onSurfaceVariant.z, 0.06f); style.Colors[ImGuiCol_Separator] = border; style.Colors[ImGuiCol_SeparatorHovered] = accent;