mirror of
https://github.com/obsqrbtz/clrsync.git
synced 2026-04-08 20:19:04 +03:00
updated preview
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <cstdio>
|
||||
#include <format>
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace clrsync::core
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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,45 +101,133 @@ 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 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 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 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, bg);
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, border_col);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, editor_bg);
|
||||
ImGui::BeginChild("TerminalPreview", ImVec2(0, 0), true);
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, border);
|
||||
const float terminal_height = std::max(200.0f, ImGui::GetContentRegionAvail().y - 10.0f);
|
||||
ImGui::BeginChild("TerminalPreview", ImVec2(0, terminal_height), true);
|
||||
|
||||
struct term_line
|
||||
{
|
||||
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},
|
||||
};
|
||||
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");
|
||||
|
||||
for (auto &[text, col] : term_lines)
|
||||
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++)
|
||||
{
|
||||
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();
|
||||
|
||||
@@ -605,30 +605,7 @@ void template_editor::render_editor()
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -4,47 +4,49 @@
|
||||
namespace theme_applier
|
||||
{
|
||||
|
||||
static uint32_t get_color_u32(const clrsync::core::palette& current, const std::string &key)
|
||||
{
|
||||
const auto &col = current.get_color(key);
|
||||
const uint32_t hex = col.hex();
|
||||
// Convert from RRGGBBAA to AABBGGRR (ImGui format)
|
||||
const uint32_t r = (hex >> 24) & 0xFF;
|
||||
const uint32_t g = (hex >> 16) & 0xFF;
|
||||
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 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)
|
||||
const uint32_t r = (hex >> 24) & 0xFF;
|
||||
const uint32_t g = (hex >> 16) & 0xFF;
|
||||
const uint32_t b = (hex >> 8) & 0xFF;
|
||||
const uint32_t a = hex & 0xFF;
|
||||
return (a << 24) | (b << 16) | (g << 8) | r;
|
||||
};
|
||||
|
||||
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::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("border_focused");
|
||||
palette[int(TextEditor::PaletteIndex::CurrentLineEdge)] = get_color_u32(current, "border_focused");
|
||||
|
||||
editor.SetPalette(palette);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user