fix: coloring

This commit is contained in:
2025-12-17 15:49:48 +03:00
parent 231e9f0176
commit b08ba4d754
11 changed files with 178 additions and 26 deletions

View File

@@ -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;
}

View File

@@ -1,5 +1,6 @@
#include "preview_renderer.hpp"
#include "theme_applier.hpp"
#include "imgui_helpers.hpp"
#include "imgui.h"
#include <algorithm>
#include <array>
@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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))

View File

@@ -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;