updated preview

This commit is contained in:
2025-12-17 14:46:32 +03:00
parent b98761a172
commit 231e9f0176
12 changed files with 279 additions and 168 deletions

View File

@@ -1,67 +1,54 @@
[colors]
# General
background = "#f5f5f5FF"
on_background = "#3d3d2fFF"
surface = "#e8e8e8FF"
on_surface = "#3d3d2fFF"
surface_variant = "#d0d0c8FF"
on_surface_variant = "#3d3d2fFF"
border_focused = "#c9a305FF"
border = "#d0d0c8FF"
foreground = "#3d3d2fFF"
cursor = "#c9a305FF"
accent = "#b44242FF"
# Terminal
base00 = "#f5f5f5FF"
base01 = "#b44242FF"
base02 = "#95a328FF"
base03 = "#c9a305FF"
base04 = "#60928fFF"
base05 = "#7c435aFF"
base06 = "#a48b4aFF"
base07 = "#3d3d2fFF"
base08 = "#c0c0b8FF"
base09 = "#dc7671FF"
base0A = "#d4d430FF"
base0B = "#9e9052FF"
base0C = "#76c39bFF"
base0D = "#86596cFF"
base0E = "#b89a1fFF"
base0F = "#4f4f48FF"
# Semantic
success = "#95a328FF"
info = "#60928fFF"
warning = "#c9a305FF"
error = "#b44242FF"
on_success = "#f5f5f5FF"
on_info = "#f5f5f5FF"
on_warning = "#f5f5f5FF"
on_error = "#f5f5f5FF"
# Code editor
editor_background = "#f5f5f5FF"
editor_command = "#b89a1fFF"
editor_comment = "#a0a098FF"
editor_disabled = "#c0c0b8FF"
editor_emphasis = "#dc7671FF"
editor_error = "#b44242FF"
editor_inactive = "#a0a098FF"
editor_line_number = "#86596cFF"
editor_link = "#60928fFF"
editor_main = "#3d3d2fFF"
editor_selected = "#d0d0c8FF"
editor_selection_inactive = "#e0e0d8FF"
editor_string = "#5fa37bFF"
editor_success = "#95a328FF"
editor_warning = "#c9a305FF"
accent = '#95A328FF'
background = '#F5F5F5FF'
base00 = '#F5F5F5FF'
base01 = '#B44242FF'
base02 = '#95A328FF'
base03 = '#C9A305FF'
base04 = '#60928FFF'
base05 = '#7C435AFF'
base06 = '#A48B4AFF'
base07 = '#3D3D2FFF'
base08 = '#C0C0B8FF'
base09 = '#DC7671FF'
base0A = '#D4D430FF'
base0B = '#9E9052FF'
base0C = '#76C39BFF'
base0D = '#86596CFF'
base0E = '#B89A1FFF'
base0F = '#4F4F48FF'
border = '#D0D0C8FF'
border_focused = '#C9A305FF'
cursor = '#C9A305FF'
editor_background = '#F5F5F5FF'
editor_command = '#B89A1FFF'
editor_comment = '#A0A098FF'
editor_disabled = '#C0C0B8FF'
editor_emphasis = '#DC7671FF'
editor_error = '#B44242FF'
editor_inactive = '#A0A098FF'
editor_line_number = '#86596CFF'
editor_link = '#60928FFF'
editor_main = '#3D3D2FFF'
editor_selected = '#D0D0C8FF'
editor_selection_inactive = '#E0E0D8FF'
editor_string = '#5FA37BFF'
editor_success = '#95A328FF'
editor_warning = '#C9A305FF'
error = '#B44242FF'
foreground = '#3D3D2FFF'
info = '#60928FFF'
on_background = '#3D3D2FFF'
on_error = '#F5F5F5FF'
on_info = '#F5F5F5FF'
on_success = '#F5F5F5FF'
on_surface = '#3D3D2FFF'
on_surface_variant = '#CCCCCCFF'
on_warning = '#F5F5F5FF'
success = '#95A328FF'
surface = '#E8E8E8FF'
surface_variant = '#D0D0C8FF'
warning = '#C9A305FF'
[general]
name = 'cursed-light'

View File

@@ -1,5 +1,5 @@
[colors]
accent = '#B44242FF'
accent = '#95A328FF'
background = '#151515FF'
base00 = '#151515FF'
base01 = '#B44242FF'
@@ -22,7 +22,7 @@ border_focused = '#E1C135FF'
cursor = '#E1C135FF'
editor_background = '#151515FF'
editor_command = '#CEB34FFF'
editor_comment = '#3F3639FF'
editor_comment = '#7A7A7AFF'
editor_disabled = '#3F3639FF'
editor_emphasis = '#DC7671FF'
editor_error = '#B44242FF'
@@ -43,7 +43,7 @@ on_error = '#151515FF'
on_info = '#151515FF'
on_success = '#151515FF'
on_surface = '#C2C2B0FF'
on_surface_variant = '#C2C2B0FF'
on_surface_variant = '#CCCCCCFF'
on_warning = '#151515FF'
success = '#95A328FF'
surface = '#1C1C1CFF'

View File

@@ -0,0 +1,54 @@
[colors]
accent = '#5E81ACFF'
background = '#2E3440FF'
base00 = '#2E3440FF'
base01 = '#BF616AFF'
base02 = '#A3BE8CFF'
base03 = '#EBCB8BFF'
base04 = '#81A1C1FF'
base05 = '#B48EADFF'
base06 = '#88C0D0FF'
base07 = '#E5E9F0FF'
base08 = '#4C566AFF'
base09 = '#D08770FF'
base0A = '#EBCB8BFF'
base0B = '#A3BE8CFF'
base0C = '#8FBCBBFF'
base0D = '#5E81ACFF'
base0E = '#B48EADFF'
base0F = '#ECEFF4FF'
border = '#4C566AFF'
border_focused = '#88C0D0FF'
cursor = '#D8DEE9FF'
editor_background = '#2E3440FF'
editor_command = '#81A1C1FF'
editor_comment = '#616E88FF'
editor_disabled = '#4C566AFF'
editor_emphasis = '#B48EADFF'
editor_error = '#BF616AFF'
editor_inactive = '#616E88FF'
editor_line_number = '#4C566AFF'
editor_link = '#88C0D0FF'
editor_main = '#D8DEE9FF'
editor_selected = '#434C5EFF'
editor_selection_inactive = '#3B4252FF'
editor_string = '#A3BE8CFF'
editor_success = '#A3BE8CFF'
editor_warning = '#EBCB8BFF'
error = '#BF616AFF'
foreground = '#D8DEE9FF'
info = '#5E81ACFF'
on_background = '#D8DEE9FF'
on_error = '#2E3440FF'
on_info = '#2E3440FF'
on_success = '#2E3440FF'
on_surface = '#ECEFF4FF'
on_surface_variant = '#ECEFF4FF'
on_warning = '#2E3440FF'
success = '#A3BE8CFF'
surface = '#3B4252FF'
surface_variant = '#434C5EFF'
warning = '#EBCB8BFF'
[general]
name = 'nord'

View File

@@ -3,7 +3,6 @@
#include <cstdio>
#include <format>
#include <stdexcept>
#include <unordered_map>
namespace clrsync::core
{

View File

@@ -6,7 +6,7 @@
namespace clrsync::core
{
const std::string GIT_SEMVER = "0.1.4+git.g92b06a9";
const std::string GIT_SEMVER = "0.1.5+git.gb98761a";
const std::string version_string();
} // namespace clrsync::core

View File

@@ -35,6 +35,7 @@ if(WIN32)
comdlg32
shlwapi
)
set_target_properties(clrsync_gui PROPERTIES WIN32_EXECUTABLE TRUE)
elseif(APPLE)
target_link_libraries(clrsync_gui PRIVATE
clrsync_core

View File

@@ -131,16 +131,6 @@ void color_table_renderer::render(const clrsync::core::palette& current,
ImGui::SetTooltip("Clear filter");
}
ImGui::SameLine();
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::TextUnformatted("Click on a color name to copy its template variable");
ImGui::TextUnformatted("Example: clicking 'background' copies {background.hex}");
ImGui::EndTooltip();
}
ImGui::PopStyleVar();
ImGui::Spacing();

View File

@@ -133,8 +133,8 @@ void setup_main_dockspace(bool& first_time)
}
ImGui::DockBuilderDockWindow("Color Schemes", right);
ImGui::DockBuilderDockWindow("Templates", center);
ImGui::DockBuilderDockWindow("Color Preview", center);
ImGui::DockBuilderDockWindow("Templates", center);
ImGui::DockBuilderFinish(dockspace_id);
}

View File

@@ -77,9 +77,9 @@ int main(int, char**)
render_menu_bar(&aboutWindow, &settingsWindow);
setup_main_dockspace(first_time);
templateEditor.render();
colorEditor.render_controls_and_colors();
colorEditor.render_preview();
templateEditor.render();
aboutWindow.render(colorEditor.controller().current_palette());
settingsWindow.render();

View File

@@ -2,6 +2,7 @@
#include "theme_applier.hpp"
#include "imgui.h"
#include <algorithm>
#include <array>
preview_renderer::preview_renderer()
{
@@ -70,6 +71,16 @@ int main()
m_editor.SetShowWhitespaces(false);
}
static ImVec4 hex_to_imvec4(uint32_t hex)
{
return {
((hex >> 24) & 0xFF) / 255.0f,
((hex >> 16) & 0xFF) / 255.0f,
((hex >> 8) & 0xFF) / 255.0f,
(hex & 0xFF) / 255.0f
};
}
void preview_renderer::apply_palette(const clrsync::core::palette& palette)
{
theme_applier::apply_to_editor(m_editor, palette);
@@ -78,9 +89,11 @@ void preview_renderer::apply_palette(const clrsync::core::palette& palette)
void preview_renderer::render_code_preview()
{
const float avail_height = ImGui::GetContentRegionAvail().y;
const float code_preview_height = std::max(250.0f, avail_height * 0.55f);
const float code_preview_height = std::max(250.0f, avail_height * 0.50f);
ImGui::Text("Code Editor:");
ImGui::Text("Code Editor Preview:");
ImGui::SameLine();
ImGui::TextDisabled("(editor_* colors)");
m_editor.Render("##CodeEditor", ImVec2(0, code_preview_height), true);
}
@@ -88,46 +101,134 @@ void preview_renderer::render_terminal_preview(const clrsync::core::palette& cur
{
auto get_color = [&](const std::string &key) -> ImVec4 {
const auto &col = current.get_color(key);
const uint32_t hex = col.hex();
return {((hex >> 24) & 0xFF) / 255.0f, ((hex >> 16) & 0xFF) / 255.0f,
((hex >> 8) & 0xFF) / 255.0f, ((hex) & 0xFF) / 255.0f};
return hex_to_imvec4(col.hex());
};
const ImVec4 bg = get_color("base00");
const ImVec4 fg = get_color("base07");
const ImVec4 cursor_col = get_color("cursor");
const ImVec4 border_col = get_color("border");
const ImVec4 editor_bg = get_color("editor_background");
const ImVec4 fg = get_color("foreground");
const ImVec4 accent = get_color("accent");
const ImVec4 border = get_color("border");
const ImVec4 error = get_color("error");
const ImVec4 warning = get_color("warning");
const ImVec4 success = get_color("success");
const ImVec4 info = get_color("info");
const ImVec4 black = get_color("base00");
const ImVec4 red = get_color("base01");
const ImVec4 green = get_color("base02");
const ImVec4 yellow = get_color("base03");
const ImVec4 blue = get_color("base04");
const ImVec4 magenta = get_color("base05");
const ImVec4 cyan = get_color("base06");
const ImVec4 white = get_color("base07");
const ImVec4 bright_black = get_color("base08");
const ImVec4 bright_red = get_color("base09");
const ImVec4 bright_green = get_color("base0A");
const ImVec4 bright_yellow = get_color("base0B");
const ImVec4 bright_blue = get_color("base0C");
const ImVec4 bright_magenta = get_color("base0D");
const ImVec4 bright_cyan = get_color("base0E");
const ImVec4 bright_white = get_color("base0F");
ImGui::Spacing();
ImGui::Text("Terminal Preview:");
ImGui::SameLine();
ImGui::TextDisabled("(base00-base0F colors)");
ImGui::PushStyleColor(ImGuiCol_ChildBg, editor_bg);
ImGui::BeginChild("TerminalPreview", ImVec2(0, 0), true);
ImGui::PushStyleColor(ImGuiCol_Border, border);
ImGui::PushStyleColor(ImGuiCol_ChildBg, bg);
ImGui::PushStyleColor(ImGuiCol_Border, border_col);
struct term_line
const float terminal_height = std::max(200.0f, ImGui::GetContentRegionAvail().y - 10.0f);
ImGui::BeginChild("TerminalPreview", ImVec2(0, terminal_height), true);
ImGui::TextColored(green, "user@host");
ImGui::SameLine(0, 0);
ImGui::TextColored(fg, ":");
ImGui::SameLine(0, 0);
ImGui::TextColored(blue, "~/projects");
ImGui::SameLine(0, 0);
ImGui::TextColored(fg, "$ ");
ImGui::SameLine(0, 0);
ImGui::TextColored(fg, "ls -la");
ImGui::TextColored(fg, "total 48");
ImGui::TextColored(blue, "drwxr-xr-x");
ImGui::SameLine();
ImGui::TextColored(fg, " 5 user group 4096 Dec 2 10:30 ");
ImGui::SameLine(0, 0);
ImGui::TextColored(blue, ".");
ImGui::TextColored(blue, "drwxr-xr-x");
ImGui::SameLine();
ImGui::TextColored(fg, " 3 user group 4096 Dec 1 09:15 ");
ImGui::SameLine(0, 0);
ImGui::TextColored(blue, "..");
ImGui::TextColored(fg, "-rw-r--r--");
ImGui::SameLine();
ImGui::TextColored(fg, " 1 user group 1234 Dec 2 10:30 ");
ImGui::SameLine(0, 0);
ImGui::TextColored(fg, "README.md");
ImGui::TextColored(fg, "-rwxr-xr-x");
ImGui::SameLine();
ImGui::TextColored(fg, " 1 user group 8192 Dec 2 10:28 ");
ImGui::SameLine(0, 0);
ImGui::TextColored(green, "build.sh");
ImGui::TextColored(cyan, "lrwxrwxrwx");
ImGui::SameLine();
ImGui::TextColored(fg, " 1 user group 24 Dec 1 15:00 ");
ImGui::SameLine(0, 0);
ImGui::TextColored(cyan, "config -> ~/.config/app");
ImGui::Spacing();
ImGui::TextColored(green, "user@host");
ImGui::SameLine(0, 0);
ImGui::TextColored(fg, ":");
ImGui::SameLine(0, 0);
ImGui::TextColored(blue, "~/projects");
ImGui::SameLine(0, 0);
ImGui::TextColored(fg, "$ ");
ImGui::SameLine(0, 0);
ImGui::TextColored(fg, "git status");
ImGui::TextColored(fg, "On branch ");
ImGui::SameLine(0, 0);
ImGui::TextColored(green, "main");
ImGui::TextColored(fg, "Changes to be committed:");
ImGui::TextColored(green, " modified: src/main.cpp");
ImGui::TextColored(green, " new file: src/utils.hpp");
ImGui::TextColored(fg, "Changes not staged:");
ImGui::TextColored(red, " modified: README.md");
ImGui::Spacing();
ImGui::TextColored(fg, "ANSI Colors (0-7 / 8-15):");
const float box_size = 20.0f;
const float spacing = 4.0f;
ImVec2 start_pos = ImGui::GetCursorScreenPos();
ImDrawList* draw_list = ImGui::GetWindowDrawList();
std::array<ImVec4, 8> normal_colors = {black, red, green, yellow, blue, magenta, cyan, white};
for (size_t i = 0; i < 8; i++)
{
const char *text{};
ImVec4 col;
};
term_line term_lines[] = {
{"$ ls -la", fg},
{"drwxr-xr-x 5 user group 4096 Dec 2 10:30 .", accent},
{"Build successful", success},
{"Error: file not found", error},
{"Warning: low disk space", warning},
{"Info: update available", info},
};
for (auto &[text, col] : term_lines)
{
ImGui::TextColored(col, "%s", text);
ImVec2 p0 = ImVec2(start_pos.x + i * (box_size + spacing), start_pos.y);
ImVec2 p1 = ImVec2(p0.x + box_size, p0.y + box_size);
draw_list->AddRectFilled(p0, p1, ImGui::ColorConvertFloat4ToU32(normal_colors[i]));
draw_list->AddRect(p0, p1, ImGui::ColorConvertFloat4ToU32(border_col));
}
std::array<ImVec4, 8> bright_colors = {bright_black, bright_red, bright_green, bright_yellow,
bright_blue, bright_magenta, bright_cyan, bright_white};
for (size_t i = 0; i < 8; i++)
{
ImVec2 p0 = ImVec2(start_pos.x + i * (box_size + spacing), start_pos.y + box_size + spacing);
ImVec2 p1 = ImVec2(p0.x + box_size, p0.y + box_size);
draw_list->AddRectFilled(p0, p1, ImGui::ColorConvertFloat4ToU32(bright_colors[i]));
draw_list->AddRect(p0, p1, ImGui::ColorConvertFloat4ToU32(border_col));
}
ImGui::Dummy(ImVec2(8 * (box_size + spacing), 2 * box_size + spacing + 4));
ImGui::PopStyleColor(2);
ImGui::EndChild();
}

View File

@@ -606,29 +606,6 @@ void template_editor::render_editor()
}
}
ImGui::SameLine(ImGui::GetContentRegionAvail().x - 30);
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 25.0f);
ImGui::TextUnformatted("Template Syntax:");
ImGui::Separator();
ImGui::TextUnformatted("Use {color_key.format} for color variables");
ImGui::Spacing();
ImGui::TextUnformatted("Color Keys: background, foreground, accent, etc.");
ImGui::TextUnformatted("Formats: hex, rgb, rgba, r, g, b, hsl, hsla, etc.");
ImGui::Spacing();
ImGui::TextUnformatted("Examples:");
ImGui::BulletText("{background.hex} -> #1E1E1E");
ImGui::BulletText("{accent.rgb} -> rgb(14,99,156)");
ImGui::BulletText("{foreground.r} -> 204");
ImGui::Spacing();
ImGui::TextUnformatted("Tip: Type '{' to trigger autocomplete!");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
ImGui::PopStyleVar();
ImGui::Separator();

View File

@@ -4,9 +4,8 @@
namespace theme_applier
{
void apply_to_editor(TextEditor& editor, const clrsync::core::palette& current)
static uint32_t get_color_u32(const clrsync::core::palette& current, const std::string &key)
{
auto get_color_u32 = [&](const std::string &key) -> uint32_t {
const auto &col = current.get_color(key);
const uint32_t hex = col.hex();
// Convert from RRGGBBAA to AABBGGRR (ImGui format)
@@ -15,36 +14,39 @@ void apply_to_editor(TextEditor& editor, const clrsync::core::palette& current)
const uint32_t b = (hex >> 8) & 0xFF;
const uint32_t a = hex & 0xFF;
return (a << 24) | (b << 16) | (g << 8) | r;
};
}
void apply_to_editor(TextEditor& editor, const clrsync::core::palette& current)
{
auto palette = editor.GetPalette();
palette[int(TextEditor::PaletteIndex::Default)] = get_color_u32("editor_main");
palette[int(TextEditor::PaletteIndex::Keyword)] = get_color_u32("editor_command");
palette[int(TextEditor::PaletteIndex::Number)] = get_color_u32("editor_warning");
palette[int(TextEditor::PaletteIndex::String)] = get_color_u32("editor_string");
palette[int(TextEditor::PaletteIndex::CharLiteral)] = get_color_u32("editor_string");
palette[int(TextEditor::PaletteIndex::Punctuation)] = get_color_u32("editor_main");
palette[int(TextEditor::PaletteIndex::Preprocessor)] = get_color_u32("editor_emphasis");
palette[int(TextEditor::PaletteIndex::Identifier)] = get_color_u32("editor_main");
palette[int(TextEditor::PaletteIndex::KnownIdentifier)] = get_color_u32("editor_link");
palette[int(TextEditor::PaletteIndex::PreprocIdentifier)] = get_color_u32("editor_link");
palette[int(TextEditor::PaletteIndex::Default)] = get_color_u32(current, "editor_main");
palette[int(TextEditor::PaletteIndex::Keyword)] = get_color_u32(current, "editor_command");
palette[int(TextEditor::PaletteIndex::Number)] = get_color_u32(current, "editor_warning");
palette[int(TextEditor::PaletteIndex::String)] = get_color_u32(current, "editor_string");
palette[int(TextEditor::PaletteIndex::CharLiteral)] = get_color_u32(current, "editor_string");
palette[int(TextEditor::PaletteIndex::Punctuation)] = get_color_u32(current, "editor_main");
palette[int(TextEditor::PaletteIndex::Preprocessor)] = get_color_u32(current, "editor_emphasis");
palette[int(TextEditor::PaletteIndex::Identifier)] = get_color_u32(current, "editor_main");
palette[int(TextEditor::PaletteIndex::KnownIdentifier)] = get_color_u32(current, "editor_link");
palette[int(TextEditor::PaletteIndex::PreprocIdentifier)] = get_color_u32(current, "editor_link");
palette[int(TextEditor::PaletteIndex::Comment)] = get_color_u32("editor_comment");
palette[int(TextEditor::PaletteIndex::MultiLineComment)] = get_color_u32("editor_comment");
palette[int(TextEditor::PaletteIndex::Comment)] = get_color_u32(current, "editor_comment");
palette[int(TextEditor::PaletteIndex::MultiLineComment)] = get_color_u32(current, "editor_comment");
palette[int(TextEditor::PaletteIndex::Background)] = get_color_u32("editor_background");
palette[int(TextEditor::PaletteIndex::Cursor)] = get_color_u32("cursor");
palette[int(TextEditor::PaletteIndex::Background)] = get_color_u32(current, "editor_background");
palette[int(TextEditor::PaletteIndex::Cursor)] = get_color_u32(current, "cursor");
palette[int(TextEditor::PaletteIndex::Selection)] = get_color_u32("editor_selected");
palette[int(TextEditor::PaletteIndex::ErrorMarker)] = get_color_u32("editor_error");
palette[int(TextEditor::PaletteIndex::Breakpoint)] = get_color_u32("editor_error");
palette[int(TextEditor::PaletteIndex::Selection)] = get_color_u32(current, "editor_selected");
palette[int(TextEditor::PaletteIndex::ErrorMarker)] = get_color_u32(current, "editor_error");
palette[int(TextEditor::PaletteIndex::Breakpoint)] = get_color_u32(current, "editor_error");
palette[int(TextEditor::PaletteIndex::LineNumber)] = get_color_u32("editor_line_number");
palette[int(TextEditor::PaletteIndex::CurrentLineFill)] = get_color_u32("surface_variant");
palette[int(TextEditor::PaletteIndex::CurrentLineFillInactive)] = get_color_u32("surface");
palette[int(TextEditor::PaletteIndex::LineNumber)] = get_color_u32(current, "editor_line_number");
palette[int(TextEditor::PaletteIndex::CurrentLineEdge)] = get_color_u32("border_focused");
palette[int(TextEditor::PaletteIndex::CurrentLineFill)] = get_color_u32(current, "surface_variant");
palette[int(TextEditor::PaletteIndex::CurrentLineFillInactive)] = get_color_u32(current, "surface");
palette[int(TextEditor::PaletteIndex::CurrentLineEdge)] = get_color_u32(current, "border_focused");
editor.SetPalette(palette);
}