16 Commits

87 changed files with 3030 additions and 1972 deletions

View File

@@ -2,7 +2,7 @@ name: Test PKGBUILD-git
on: on:
push: push:
branch: master branches: master
pull_request: pull_request:
branches: master branches: master

View File

@@ -49,6 +49,7 @@ jobs:
sudo apt-get update sudo apt-get update
sudo apt-get install -y cmake build-essential git \ sudo apt-get install -y cmake build-essential git \
libglfw3-dev libfreetype6-dev libfontconfig1-dev \ libglfw3-dev libfreetype6-dev libfontconfig1-dev \
zlib1g-dev libharfbuzz-dev \
libx11-dev libxrandr-dev libxi-dev libgtk-3-dev \ libx11-dev libxrandr-dev libxi-dev libgtk-3-dev \
mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev \ mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev \
libxinerama-dev libxcursor-dev libxkbcommon-dev libxinerama-dev libxcursor-dev libxkbcommon-dev
@@ -83,6 +84,7 @@ jobs:
run: | run: |
dnf install -y cmake gcc gcc-c++ make rpm-build git \ dnf install -y cmake gcc gcc-c++ make rpm-build git \
glfw-devel freetype-devel fontconfig-devel \ glfw-devel freetype-devel fontconfig-devel \
zlib-devel harfbuzz-devel \
libX11-devel libXrandr-devel libXi-devel \ libX11-devel libXrandr-devel libXi-devel \
mesa-libGL-devel mesa-libGLU-devel \ mesa-libGL-devel mesa-libGLU-devel \
libXinerama-devel libXcursor-devel \ libXinerama-devel libXcursor-devel \

1
.gitignore vendored
View File

@@ -4,6 +4,7 @@
out out
build/ build/
build-msvc/
CMakeCache.txt CMakeCache.txt
CMakeFiles/ CMakeFiles/
cmake_install.cmake cmake_install.cmake

18
.vscode/launch.json vendored
View File

@@ -5,7 +5,7 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Debug current target", "name": "Debug current target (GDB)",
"type": "cppdbg", "type": "cppdbg",
"request": "launch", "request": "launch",
"program": "${command:cmake.launchTargetPath}", "program": "${command:cmake.launchTargetPath}",
@@ -31,6 +31,22 @@
"ignoreFailures": true "ignoreFailures": true
} }
] ]
},
{
"name": "Debug current target (LLDB)",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [
"--apply",
"--theme",
"dark"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
}, },
] ]
} }

View File

@@ -1,6 +1,6 @@
# Maintainer: Daniel Dada <dan@binarygoose.dev> # Maintainer: Daniel Dada <dan@binarygoose.dev>
pkgname=clrsync pkgname=clrsync
pkgver=0.1.5 pkgver=0.1.7
pkgrel=1 pkgrel=1
pkgdesc="Color scheme manager" pkgdesc="Color scheme manager"
arch=('x86_64') arch=('x86_64')

View File

@@ -10,6 +10,8 @@ depends=(
glfw glfw
freetype2 freetype2
fontconfig fontconfig
zlib
harfbuzz
mesa mesa
libglvnd libglvnd
libxcursor libxcursor

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(clrsync VERSION 0.1.5 LANGUAGES CXX) project(clrsync VERSION 0.1.7 LANGUAGES CXX)
include(GNUInstallDirs) include(GNUInstallDirs)
@@ -57,8 +57,8 @@ endif()
message(STATUS "clrsync version: ${SEMVER}") message(STATUS "clrsync version: ${SEMVER}")
configure_file( configure_file(
${CMAKE_SOURCE_DIR}/src/core/version.hpp.in ${CMAKE_SOURCE_DIR}/src/core/common/version.hpp.in
${CMAKE_SOURCE_DIR}/src/core/version.hpp ${CMAKE_SOURCE_DIR}/src/core/common/version.hpp
@ONLY @ONLY
) )

View File

@@ -1 +1 @@
0.1.5 0.1.7

Binary file not shown.

Before

Width:  |  Height:  |  Size: 370 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@@ -7,7 +7,25 @@ if(WIN32)
freetype freetype
URL https://download.savannah.gnu.org/releases/freetype/freetype-2.14.1.tar.gz URL https://download.savannah.gnu.org/releases/freetype/freetype-2.14.1.tar.gz
) )
set(FT_DISABLE_ZLIB FALSE CACHE BOOL "" FORCE)
set(FT_DISABLE_BZIP2 TRUE CACHE BOOL "" FORCE)
set(FT_DISABLE_PNG TRUE CACHE BOOL "" FORCE)
set(FT_DISABLE_HARFBUZZ FALSE CACHE BOOL "" FORCE)
set(FT_DISABLE_BROTLI TRUE CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(freetype) FetchContent_MakeAvailable(freetype)
elseif(APPLE)
option(USE_SYSTEM_GLFW ON)
find_package(Freetype REQUIRED)
find_package(ZLIB REQUIRED)
find_package(BZip2 REQUIRED)
find_package(PNG REQUIRED)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(HARFBUZZ harfbuzz)
endif()
else() else()
find_package(Freetype REQUIRED) find_package(Freetype REQUIRED)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
@@ -15,22 +33,29 @@ else()
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
find_package(BZip2 REQUIRED) find_package(BZip2 REQUIRED)
find_package(PNG REQUIRED) find_package(PNG REQUIRED)
find_library(BROTLIDEC_LIBRARY NAMES brotlidec)
find_library(BROTLICOMMON_LIBRARY NAMES brotlicommon)
pkg_check_modules(HARFBUZZ harfbuzz) pkg_check_modules(HARFBUZZ harfbuzz)
pkg_check_modules(WAYLAND_CLIENT wayland-client) pkg_check_modules(WAYLAND_CLIENT wayland-client)
pkg_check_modules(WAYLAND_EGL wayland-egl) pkg_check_modules(WAYLAND_EGL wayland-egl)
endif() endif()
if (LINUX) if(LINUX)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0) pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
endif() endif()
if(USE_SYSTEM_GLFW) if(USE_SYSTEM_GLFW)
pkg_check_modules(GLFW REQUIRED glfw3) if(APPLE)
find_package(glfw3 QUIET)
if(glfw3_FOUND)
set(GLFW_FOUND TRUE)
set(GLFW_LIBRARIES glfw)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLFW REQUIRED glfw3)
endif()
else()
pkg_check_modules(GLFW REQUIRED glfw3)
endif()
else() else()
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
@@ -51,23 +76,19 @@ else()
endif() endif()
set(FREETYPE_EXTRA_LIBS "") set(FREETYPE_EXTRA_LIBS "")
if(BROTLIDEC_LIBRARY AND BROTLICOMMON_LIBRARY)
list(APPEND FREETYPE_EXTRA_LIBS ${BROTLIDEC_LIBRARY} ${BROTLICOMMON_LIBRARY})
message(STATUS "Found Brotli libraries")
endif()
if(HARFBUZZ_FOUND) if(HARFBUZZ_FOUND)
list(APPEND FREETYPE_EXTRA_LIBS ${HARFBUZZ_LIBRARIES}) list(APPEND FREETYPE_EXTRA_LIBS ${HARFBUZZ_LIBRARIES})
message(STATUS "Found HarfBuzz") message(STATUS "Found HarfBuzz")
endif() endif()
set(WAYLAND_LIBS "") set(WAYLAND_LIBS "")
if(WAYLAND_CLIENT_FOUND) if(NOT APPLE)
list(APPEND WAYLAND_LIBS ${WAYLAND_CLIENT_LIBRARIES}) if(WAYLAND_CLIENT_FOUND)
message(STATUS "Found Wayland client") list(APPEND WAYLAND_LIBS ${WAYLAND_CLIENT_LIBRARIES})
message(STATUS "Found Wayland client")
endif()
if(WAYLAND_EGL_FOUND)
list(APPEND WAYLAND_LIBS ${WAYLAND_EGL_LIBRARIES})
message(STATUS "Found Wayland EGL")
endif()
endif() endif()
if(WAYLAND_EGL_FOUND)
list(APPEND WAYLAND_LIBS ${WAYLAND_EGL_LIBRARIES})
message(STATUS "Found Wayland EGL")
endif()

View File

@@ -27,7 +27,7 @@ set(CPACK_NSIS_CREATE_DESKTOP_LINKS "bin/clrsync_gui.exe;clrsync")
# Debian # Debian
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Daniel Dada <dan@binarygoose.dev>") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Daniel Dada <dan@binarygoose.dev>")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.31), libglfw3, libfreetype6") set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.31), libglfw3, libfreetype6, zlib1g, libharfbuzz0b")
set(CPACK_DEBIAN_PACKAGE_SECTION "utils") set(CPACK_DEBIAN_PACKAGE_SECTION "utils")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
@@ -36,6 +36,6 @@ set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_RPM_PACKAGE_LICENSE "MIT") set(CPACK_RPM_PACKAGE_LICENSE "MIT")
set(CPACK_RPM_PACKAGE_GROUP "Applications/System") set(CPACK_RPM_PACKAGE_GROUP "Applications/System")
set(CPACK_RPM_PACKAGE_URL "https://github.com/obsqrbtz/clrsync") set(CPACK_RPM_PACKAGE_URL "https://github.com/obsqrbtz/clrsync")
set(CPACK_RPM_PACKAGE_REQUIRES "freetype, glfw, fontconfig") set(CPACK_RPM_PACKAGE_REQUIRES "freetype, glfw, fontconfig, zlib, harfbuzz")
include(CPack) include(CPack)

View File

@@ -1,5 +1,5 @@
[general] [general]
default_theme = 'cursed' default_theme = 'dark'
palettes_path = '~/.config/clrsync/palettes' palettes_path = '~/.config/clrsync/palettes'
font = 'JetBrainsMono Nerd Font Mono' font = 'JetBrainsMono Nerd Font Mono'
font_size = 14 font_size = 14

View File

@@ -1,67 +0,0 @@
[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"
[general]
name = 'cursed-light'

View File

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

View File

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

View File

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

54
extra/palettes/nord.toml Normal file
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'

6
flake.lock generated
View File

@@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1764950072, "lastModified": 1765779637,
"narHash": "sha256-BmPWzogsG2GsXZtlT+MTcAWeDK5hkbGRZTeZNW42fwA=", "narHash": "sha256-KJ2wa/BLSrTqDjbfyNx70ov/HdgNBCBBSQP3BIzKnv4=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "f61125a668a320878494449750330ca58b78c557", "rev": "1306659b587dc277866c7b69eb97e5f07864d8c4",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -5,6 +5,7 @@
git, git,
pkg-config, pkg-config,
makeWrapper, makeWrapper,
wrapGAppsHook3,
wayland-protocols, wayland-protocols,
glfw, glfw,
freetype, freetype,
@@ -17,7 +18,9 @@
bzip2, bzip2,
wayland-scanner, wayland-scanner,
gtk3, gtk3,
semver glib,
gsettings-desktop-schemas,
semver,
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
@@ -49,6 +52,7 @@ stdenv.mkDerivation rec {
git git
pkg-config pkg-config
makeWrapper makeWrapper
wrapGAppsHook3
wayland-protocols wayland-protocols
]; ];
@@ -69,6 +73,8 @@ stdenv.mkDerivation rec {
zlib zlib
bzip2 bzip2
gtk3 gtk3
gsettings-desktop-schemas
glib
]; ];
cmakeFlags = [ cmakeFlags = [
@@ -82,21 +88,17 @@ stdenv.mkDerivation rec {
cmake --install . --prefix $out cmake --install . --prefix $out
wrapProgram $out/bin/clrsync_gui \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs}
wrapProgram $out/bin/clrsync_cli \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs}
runHook postInstall runHook postInstall
''; '';
dontWrapGApps = false;
meta = with lib; { meta = with lib; {
description = "Color scheme manager with GUI and CLI"; description = "Color scheme manager with GUI and CLI";
homepage = "https://github.com/obsqrbtz/clrsync"; homepage = "https://github.com/obsqrbtz/clrsync";
license = licenses.mit; license = licenses.mit;
platforms = platforms.linux; platforms = platforms.linux;
mainProgram = "clrsync_gui"; mainProgram = "clrsync_gui";
maintainers = [ ]; maintainers = [ "Daniel Dada" ];
}; };
} }

View File

@@ -4,15 +4,15 @@
#include <argparse/argparse.hpp> #include <argparse/argparse.hpp>
#include <core/config/config.hpp> #include "core/common/error.hpp"
#include <core/error.hpp> #include "core/common/utils.hpp"
#include <core/io/toml_file.hpp> #include "core/common/version.hpp"
#include <core/palette/palette_file.hpp> #include "core/config/config.hpp"
#include <core/palette/palette_manager.hpp> #include "core/io/toml_file.hpp"
#include <core/theme/theme_renderer.hpp> #include "core/palette/palette_file.hpp"
#include <core/theme/theme_template.hpp> #include "core/palette/palette_manager.hpp"
#include <core/utils.hpp> #include "core/theme/theme_renderer.hpp"
#include <core/version.hpp> #include "core/theme/theme_template.hpp"
void handle_show_vars() void handle_show_vars()
{ {

View File

@@ -2,8 +2,8 @@ set(CORE_SOURCES
palette/color.cpp palette/color.cpp
io/toml_file.cpp io/toml_file.cpp
config/config.cpp config/config.cpp
utils.cpp common/utils.cpp
version.cpp common/version.cpp
theme/theme_template.cpp theme/theme_template.cpp
) )

266
src/core/common/error.hpp Normal file
View File

@@ -0,0 +1,266 @@
#ifndef CLRSYNC_CORE_ERROR_HPP
#define CLRSYNC_CORE_ERROR_HPP
#include <optional>
#include <string>
#include <variant>
namespace clrsync::core
{
enum class error_code
{
unknown,
file_not_found,
file_open_failed,
file_write_failed,
file_read_failed,
dir_create_failed,
parse_failed,
invalid_format,
config_missing,
config_invalid,
template_not_found,
template_load_failed,
template_apply_failed,
palette_not_found,
palette_load_failed,
init_failed,
invalid_arg,
resource_missing,
};
inline const char *error_code_string(error_code code)
{
switch (code)
{
case error_code::unknown:
return "Unknown error";
case error_code::file_not_found:
return "File not found";
case error_code::file_open_failed:
return "Failed to open file";
case error_code::file_write_failed:
return "Failed to write file";
case error_code::file_read_failed:
return "Failed to read file";
case error_code::dir_create_failed:
return "Failed to create directory";
case error_code::parse_failed:
return "Parse failed";
case error_code::invalid_format:
return "Invalid format";
case error_code::config_missing:
return "Configuration missing";
case error_code::config_invalid:
return "Configuration invalid";
case error_code::template_not_found:
return "Template not found";
case error_code::template_load_failed:
return "Failed to load template";
case error_code::template_apply_failed:
return "Failed to apply template";
case error_code::palette_not_found:
return "Palette not found";
case error_code::palette_load_failed:
return "Failed to load palette";
case error_code::init_failed:
return "Initialization failed";
case error_code::invalid_arg:
return "Invalid argument";
case error_code::resource_missing:
return "Resource missing";
default:
return "Unknown error code";
}
}
struct Error
{
error_code code;
std::string message;
std::string context;
Error(error_code c) : code(c), message(error_code_string(c))
{
}
Error(error_code c, std::string msg) : code(c), message(std::move(msg))
{
}
Error(error_code c, std::string msg, std::string ctx)
: code(c), message(std::move(msg)), context(std::move(ctx))
{
}
std::string description() const
{
if (context.empty())
return message;
return message + " [" + context + "]";
}
};
template <typename T> class [[nodiscard]] Result
{
private:
std::variant<T, Error> m_data;
public:
Result(T value) : m_data(std::move(value))
{
}
Result(Error error) : m_data(std::move(error))
{
}
bool is_ok() const
{
return std::holds_alternative<T>(m_data);
}
bool is_error() const
{
return std::holds_alternative<Error>(m_data);
}
explicit operator bool() const
{
return is_ok();
}
T &value() &
{
return std::get<T>(m_data);
}
const T &value() const &
{
return std::get<T>(m_data);
}
T &&value() &&
{
return std::get<T>(std::move(m_data));
}
const Error &error() const
{
return std::get<Error>(m_data);
}
T value_or(T default_value) const
{
return is_ok() ? std::get<T>(m_data) : std::move(default_value);
}
std::optional<T> ok() const
{
if (is_ok())
return std::get<T>(m_data);
return std::nullopt;
}
std::optional<Error> err() const
{
if (is_error())
return std::get<Error>(m_data);
return std::nullopt;
}
template <typename F> auto map(F &&func) -> Result<decltype(func(std::declval<T>()))>
{
using U = decltype(func(std::declval<T>()));
if (is_ok())
return Result<U>(func(std::get<T>(m_data)));
return Result<U>(std::get<Error>(m_data));
}
template <typename F> auto and_then(F &&func) -> decltype(func(std::declval<T>()))
{
if (is_ok())
return func(std::get<T>(m_data));
using ResultType = decltype(func(std::declval<T>()));
return ResultType(std::get<Error>(m_data));
}
};
template <> class [[nodiscard]] Result<void>
{
private:
std::optional<Error> m_error;
public:
Result() : m_error(std::nullopt)
{
}
Result(Error error) : m_error(std::move(error))
{
}
bool is_ok() const
{
return !m_error.has_value();
}
bool is_error() const
{
return m_error.has_value();
}
explicit operator bool() const
{
return is_ok();
}
const Error &error() const
{
return *m_error;
}
std::optional<Error> err() const
{
return m_error;
}
};
template <typename T> Result<T> Ok(T value)
{
return Result<T>(std::move(value));
}
inline Result<void> Ok()
{
return Result<void>();
}
template <typename T> Result<T> Err(Error error)
{
return Result<T>(std::move(error));
}
template <typename T> Result<T> Err(error_code code)
{
return Result<T>(Error(code));
}
template <typename T> Result<T> Err(error_code code, std::string message)
{
return Result<T>(Error(code, std::move(message)));
}
template <typename T> Result<T> Err(error_code code, std::string message, std::string context)
{
return Result<T>(Error(code, std::move(message), std::move(context)));
}
} // namespace clrsync::core
#endif // CLRSYNC_CORE_ERROR_HPP

View File

@@ -1,6 +1,6 @@
#include "utils.hpp" #include "utils.hpp"
#include <iostream>
#include <filesystem> #include <filesystem>
#include <iostream>
namespace clrsync::core namespace clrsync::core
{ {
@@ -14,7 +14,7 @@ void print_color_keys()
std::string get_default_config_path() std::string get_default_config_path()
{ {
const char* env_path = std::getenv("CLRSYNC_CONFIG_PATH"); const char *env_path = std::getenv("CLRSYNC_CONFIG_PATH");
if (env_path && env_path[0] != '\0') if (env_path && env_path[0] != '\0')
return normalize_path(env_path).string(); return normalize_path(env_path).string();

View File

@@ -1,10 +1,10 @@
#ifndef CLRSYNC_CORE_UTILS_HPP #ifndef CLRSYNC_CORE_UTILS_HPP
#define CLRSYNC_CORE_UTILS_HPP #define CLRSYNC_CORE_UTILS_HPP
#include <string>
#include <filesystem> #include <filesystem>
#include <string>
#include <core/palette/color_keys.hpp> #include "core/palette/color_keys.hpp"
namespace clrsync::core namespace clrsync::core
{ {

View File

@@ -1,4 +1,4 @@
#include "version.hpp" #include "core/common/version.hpp"
namespace clrsync::core namespace clrsync::core
{ {

View File

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

View File

@@ -1,8 +1,9 @@
#include "config.hpp" #include "config.hpp"
#include "core/utils.hpp" #include "core/common/error.hpp"
#include "core/error.hpp" #include "core/common/utils.hpp"
#include "core/io/toml_file.hpp"
#include <core/palette/color.hpp> #include "core/palette/color.hpp"
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@@ -28,7 +29,39 @@ Result<void> config::initialize(std::unique_ptr<clrsync::core::io::file> file)
auto parse_result = m_file->parse(); auto parse_result = m_file->parse();
if (!parse_result) if (!parse_result)
return Err<void>(error_code::config_invalid, parse_result.error().message, parse_result.error().context); return Err<void>(error_code::config_invalid, parse_result.error().message,
parse_result.error().context);
std::filesystem::path config_path = get_user_config_dir() / "config.toml";
std::filesystem::path temp_config_path = get_user_config_dir() / "config-temp.toml";
if (std::filesystem::exists(config_path))
{
std::error_code ec;
auto perms = std::filesystem::status(config_path, ec).permissions();
if (ec || (perms & std::filesystem::perms::owner_write) == std::filesystem::perms::none)
{
m_temp_config_path = temp_config_path.string();
if (std::filesystem::exists(temp_config_path))
{
try
{
auto temp_conf = std::make_unique<clrsync::core::io::toml_file>(temp_config_path.string());
auto temp_parse = temp_conf->parse();
if (temp_parse)
{
m_temp_file = std::move(temp_conf);
}
}
catch (const std::exception &e)
{
std::cerr << "Warning: Failed to load temp config: " << e.what() << std::endl;
}
}
}
}
return Ok(); return Ok();
} }
@@ -39,6 +72,30 @@ std::filesystem::path config::get_user_config_dir()
return home / ".config" / "clrsync"; return home / ".config" / "clrsync";
} }
std::filesystem::path config::get_user_state_dir()
{
std::filesystem::path home = normalize_path("~");
return home / ".local" / "state" / "clrsync";
}
std::filesystem::path config::get_writable_config_path()
{
std::filesystem::path config_path = get_user_config_dir() / "config.toml";
if (std::filesystem::exists(config_path))
{
std::error_code ec;
auto perms = std::filesystem::status(config_path, ec).permissions();
if (ec || (perms & std::filesystem::perms::owner_write) == std::filesystem::perms::none)
{
return get_user_config_dir() / "config-temp.toml";
}
}
return config_path;
}
std::filesystem::path config::get_data_dir() std::filesystem::path config::get_data_dir()
{ {
if (std::filesystem::exists(CLRSYNC_DATADIR)) if (std::filesystem::exists(CLRSYNC_DATADIR))
@@ -134,15 +191,50 @@ void config::copy_default_configs()
} }
} }
Result<void> config::save_config_value(const std::string &section, const std::string &key, const value_type &value)
{
if (!m_temp_config_path.empty())
{
if (!m_temp_file)
{
m_temp_file = std::make_unique<clrsync::core::io::toml_file>(m_temp_config_path);
m_temp_file->parse();
}
m_temp_file->set_value(section, key, value);
return m_temp_file->save_file();
}
m_file->set_value(section, key, value);
return m_file->save_file();
}
const std::string &config::palettes_path() const std::string &config::palettes_path()
{ {
if (m_palettes_dir.empty() && m_file) if (m_palettes_dir.empty() && m_file)
{
if (m_temp_file)
{
auto temp_value = m_temp_file->get_string_value("general", "palettes_path");
if (!temp_value.empty())
{
m_palettes_dir = temp_value;
return m_palettes_dir;
}
}
m_palettes_dir = m_file->get_string_value("general", "palettes_path"); m_palettes_dir = m_file->get_string_value("general", "palettes_path");
}
return m_palettes_dir; return m_palettes_dir;
} }
const std::string config::default_theme() const const std::string config::default_theme() const
{ {
if (m_temp_file)
{
auto temp_value = m_temp_file->get_string_value("general", "default_theme");
if (!temp_value.empty())
return temp_value;
}
if (m_file) if (m_file)
return m_file->get_string_value("general", "default_theme"); return m_file->get_string_value("general", "default_theme");
return {}; return {};
@@ -150,6 +242,12 @@ const std::string config::default_theme() const
const std::string config::font() const const std::string config::font() const
{ {
if (m_temp_file)
{
auto temp_value = m_temp_file->get_string_value("general", "font");
if (!temp_value.empty())
return temp_value;
}
if (m_file) if (m_file)
return m_file->get_string_value("general", "font"); return m_file->get_string_value("general", "font");
return {}; return {};
@@ -157,6 +255,12 @@ const std::string config::font() const
const uint32_t config::font_size() const const uint32_t config::font_size() const
{ {
if (m_temp_file)
{
auto temp_value = m_temp_file->get_uint_value("general", "font_size");
if (temp_value != 0)
return temp_value;
}
if (m_file) if (m_file)
return m_file->get_uint_value("general", "font_size"); return m_file->get_uint_value("general", "font_size");
return 14; return 14;
@@ -167,8 +271,7 @@ Result<void> config::set_default_theme(const std::string &theme)
if (!m_file) if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized"); return Err<void>(error_code::config_missing, "Configuration not initialized");
m_file->set_value("general", "default_theme", theme); return save_config_value("general", "default_theme", theme);
return m_file->save_file();
} }
Result<void> config::set_palettes_path(const std::string &path) Result<void> config::set_palettes_path(const std::string &path)
@@ -176,8 +279,7 @@ Result<void> config::set_palettes_path(const std::string &path)
if (!m_file) if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized"); return Err<void>(error_code::config_missing, "Configuration not initialized");
m_file->set_value("general", "palettes_path", path); return save_config_value("general", "palettes_path", path);
return m_file->save_file();
} }
Result<void> config::set_font(const std::string &font) Result<void> config::set_font(const std::string &font)
@@ -185,30 +287,34 @@ Result<void> config::set_font(const std::string &font)
if (!m_file) if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized"); return Err<void>(error_code::config_missing, "Configuration not initialized");
m_file->set_value("general", "font", font); return save_config_value("general", "font", font);
return m_file->save_file();
} }
Result<void> config::set_font_size(int font_size) Result<void> config::set_font_size(int font_size)
{ {
if (!m_file) if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized"); return Err<void>(error_code::config_missing, "Configuration not initialized");
m_file->set_value("general", "font_size", font_size); return save_config_value("general", "font_size", static_cast<uint32_t>(font_size));
return m_file->save_file();
} }
Result<void> config::update_template(const std::string &key, Result<void> config::update_template(const std::string &key,
const clrsync::core::theme_template &theme_template) const clrsync::core::theme_template &theme_template)
{ {
if (!m_file) if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized"); return Err<void>(error_code::config_missing, "Configuration not initialized");
m_themes[key] = theme_template; m_themes[key] = theme_template;
m_file->set_value("templates." + key, "input_path", theme_template.template_path());
m_file->set_value("templates." + key, "output_path", theme_template.output_path()); auto result1 = save_config_value("templates." + key, "input_path", theme_template.template_path());
m_file->set_value("templates." + key, "enabled", theme_template.enabled()); if (!result1) return result1;
m_file->set_value("templates." + key, "reload_cmd", theme_template.reload_command());
return m_file->save_file(); auto result2 = save_config_value("templates." + key, "output_path", theme_template.output_path());
if (!result2) return result2;
auto result3 = save_config_value("templates." + key, "enabled", theme_template.enabled());
if (!result3) return result3;
return save_config_value("templates." + key, "reload_cmd", theme_template.reload_command());
} }
Result<void> config::remove_template(const std::string &key) Result<void> config::remove_template(const std::string &key)
@@ -223,17 +329,31 @@ Result<void> config::remove_template(const std::string &key)
std::filesystem::path template_file = it->second.template_path(); std::filesystem::path template_file = it->second.template_path();
if (std::filesystem::exists(template_file)) if (std::filesystem::exists(template_file))
{ {
try { try
{
std::filesystem::remove(template_file); std::filesystem::remove(template_file);
} catch (const std::exception& e) { }
return Err<void>(error_code::file_write_failed, "Failed to delete template file", e.what()); catch (const std::exception &e)
{
return Err<void>(error_code::file_write_failed, "Failed to delete template file",
e.what());
} }
} }
m_themes.erase(it); m_themes.erase(it);
m_file->remove_section("templates." + key); if (!m_temp_config_path.empty())
{
if (!m_temp_file)
{
m_temp_file = std::make_unique<clrsync::core::io::toml_file>(m_temp_config_path);
m_temp_file->parse();
}
m_temp_file->remove_section("templates." + key);
return m_temp_file->save_file();
}
m_file->remove_section("templates." + key);
return m_file->save_file(); return m_file->save_file();
} }
@@ -264,14 +384,16 @@ const std::unordered_map<std::string, clrsync::core::theme_template> config::tem
return m_themes; return m_themes;
} }
Result<const clrsync::core::theme_template*> config::template_by_name(const std::string &name) const Result<const clrsync::core::theme_template *> config::template_by_name(
const std::string &name) const
{ {
auto it = m_themes.find(name); auto it = m_themes.find(name);
if (it != m_themes.end()) if (it != m_themes.end())
{ {
return Ok(&it->second); return Ok(&it->second);
} }
return Err<const clrsync::core::theme_template*>(error_code::template_not_found, "Template not found", name); return Err<const clrsync::core::theme_template *>(error_code::template_not_found,
"Template not found", name);
} }
} // namespace clrsync::core } // namespace clrsync::core

View File

@@ -1,9 +1,9 @@
#ifndef CLRSYNC_CORE_CONFIG_HPP #ifndef CLRSYNC_CORE_CONFIG_HPP
#define CLRSYNC_CORE_CONFIG_HPP #define CLRSYNC_CORE_CONFIG_HPP
#include <core/io/file.hpp> #include "core/common/error.hpp"
#include <core/theme/theme_template.hpp> #include "core/io/file.hpp"
#include <core/error.hpp> #include "core/theme/theme_template.hpp"
#include <filesystem> #include <filesystem>
#include <memory> #include <memory>
#include <string> #include <string>
@@ -22,9 +22,10 @@ class config
const std::string &palettes_path(); const std::string &palettes_path();
const std::string default_theme() const; const std::string default_theme() const;
const std::unordered_map<std::string, clrsync::core::theme_template> templates(); const std::unordered_map<std::string, clrsync::core::theme_template> templates();
Result<const clrsync::core::theme_template*> template_by_name(const std::string &name) const; Result<const clrsync::core::theme_template *> template_by_name(const std::string &name) const;
std::filesystem::path get_user_config_dir(); std::filesystem::path get_user_config_dir();
std::filesystem::path get_user_state_dir();
std::filesystem::path get_writable_config_path();
Result<void> set_default_theme(const std::string &theme); Result<void> set_default_theme(const std::string &theme);
Result<void> set_palettes_path(const std::string &path); Result<void> set_palettes_path(const std::string &path);
@@ -32,7 +33,7 @@ class config
Result<void> set_font_size(int font_size); Result<void> set_font_size(int font_size);
Result<void> update_template(const std::string &key, Result<void> update_template(const std::string &key,
const clrsync::core::theme_template &theme_template); const clrsync::core::theme_template &theme_template);
Result<void> remove_template(const std::string &key); Result<void> remove_template(const std::string &key);
static std::filesystem::path get_data_dir(); static std::filesystem::path get_data_dir();
@@ -43,9 +44,12 @@ class config
std::string m_palettes_dir{}; std::string m_palettes_dir{};
std::unique_ptr<io::file> m_file; std::unique_ptr<io::file> m_file;
std::unique_ptr<io::file> m_temp_file;
std::string m_temp_config_path;
std::unordered_map<std::string, theme_template> m_themes{}; std::unordered_map<std::string, theme_template> m_themes{};
static void copy_file(const std::filesystem::path& src, const std::filesystem::path& dst); Result<void> save_config_value(const std::string &section, const std::string &key, const value_type &value);
static void copy_dir(const std::filesystem::path& src, const std::filesystem::path& dst); static void copy_file(const std::filesystem::path &src, const std::filesystem::path &dst);
static void copy_dir(const std::filesystem::path &src, const std::filesystem::path &dst);
void copy_default_configs(); void copy_default_configs();
}; };
} // namespace clrsync::core } // namespace clrsync::core

View File

@@ -1,207 +0,0 @@
#ifndef CLRSYNC_CORE_ERROR_HPP
#define CLRSYNC_CORE_ERROR_HPP
#include <string>
#include <variant>
#include <optional>
namespace clrsync::core
{
enum class error_code
{
unknown,
file_not_found,
file_open_failed,
file_write_failed,
file_read_failed,
dir_create_failed,
parse_failed,
invalid_format,
config_missing,
config_invalid,
template_not_found,
template_load_failed,
template_apply_failed,
palette_not_found,
palette_load_failed,
init_failed,
invalid_arg,
resource_missing,
};
inline const char* error_code_string(error_code code)
{
switch (code)
{
case error_code::unknown: return "Unknown error";
case error_code::file_not_found: return "File not found";
case error_code::file_open_failed: return "Failed to open file";
case error_code::file_write_failed: return "Failed to write file";
case error_code::file_read_failed: return "Failed to read file";
case error_code::dir_create_failed: return "Failed to create directory";
case error_code::parse_failed: return "Parse failed";
case error_code::invalid_format: return "Invalid format";
case error_code::config_missing: return "Configuration missing";
case error_code::config_invalid: return "Configuration invalid";
case error_code::template_not_found: return "Template not found";
case error_code::template_load_failed: return "Failed to load template";
case error_code::template_apply_failed: return "Failed to apply template";
case error_code::palette_not_found: return "Palette not found";
case error_code::palette_load_failed: return "Failed to load palette";
case error_code::init_failed: return "Initialization failed";
case error_code::invalid_arg: return "Invalid argument";
case error_code::resource_missing: return "Resource missing";
default: return "Unknown error code";
}
}
struct Error
{
error_code code;
std::string message;
std::string context;
Error(error_code c) : code(c), message(error_code_string(c)) {}
Error(error_code c, std::string msg)
: code(c), message(std::move(msg)) {}
Error(error_code c, std::string msg, std::string ctx)
: code(c), message(std::move(msg)), context(std::move(ctx)) {}
std::string description() const
{
if (context.empty())
return message;
return message + " [" + context + "]";
}
};
template<typename T>
class [[nodiscard]] Result
{
private:
std::variant<T, Error> m_data;
public:
Result(T value) : m_data(std::move(value)) {}
Result(Error error) : m_data(std::move(error)) {}
bool is_ok() const { return std::holds_alternative<T>(m_data); }
bool is_error() const { return std::holds_alternative<Error>(m_data); }
explicit operator bool() const { return is_ok(); }
T& value() & { return std::get<T>(m_data); }
const T& value() const & { return std::get<T>(m_data); }
T&& value() && { return std::get<T>(std::move(m_data)); }
const Error& error() const { return std::get<Error>(m_data); }
T value_or(T default_value) const
{
return is_ok() ? std::get<T>(m_data) : std::move(default_value);
}
std::optional<T> ok() const
{
if (is_ok())
return std::get<T>(m_data);
return std::nullopt;
}
std::optional<Error> err() const
{
if (is_error())
return std::get<Error>(m_data);
return std::nullopt;
}
template<typename F>
auto map(F&& func) -> Result<decltype(func(std::declval<T>()))>
{
using U = decltype(func(std::declval<T>()));
if (is_ok())
return Result<U>(func(std::get<T>(m_data)));
return Result<U>(std::get<Error>(m_data));
}
template<typename F>
auto and_then(F&& func) -> decltype(func(std::declval<T>()))
{
if (is_ok())
return func(std::get<T>(m_data));
using ResultType = decltype(func(std::declval<T>()));
return ResultType(std::get<Error>(m_data));
}
};
template<>
class [[nodiscard]] Result<void>
{
private:
std::optional<Error> m_error;
public:
Result() : m_error(std::nullopt) {}
Result(Error error) : m_error(std::move(error)) {}
bool is_ok() const { return !m_error.has_value(); }
bool is_error() const { return m_error.has_value(); }
explicit operator bool() const { return is_ok(); }
const Error& error() const { return *m_error; }
std::optional<Error> err() const { return m_error; }
};
template<typename T>
Result<T> Ok(T value)
{
return Result<T>(std::move(value));
}
inline Result<void> Ok()
{
return Result<void>();
}
template<typename T>
Result<T> Err(Error error)
{
return Result<T>(std::move(error));
}
template<typename T>
Result<T> Err(error_code code)
{
return Result<T>(Error(code));
}
template<typename T>
Result<T> Err(error_code code, std::string message)
{
return Result<T>(Error(code, std::move(message)));
}
template<typename T>
Result<T> Err(error_code code, std::string message, std::string context)
{
return Result<T>(Error(code, std::move(message), std::move(context)));
}
} // namespace clrsync::core
#endif // CLRSYNC_CORE_ERROR_HPP

View File

@@ -1,10 +1,10 @@
#ifndef CLRSYNC_CORE_IO_FILE_HPP #ifndef CLRSYNC_CORE_IO_FILE_HPP
#define CLRSYNC_CORE_IO_FILE_HPP #define CLRSYNC_CORE_IO_FILE_HPP
#include "core/common/error.hpp"
#include <cstdint> #include <cstdint>
#include <map> #include <map>
#include <string> #include <string>
#include <variant> #include <variant>
#include <core/error.hpp>
using value_type = std::variant<std::string, uint32_t, int, bool>; using value_type = std::variant<std::string, uint32_t, int, bool>;
@@ -16,7 +16,10 @@ class file
file() = default; file() = default;
file(std::string path) {}; file(std::string path) {};
virtual ~file() = default; virtual ~file() = default;
virtual Result<void> parse() { return Ok(); }; virtual Result<void> parse()
{
return Ok();
};
virtual const std::string get_string_value(const std::string &section, virtual const std::string get_string_value(const std::string &section,
const std::string &key) const const std::string &key) const
{ {
@@ -35,14 +38,17 @@ class file
return {}; return {};
} }
virtual void set_value(const std::string &section, const std::string &key, virtual void set_value(const std::string &section, const std::string &key,
const value_type &value) const value_type &value)
{ {
insert_or_update_value(section, key, value); insert_or_update_value(section, key, value);
} }
virtual void insert_or_update_value(const std::string &section, const std::string &key, virtual void insert_or_update_value(const std::string &section, const std::string &key,
const value_type &value) {}; const value_type &value) {};
virtual void remove_section(const std::string &section) {}; virtual void remove_section(const std::string &section) {};
virtual Result<void> save_file() { return Ok(); }; virtual Result<void> save_file()
{
return Ok();
};
}; };
} // namespace clrsync::core::io } // namespace clrsync::core::io
#endif #endif

View File

@@ -1,5 +1,5 @@
#include "toml_file.hpp" #include "core/io/toml_file.hpp"
#include "core/utils.hpp" #include "core/common/utils.hpp"
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <vector> #include <vector>
@@ -113,9 +113,12 @@ void toml_file::remove_section(const std::string &section)
Result<void> toml_file::save_file() Result<void> toml_file::save_file()
{ {
try { try
{
std::filesystem::create_directories(std::filesystem::path(m_path).parent_path()); std::filesystem::create_directories(std::filesystem::path(m_path).parent_path());
} catch (const std::exception& e) { }
catch (const std::exception &e)
{
return Err<void>(error_code::dir_create_failed, e.what(), m_path); return Err<void>(error_code::dir_create_failed, e.what(), m_path);
} }

View File

@@ -1,7 +1,7 @@
#ifndef CLRSYNC_CORE_IO_TOML_FILE_HPP #ifndef CLRSYNC_CORE_IO_TOML_FILE_HPP
#define CLRSYNC_CORE_IO_TOML_FILE_HPP #define CLRSYNC_CORE_IO_TOML_FILE_HPP
#include <core/io/file.hpp> #include "core/common/error.hpp"
#include <core/error.hpp> #include "core/io/file.hpp"
#include <string> #include <string>
#include <toml/toml.hpp> #include <toml/toml.hpp>

View File

@@ -3,7 +3,6 @@
#include <cstdio> #include <cstdio>
#include <format> #include <format>
#include <stdexcept> #include <stdexcept>
#include <unordered_map>
namespace clrsync::core namespace clrsync::core
{ {
@@ -112,14 +111,17 @@ void color::from_hex_string(const std::string &str)
if (str.empty() || str[0] != '#') if (str.empty() || str[0] != '#')
throw std::invalid_argument("Invalid hex color format"); throw std::invalid_argument("Invalid hex color format");
if (str.size() == 7) { if (str.size() == 7)
{
uint32_t rgb = static_cast<uint32_t>(std::stoul(str.substr(1), nullptr, 16)); uint32_t rgb = static_cast<uint32_t>(std::stoul(str.substr(1), nullptr, 16));
m_hex = (rgb << 8) | 0xFF; m_hex = (rgb << 8) | 0xFF;
} }
else if (str.size() == 9) { else if (str.size() == 9)
{
m_hex = static_cast<uint32_t>(std::stoul(str.substr(1), nullptr, 16)); m_hex = static_cast<uint32_t>(std::stoul(str.substr(1), nullptr, 16));
} }
else { else
{
throw std::invalid_argument("Invalid hex color format"); throw std::invalid_argument("Invalid hex color format");
} }
} }
@@ -138,30 +140,38 @@ const std::string color::to_hex_string_with_alpha() const
return std::string(buffer); return std::string(buffer);
} }
std::string color::format(const std::string& field) const std::string color::format(const std::string &field) const
{ {
auto rgb = to_rgb(); auto rgb = to_rgb();
auto rgba = to_rgba(); auto rgba = to_rgba();
auto hslv = to_hsl(); auto hslv = to_hsl();
auto hslav = to_hsla(); auto hslav = to_hsla();
if (field == "hex") return to_hex_string(); if (field == "hex")
if (field == "hex_stripped") { return to_hex_string();
if (field == "hex_stripped")
{
auto s = to_hex_string(); auto s = to_hex_string();
return s.substr(1); return s.substr(1);
} }
if (field == "hexa") return to_hex_string_with_alpha(); if (field == "hexa")
if (field == "hexa_stripped") { return to_hex_string_with_alpha();
if (field == "hexa_stripped")
{
auto s = to_hex_string_with_alpha(); auto s = to_hex_string_with_alpha();
return s.substr(1); return s.substr(1);
} }
if (field == "r") return std::to_string(rgb.r); if (field == "r")
if (field == "g") return std::to_string(rgb.g); return std::to_string(rgb.r);
if (field == "b") return std::to_string(rgb.b); if (field == "g")
return std::to_string(rgb.g);
if (field == "b")
return std::to_string(rgb.b);
if (field == "a") { if (field == "a")
{
float af = rgba.a / 255.0f; float af = rgba.a / 255.0f;
return std::format("{:.2f}", af); return std::format("{:.2f}", af);
} }
@@ -170,9 +180,7 @@ std::string color::format(const std::string& field) const
return std::format("rgb({},{},{})", rgb.r, rgb.g, rgb.b); return std::format("rgb({},{},{})", rgb.r, rgb.g, rgb.b);
if (field == "rgba") if (field == "rgba")
return std::format("rgba({},{},{},{:.2f})", return std::format("rgba({},{},{},{:.2f})", rgba.r, rgba.g, rgba.b, rgba.a / 255.0f);
rgba.r, rgba.g, rgba.b,
rgba.a / 255.0f);
if (field == "h") if (field == "h")
return std::format("{:.0f}", hslv.h); return std::format("{:.0f}", hslv.h);
@@ -186,12 +194,10 @@ std::string color::format(const std::string& field) const
return std::format("{:.2f}", hslav.a); return std::format("{:.2f}", hslav.a);
if (field == "hsl") if (field == "hsl")
return std::format("hsl({:.0f},{:.2f},{:.2f})", return std::format("hsl({:.0f},{:.2f},{:.2f})", hslv.h, hslv.s, hslv.l);
hslv.h, hslv.s, hslv.l);
if (field == "hsla") if (field == "hsla")
return std::format("hsla({:.0f},{:.2f},{:.2f},{:.2f})", return std::format("hsla({:.0f},{:.2f},{:.2f},{:.2f})", hslav.h, hslav.s, hslav.l, hslav.a);
hslav.h, hslav.s, hslav.l, hslav.a);
throw std::runtime_error("Unknown color format: " + field); throw std::runtime_error("Unknown color format: " + field);
} }

View File

@@ -60,7 +60,7 @@ class color
const std::string to_hex_string_with_alpha() const; const std::string to_hex_string_with_alpha() const;
std::string format(const std::string& field) const; std::string format(const std::string &field) const;
void set(uint32_t hex); void set(uint32_t hex);

View File

@@ -3,12 +3,12 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
#include <unordered_map>
#include <string> #include <string>
#include <unordered_map>
namespace clrsync::core namespace clrsync::core
{ {
constexpr const char* COLOR_KEYS[] = { constexpr const char *COLOR_KEYS[] = {
// General UI // General UI
"background", "background",
"on_background", "on_background",
@@ -77,65 +77,65 @@ constexpr const char* COLOR_KEYS[] = {
constexpr size_t NUM_COLOR_KEYS = std::size(COLOR_KEYS); constexpr size_t NUM_COLOR_KEYS = std::size(COLOR_KEYS);
inline const std::unordered_map<std::string, uint32_t> DEFAULT_COLORS = { inline const std::unordered_map<std::string, uint32_t> DEFAULT_COLORS = {
{"background", 0x1e1e1eff}, {"background", 0x111111ff},
{"on_background", 0xd4d4d4ff}, {"on_background", 0xd4d4d4ff},
{"surface", 0x252526ff}, {"surface", 0x111111ff},
{"on_surface", 0xe8e8e8ff}, {"on_surface", 0xd4d4d4ff},
{"surface_variant", 0x2d2d30ff}, {"surface_variant", 0x191919ff},
{"on_surface_variant", 0xccccccff}, {"on_surface_variant", 0xd4d4d4ff},
{"border_focused", 0x007accff}, {"border_focused", 0x2e2e2eff},
{"border", 0x3e3e42ff}, {"border", 0x242424ff},
{"foreground", 0xccccccff}, {"foreground", 0xd2d2d2ff},
{"cursor", 0xaeafadff}, {"cursor", 0xd2d2d2ff},
{"accent", 0x0e639cff}, {"accent", 0x9a8652ff},
{"success", 0x4ec9b0ff}, {"success", 0x668a51ff},
{"info", 0x4fc1ffff}, {"info", 0x3a898cff},
{"warning", 0xdcdcaaff}, {"warning", 0xb47837ff},
{"error", 0xf48771ff}, {"error", 0xaa4e4aff},
{"on_success", 0x000000ff}, {"on_success", 0xd2d2d2ff},
{"on_info", 0x000000ff}, {"on_info", 0xd2d2d2ff},
{"on_warning", 0x000000ff}, {"on_warning", 0xd2d2d2ff},
{"on_error", 0xffffffff}, {"on_error", 0xd2d2d2ff},
{"editor_background", 0x1e1e1eff}, {"editor_background", 0x111111ff},
{"editor_command", 0xd7ba7dff}, {"editor_command", 0x3a898cff},
{"editor_comment", 0x6a9955ff}, {"editor_comment", 0x849899ff},
{"editor_disabled", 0x808080ff}, {"editor_disabled", 0x849899ff},
{"editor_emphasis", 0x569cd6ff}, {"editor_emphasis", 0xa9dc86ff},
{"editor_error", 0xf44747ff}, {"editor_error", 0xaa4e4aff},
{"editor_inactive", 0x858585ff}, {"editor_inactive", 0x849899ff},
{"editor_line_number", 0x858585ff}, {"editor_line_number", 0x849899ff},
{"editor_link", 0x3794ffff}, {"editor_link", 0xb0779eff},
{"editor_main", 0xd4d4d4ff}, {"editor_main", 0xd2d2d2ff},
{"editor_selected", 0x264f78ff}, {"editor_selected", 0x242424ff},
{"editor_selection_inactive", 0x3a3d41ff}, {"editor_selection_inactive", 0x1d1c1cff},
{"editor_string", 0xce9178ff}, {"editor_string", 0x9a8652ff},
{"editor_success", 0x89d185ff}, {"editor_success", 0x668a51ff},
{"editor_warning", 0xcca700ff}, {"editor_warning", 0xb47837ff},
{"base00", 0x181818ff}, {"base00", 0x111111ff},
{"base01", 0x282828ff}, {"base01", 0x668a51ff},
{"base02", 0x383838ff}, {"base02", 0x9a8652ff},
{"base03", 0x585858ff}, {"base03", 0xb47837ff},
{"base04", 0xb8b8b8ff}, {"base04", 0x9a5552ff},
{"base05", 0xd8d8d8ff}, {"base05", 0xaa477bff},
{"base06", 0xe8e8e8ff}, {"base06", 0x3a898cff},
{"base07", 0xf8f8f8ff}, {"base07", 0xb5b5b5ff},
{"base08", 0xab4642ff}, {"base08", 0xaa4e4aff},
{"base09", 0xdc9656ff}, {"base09", 0xa9dc86ff},
{"base0A", 0xf7ca88ff}, {"base0A", 0xb6ab82ff},
{"base0B", 0xa1b56cff}, {"base0B", 0xc5916bff},
{"base0C", 0x86c1b9ff}, {"base0C", 0xac7676ff},
{"base0D", 0x7cafc2ff}, {"base0D", 0xb0779eff},
{"base0E", 0xba8bafff}, {"base0E", 0x849899ff},
{"base0F", 0xa16946ff}, {"base0F", 0xd2d2d2ff},
}; };
} // namespace clrsync::core } // namespace clrsync::core
#endif #endif

View File

@@ -4,8 +4,8 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <core/palette/color.hpp> #include "core/palette/color.hpp"
#include <core/palette/color_keys.hpp> #include "core/palette/color_keys.hpp"
namespace clrsync::core namespace clrsync::core
{ {

View File

@@ -5,9 +5,9 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <core/io/file.hpp> #include "core/io/file.hpp"
#include <core/palette/color_keys.hpp> #include "core/palette/color_keys.hpp"
#include <core/palette/palette.hpp> #include "core/palette/palette.hpp"
#include <memory> #include <memory>

View File

@@ -1,14 +1,13 @@
#ifndef CLRSYNC_CORE_PALETTE_PALETTE_MANAGER_HPP #ifndef CLRSYNC_CORE_PALETTE_PALETTE_MANAGER_HPP
#define CLRSYNC_CORE_PALETTE_PALETTE_MANAGER_HPP #define CLRSYNC_CORE_PALETTE_PALETTE_MANAGER_HPP
#include "core/utils.hpp" #include "core/common/utils.hpp"
#include <iostream>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <core/config/config.hpp> #include "core/config/config.hpp"
#include <core/palette/palette.hpp> #include "core/palette/palette.hpp"
#include <core/palette/palette_file.hpp> #include "core/palette/palette_file.hpp"
#include <filesystem> #include <filesystem>
namespace clrsync::core namespace clrsync::core

View File

@@ -1,17 +1,15 @@
#ifndef CLRSYNC_CORE_THEME_TEMPLATE_MANAGER_HPP #ifndef CLRSYNC_CORE_THEME_TEMPLATE_MANAGER_HPP
#define CLRSYNC_CORE_THEME_TEMPLATE_MANAGER_HPP #define CLRSYNC_CORE_THEME_TEMPLATE_MANAGER_HPP
#include <core/config/config.hpp> #include "core/config/config.hpp"
#include <core/theme/theme_template.hpp> #include "core/theme/theme_template.hpp"
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
namespace clrsync::core namespace clrsync::core
{ {
template <typename FileType> template <typename FileType> class template_manager
class template_manager
{ {
public: public:
template_manager() = default; template_manager() = default;

View File

@@ -1,9 +1,10 @@
#ifndef CLRSYNC_CORE_THEME_THEME_RENDERER_HPP #ifndef CLRSYNC_CORE_THEME_THEME_RENDERER_HPP
#define CLRSYNC_CORE_THEME_THEME_RENDERER_HPP #define CLRSYNC_CORE_THEME_THEME_RENDERER_HPP
#include <core/config/config.hpp> #include "core/common/error.hpp"
#include <core/palette/palette_manager.hpp> #include "core/config/config.hpp"
#include <core/theme/template_manager.hpp> #include "core/palette/palette_manager.hpp"
#include <core/error.hpp> #include "core/theme/template_manager.hpp"
#include <iostream>
#include <string> #include <string>
namespace clrsync::core namespace clrsync::core
@@ -60,7 +61,8 @@ template <typename FileType> class theme_renderer
int result = std::system(tmpl.reload_command().c_str()); int result = std::system(tmpl.reload_command().c_str());
if (result != 0) if (result != 0)
{ {
std::cerr << "Warning: Command " << tmpl.reload_command() << " failed with code " << result << "\n"; std::cerr << "Warning: Command " << tmpl.reload_command()
<< " failed with code " << result << "\n";
} }
} }
} }

View File

@@ -1,5 +1,5 @@
#include "theme_template.hpp" #include "theme_template.hpp"
#include "core/utils.hpp" #include "core/common/utils.hpp"
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@@ -47,13 +47,15 @@ Result<void> theme_template::load_template()
{ {
if (!std::filesystem::exists(m_template_path)) if (!std::filesystem::exists(m_template_path))
{ {
return Err<void>(error_code::template_not_found, "Template file is missing", m_template_path); return Err<void>(error_code::template_not_found, "Template file is missing",
m_template_path);
} }
std::ifstream input(m_template_path, std::ios::binary); std::ifstream input(m_template_path, std::ios::binary);
if (!input) if (!input)
{ {
return Err<void>(error_code::template_load_failed, "Failed to open template file", m_template_path); return Err<void>(error_code::template_load_failed, "Failed to open template file",
m_template_path);
} }
m_template_data.assign(std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()); m_template_data.assign(std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>());
@@ -64,7 +66,7 @@ void theme_template::apply_palette(const core::palette &palette)
{ {
m_processed_data = m_template_data; m_processed_data = m_template_data;
for (const auto& [key, color] : palette.colors()) for (const auto &[key, color] : palette.colors())
{ {
// simple replacement: {foreground} // simple replacement: {foreground}
replace_all(m_processed_data, "{" + key + "}", color.format("hex")); replace_all(m_processed_data, "{" + key + "}", color.format("hex"));
@@ -96,7 +98,7 @@ Result<void> theme_template::save_output() const
{ {
std::filesystem::create_directories(std::filesystem::path(m_output_path).parent_path()); std::filesystem::create_directories(std::filesystem::path(m_output_path).parent_path());
} }
catch (const std::exception& e) catch (const std::exception &e)
{ {
return Err<void>(error_code::dir_create_failed, e.what(), m_output_path); return Err<void>(error_code::dir_create_failed, e.what(), m_output_path);
} }
@@ -104,13 +106,15 @@ Result<void> theme_template::save_output() const
std::ofstream output(m_output_path, std::ios::binary); std::ofstream output(m_output_path, std::ios::binary);
if (!output) if (!output)
{ {
return Err<void>(error_code::file_write_failed, "Failed to open output file for writing", m_output_path); return Err<void>(error_code::file_write_failed, "Failed to open output file for writing",
m_output_path);
} }
output << m_processed_data; output << m_processed_data;
if (!output) if (!output)
{ {
return Err<void>(error_code::file_write_failed, "Failed to write to output file", m_output_path); return Err<void>(error_code::file_write_failed, "Failed to write to output file",
m_output_path);
} }
return Ok(); return Ok();

View File

@@ -1,8 +1,8 @@
#ifndef clrsync_CORE_IO_THEME_TEMPLATE_HPP #ifndef clrsync_CORE_IO_THEME_TEMPLATE_HPP
#define clrsync_CORE_IO_THEME_TEMPLATE_HPP #define clrsync_CORE_IO_THEME_TEMPLATE_HPP
#include <core/palette/palette.hpp> #include "core/common/error.hpp"
#include <core/error.hpp> #include "core/palette/palette.hpp"
#include <string> #include <string>
namespace clrsync::core namespace clrsync::core

View File

@@ -1,22 +1,40 @@
set(GUI_SOURCES set(GUI_SOURCES
main.cpp main.cpp
color_scheme_editor.cpp views/color_scheme_editor.cpp
color_table_renderer.cpp views/color_table_renderer.cpp
preview_renderer.cpp views/preview_renderer.cpp
theme_applier.cpp controllers/theme_applier.cpp
template_editor.cpp views/template_editor.cpp
palette_controller.cpp controllers/palette_controller.cpp
template_controller.cpp controllers/template_controller.cpp
imgui_helpers.cpp helpers/imgui_helpers.cpp
imgui_helpers.hpp helpers/imgui_helpers.hpp
about_window.cpp views/about_window.cpp
settings_window.cpp views/settings_window.cpp
font_loader.cpp platform/windows/font_loader_windows.cpp
file_browser.cpp platform/linux/font_loader_linux.cpp
${CMAKE_SOURCE_DIR}/lib/color_text_edit/TextEditor.cpp platform/macos/font_loader_macos.cpp
platform/linux/file_browser_linux.cpp
platform/windows/file_browser_windows.cpp
${CMAKE_SOURCE_DIR}/lib/color_text_edit/TextEditor.cpp
platform/linux/font_loader_linux.cpp
platform/macos/font_loader_macos.cpp
platform/windows/font_loader_windows.cpp
backend/glfw_opengl.cpp
ui_manager.cpp
) )
add_executable(clrsync_gui ${GUI_SOURCES}) if(MACOS)
list(APPEND GUI_SOURCES
platform/macos/file_browser_macos.mm
)
endif()
if(WIN32)
add_executable(clrsync_gui WIN32 ${GUI_SOURCES})
else()
add_executable(clrsync_gui ${GUI_SOURCES})
endif()
target_include_directories(clrsync_gui PRIVATE target_include_directories(clrsync_gui PRIVATE
${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src
@@ -35,6 +53,9 @@ if(WIN32)
comdlg32 comdlg32
shlwapi shlwapi
) )
if (MSVC)
target_link_options(clrsync_gui PRIVATE /ENTRY:mainCRTStartup)
endif()
elseif(APPLE) elseif(APPLE)
target_link_libraries(clrsync_gui PRIVATE target_link_libraries(clrsync_gui PRIVATE
clrsync_core clrsync_core

View File

@@ -1,21 +0,0 @@
#ifndef CLRSYNC_GUI_ABOUT_WINDOW_HPP
#define CLRSYNC_GUI_ABOUT_WINDOW_HPP
#include "core/palette/palette.hpp"
class about_window
{
public:
about_window();
void render(const clrsync::core::palette& pal);
void render() { render(m_default_palette); }
void show() { m_visible = true; }
void hide() { m_visible = false; }
bool is_visible() const { return m_visible; }
private:
bool m_visible{false};
clrsync::core::palette m_default_palette;
};
#endif // CLRSYNC_GUI_ABOUT_WINDOW_HPP

View File

@@ -0,0 +1,38 @@
#ifndef CLRSYNC_BACKEND_HPP
#define CLRSYNC_BACKEND_HPP
#include <string>
namespace clrsync::gui::backend{
struct window_config{
std::string title = "clrsync";
int width = 1280;
int height = 720;
bool resizable = true;
bool decorated = true;
bool transparent_framebuffer = true;
float clear_color[4] = {0.1f, 0.1f, 0.1f, 0.0f};
};
class backend_interface{
public:
virtual ~backend_interface() = default;
virtual bool initialize(const window_config& config) = 0;
virtual void shutdown() = 0;
virtual bool should_close() const = 0;
virtual void begin_frame() = 0;
virtual void end_frame() = 0;
virtual void* get_native_window() const = 0;
virtual void* get_graphics_context() const = 0;
virtual bool init_imgui_backend() = 0;
virtual void shutdown_imgui_backend() = 0;
virtual void imgui_new_frame() = 0;
virtual void imgui_render_draw_data(void* draw_data) = 0;
};
}
#endif // CLRSYNC_BACKEND_HPP

View File

@@ -0,0 +1,141 @@
#include "gui/backend/glfw_opengl.hpp"
#include <iostream>
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
namespace clrsync::gui::backend
{
glfw_opengl_backend::glfw_opengl_backend() = default;
glfw_opengl_backend::~glfw_opengl_backend()
{
glfw_opengl_backend::shutdown();
}
bool glfw_opengl_backend::initialize(const window_config &config)
{
glfwSetErrorCallback([](int error, const char* description) {
std::cerr << "GLFW Error " << error << ": " << description << std::endl;
});
if (!glfwInit())
{
std::cerr << "Failed to initialize GLFW" << std::endl;
return false;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
#ifdef __APPLE__
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
#else
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
#endif
glfwWindowHint(GLFW_RESIZABLE, config.resizable ? GLFW_TRUE : GLFW_FALSE);
glfwWindowHint(GLFW_DECORATED, config.decorated ? GLFW_TRUE : GLFW_FALSE);
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, config.transparent_framebuffer ? GLFW_TRUE : GLFW_FALSE);
m_window = glfwCreateWindow(config.width, config.height, config.title.c_str(), nullptr, nullptr);
if (!m_window)
{
std::cerr << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return false;
}
glfwMakeContextCurrent(m_window);
glfwSwapInterval(1);
return true;
}
void glfw_opengl_backend::shutdown()
{
if (m_window)
{
glfwDestroyWindow(m_window);
m_window = nullptr;
}
glfwTerminate();
}
bool glfw_opengl_backend::should_close() const
{
return m_window && glfwWindowShouldClose(m_window);
}
void glfw_opengl_backend::begin_frame()
{
glfwPollEvents();
if (m_window)
{
int display_w, display_h;
glfwGetFramebufferSize(m_window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
}
void glfw_opengl_backend::end_frame()
{
if (m_window)
{
glfwSwapBuffers(m_window);
}
}
void *glfw_opengl_backend::get_native_window() const
{
return static_cast<void *>(m_window);
}
void *glfw_opengl_backend::get_graphics_context() const
{
return static_cast<void *>(m_window);
}
bool glfw_opengl_backend::init_imgui_backend()
{
if (!m_window)
return false;
if (!ImGui_ImplGlfw_InitForOpenGL(m_window, true))
return false;
#ifdef __APPLE__
const char* glsl_version = "#version 150";
#else
const char* glsl_version = "#version 120";
#endif
if (!ImGui_ImplOpenGL3_Init(glsl_version))
{
ImGui_ImplGlfw_Shutdown();
return false;
}
return true;
}
void glfw_opengl_backend::shutdown_imgui_backend()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
}
void glfw_opengl_backend::imgui_new_frame()
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
}
void glfw_opengl_backend::imgui_render_draw_data(void* draw_data)
{
ImGui_ImplOpenGL3_RenderDrawData(static_cast<ImDrawData*>(draw_data));
}
} // namespace clrsync::gui::backend

View File

@@ -0,0 +1,36 @@
#ifndef CLRSYNC_GLFW_OPENGL_HPP
#define CLRSYNC_GLFW_OPENGL_HPP
#define GL_SILENCE_DEPRECATION
#include <GLFW/glfw3.h>
#include "gui/backend/backend.hpp"
namespace clrsync::gui::backend{
class glfw_opengl_backend : public backend_interface{
public:
glfw_opengl_backend();
~glfw_opengl_backend();
bool initialize(const window_config& config) override;
void shutdown() override;
bool should_close() const override;
void begin_frame() override;
void end_frame() override;
void* get_native_window() const override;
void* get_graphics_context() const override;
bool init_imgui_backend() override;
void shutdown_imgui_backend() override;
void imgui_new_frame() override;
void imgui_render_draw_data(void* draw_data) override;
private:
GLFWwindow* m_window = nullptr;
};
}
#endif // CLRSYNC_GLFW_OPENGL_HPP

View File

@@ -1,35 +0,0 @@
#ifndef CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP
#define CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP
#include "palette_controller.hpp"
#include "color_table_renderer.hpp"
#include "preview_renderer.hpp"
class template_editor;
class settings_window;
class color_scheme_editor
{
public:
color_scheme_editor();
void render_controls_and_colors();
void render_preview();
void set_template_editor(template_editor* editor) { m_template_editor = editor; }
void set_settings_window(settings_window* window) { m_settings_window = window; }
const palette_controller& controller() const { return m_controller; }
private:
void render_controls();
void apply_themes();
void notify_palette_changed();
palette_controller m_controller;
color_table_renderer m_color_table;
preview_renderer m_preview;
template_editor* m_template_editor{nullptr};
settings_window* m_settings_window{nullptr};
bool m_show_delete_confirmation{false};
};
#endif // CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP

View File

@@ -1,30 +0,0 @@
#ifndef CLRSYNC_GUI_COLOR_TABLE_RENDERER_HPP
#define CLRSYNC_GUI_COLOR_TABLE_RENDERER_HPP
#include "core/palette/palette.hpp"
#include "palette_controller.hpp"
#include <functional>
#include <string>
class color_table_renderer
{
public:
using OnColorChangedCallback = std::function<void()>;
void render(const clrsync::core::palette& palette,
palette_controller& controller,
const OnColorChangedCallback& on_changed);
private:
void render_color_row(const std::string& name,
const clrsync::core::palette& palette,
palette_controller& controller,
const OnColorChangedCallback& on_changed);
bool matches_filter(const std::string& name) const;
char m_filter_text[128] = {0};
bool m_show_only_modified{false};
};
#endif // CLRSYNC_GUI_COLOR_TABLE_RENDERER_HPP

View File

@@ -1,4 +1,4 @@
#include "palette_controller.hpp" #include "gui/controllers/palette_controller.hpp"
#include "core/config/config.hpp" #include "core/config/config.hpp"
#include "core/theme/theme_renderer.hpp" #include "core/theme/theme_renderer.hpp"
@@ -13,26 +13,30 @@ palette_controller::palette_controller()
auto default_theme = clrsync::core::config::instance().default_theme(); auto default_theme = clrsync::core::config::instance().default_theme();
auto it = m_palettes.find(default_theme); auto it = m_palettes.find(default_theme);
if (it != m_palettes.end()) { if (it != m_palettes.end())
{
m_current_palette = it->second; m_current_palette = it->second;
} else { }
else
{
m_current_palette = m_palettes.begin()->second; m_current_palette = m_palettes.begin()->second;
} }
} }
void palette_controller::select_palette(const std::string& name) void palette_controller::select_palette(const std::string &name)
{ {
auto it = m_palettes.find(name); auto it = m_palettes.find(name);
if (it != m_palettes.end()) { if (it != m_palettes.end())
{
m_current_palette = it->second; m_current_palette = it->second;
} }
} }
void palette_controller::create_palette(const std::string& name) void palette_controller::create_palette(const std::string &name)
{ {
clrsync::core::palette new_palette(name); clrsync::core::palette new_palette(name);
for (const auto& [key, hex_value] : clrsync::core::DEFAULT_COLORS) for (const auto &[key, hex_value] : clrsync::core::DEFAULT_COLORS)
{ {
new_palette.set_color(key, clrsync::core::color(hex_value)); new_palette.set_color(key, clrsync::core::color(hex_value));
} }
@@ -63,7 +67,7 @@ void palette_controller::apply_current_theme() const
(void)theme_renderer.apply_theme(m_current_palette.name()); (void)theme_renderer.apply_theme(m_current_palette.name());
} }
void palette_controller::set_color(const std::string& key, const clrsync::core::color& color) void palette_controller::set_color(const std::string &key, const clrsync::core::color &color)
{ {
m_current_palette.set_color(key, color); m_current_palette.set_color(key, color);
} }

View File

@@ -6,21 +6,28 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
class palette_controller { class palette_controller
public: {
public:
palette_controller(); palette_controller();
const clrsync::core::palette& current_palette() const { return m_current_palette; } const clrsync::core::palette &current_palette() const
const std::unordered_map<std::string, clrsync::core::palette>& palettes() const { return m_palettes; } {
return m_current_palette;
}
const std::unordered_map<std::string, clrsync::core::palette> &palettes() const
{
return m_palettes;
}
void select_palette(const std::string& name); void select_palette(const std::string &name);
void create_palette(const std::string& name); void create_palette(const std::string &name);
void save_current_palette(); void save_current_palette();
void delete_current_palette(); void delete_current_palette();
void apply_current_theme() const; void apply_current_theme() const;
void set_color(const std::string& key, const clrsync::core::color& color); void set_color(const std::string &key, const clrsync::core::color &color);
private: private:
void reload_palettes(); void reload_palettes();
clrsync::core::palette_manager<clrsync::core::io::toml_file> m_palette_manager; clrsync::core::palette_manager<clrsync::core::io::toml_file> m_palette_manager;

View File

@@ -1,4 +1,4 @@
#include "template_controller.hpp" #include "gui/controllers/template_controller.hpp"
#include "core/config/config.hpp" #include "core/config/config.hpp"
template_controller::template_controller() template_controller::template_controller()
@@ -6,46 +6,52 @@ template_controller::template_controller()
m_templates = m_template_manager.templates(); m_templates = m_template_manager.templates();
} }
void template_controller::set_template_enabled(const std::string& key, bool enabled) void template_controller::set_template_enabled(const std::string &key, bool enabled)
{ {
auto it = m_templates.find(key); auto it = m_templates.find(key);
if (it != m_templates.end()) { if (it != m_templates.end())
{
it->second.set_enabled(enabled); it->second.set_enabled(enabled);
(void)clrsync::core::config::instance().update_template(key, it->second); (void)clrsync::core::config::instance().update_template(key, it->second);
} }
} }
void template_controller::set_template_input_path(const std::string& key, const std::string& path) void template_controller::set_template_input_path(const std::string &key, const std::string &path)
{ {
auto it = m_templates.find(key); auto it = m_templates.find(key);
if (it != m_templates.end()) { if (it != m_templates.end())
{
it->second.set_template_path(path); it->second.set_template_path(path);
(void)clrsync::core::config::instance().update_template(key, it->second); (void)clrsync::core::config::instance().update_template(key, it->second);
} }
} }
void template_controller::set_template_output_path(const std::string& key, const std::string& path) void template_controller::set_template_output_path(const std::string &key, const std::string &path)
{ {
auto it = m_templates.find(key); auto it = m_templates.find(key);
if (it != m_templates.end()) { if (it != m_templates.end())
{
it->second.set_output_path(path); it->second.set_output_path(path);
(void)clrsync::core::config::instance().update_template(key, it->second); (void)clrsync::core::config::instance().update_template(key, it->second);
} }
} }
void template_controller::set_template_reload_command(const std::string& key, const std::string& cmd) void template_controller::set_template_reload_command(const std::string &key,
const std::string &cmd)
{ {
auto it = m_templates.find(key); auto it = m_templates.find(key);
if (it != m_templates.end()) { if (it != m_templates.end())
{
it->second.set_reload_command(cmd); it->second.set_reload_command(cmd);
(void)clrsync::core::config::instance().update_template(key, it->second); (void)clrsync::core::config::instance().update_template(key, it->second);
} }
} }
bool template_controller::remove_template(const std::string& key) bool template_controller::remove_template(const std::string &key)
{ {
auto result = clrsync::core::config::instance().remove_template(key); auto result = clrsync::core::config::instance().remove_template(key);
if (result) { if (result)
{
m_templates.erase(key); m_templates.erase(key);
return true; return true;
} }

View File

@@ -1,24 +1,29 @@
#ifndef CLRSYNC_GUI_TEMPLATE_CONTROLLER_HPP #ifndef CLRSYNC_GUI_TEMPLATE_CONTROLLER_HPP
#define CLRSYNC_GUI_TEMPLATE_CONTROLLER_HPP #define CLRSYNC_GUI_TEMPLATE_CONTROLLER_HPP
#include "core/theme/theme_template.hpp"
#include "core/theme/template_manager.hpp"
#include "core/io/toml_file.hpp" #include "core/io/toml_file.hpp"
#include "core/theme/template_manager.hpp"
#include "core/theme/theme_template.hpp"
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
class template_controller { class template_controller
public: {
public:
template_controller(); template_controller();
[[nodiscard]] const std::unordered_map<std::string, clrsync::core::theme_template>& templates() const { return m_templates; } [[nodiscard]] const std::unordered_map<std::string, clrsync::core::theme_template> &templates()
void set_template_enabled(const std::string& key, bool enabled); const
void set_template_input_path(const std::string& key, const std::string& path); {
void set_template_output_path(const std::string& key, const std::string& path); return m_templates;
void set_template_reload_command(const std::string& key, const std::string& cmd); }
bool remove_template(const std::string& key); void set_template_enabled(const std::string &key, bool enabled);
void set_template_input_path(const std::string &key, const std::string &path);
void set_template_output_path(const std::string &key, const std::string &path);
void set_template_reload_command(const std::string &key, const std::string &cmd);
bool remove_template(const std::string &key);
void refresh(); void refresh();
private: private:
clrsync::core::template_manager<clrsync::core::io::toml_file> m_template_manager; clrsync::core::template_manager<clrsync::core::io::toml_file> m_template_manager;
std::unordered_map<std::string, clrsync::core::theme_template> m_templates; std::unordered_map<std::string, clrsync::core::theme_template> m_templates;
}; };

View File

@@ -1,55 +1,65 @@
#include "theme_applier.hpp" #include "gui/controllers/theme_applier.hpp"
#include "imgui.h" #include "imgui.h"
namespace theme_applier 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 auto &col = current.get_color(key); const uint32_t hex = col.hex();
const uint32_t hex = col.hex(); // Convert from RRGGBBAA to AABBGGRR (ImGui format)
// Convert from RRGGBBAA to AABBGGRR (ImGui format) const uint32_t r = (hex >> 24) & 0xFF;
const uint32_t r = (hex >> 24) & 0xFF; const uint32_t g = (hex >> 16) & 0xFF;
const uint32_t g = (hex >> 16) & 0xFF; const uint32_t b = (hex >> 8) & 0xFF;
const uint32_t b = (hex >> 8) & 0xFF; const uint32_t a = hex & 0xFF;
const uint32_t a = hex & 0xFF; return (a << 24) | (b << 16) | (g << 8) | r;
return (a << 24) | (b << 16) | (g << 8) | r; }
};
void apply_to_editor(TextEditor &editor, const clrsync::core::palette &current)
{
auto palette = editor.GetPalette(); auto palette = editor.GetPalette();
palette[int(TextEditor::PaletteIndex::Default)] = get_color_u32("editor_main"); palette[int(TextEditor::PaletteIndex::Default)] = get_color_u32(current, "editor_main");
palette[int(TextEditor::PaletteIndex::Keyword)] = get_color_u32("editor_command"); palette[int(TextEditor::PaletteIndex::Keyword)] = get_color_u32(current, "editor_command");
palette[int(TextEditor::PaletteIndex::Number)] = get_color_u32("editor_warning"); palette[int(TextEditor::PaletteIndex::Number)] = get_color_u32(current, "editor_warning");
palette[int(TextEditor::PaletteIndex::String)] = get_color_u32("editor_string"); palette[int(TextEditor::PaletteIndex::String)] = get_color_u32(current, "editor_string");
palette[int(TextEditor::PaletteIndex::CharLiteral)] = get_color_u32("editor_string"); palette[int(TextEditor::PaletteIndex::CharLiteral)] = get_color_u32(current, "editor_string");
palette[int(TextEditor::PaletteIndex::Punctuation)] = get_color_u32("editor_main"); palette[int(TextEditor::PaletteIndex::Punctuation)] = get_color_u32(current, "editor_main");
palette[int(TextEditor::PaletteIndex::Preprocessor)] = get_color_u32("editor_emphasis"); palette[int(TextEditor::PaletteIndex::Preprocessor)] =
palette[int(TextEditor::PaletteIndex::Identifier)] = get_color_u32("editor_main"); get_color_u32(current, "editor_emphasis");
palette[int(TextEditor::PaletteIndex::KnownIdentifier)] = get_color_u32("editor_link"); palette[int(TextEditor::PaletteIndex::Identifier)] = get_color_u32(current, "editor_main");
palette[int(TextEditor::PaletteIndex::PreprocIdentifier)] = get_color_u32("editor_link"); 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::Comment)] = get_color_u32(current, "editor_comment");
palette[int(TextEditor::PaletteIndex::MultiLineComment)] = get_color_u32("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::Background)] =
palette[int(TextEditor::PaletteIndex::Cursor)] = get_color_u32("cursor"); 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::Selection)] = get_color_u32(current, "editor_selected");
palette[int(TextEditor::PaletteIndex::ErrorMarker)] = get_color_u32("editor_error"); palette[int(TextEditor::PaletteIndex::ErrorMarker)] = get_color_u32(current, "editor_error");
palette[int(TextEditor::PaletteIndex::Breakpoint)] = get_color_u32("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::LineNumber)] =
palette[int(TextEditor::PaletteIndex::CurrentLineFill)] = get_color_u32("surface_variant"); get_color_u32(current, "editor_line_number");
palette[int(TextEditor::PaletteIndex::CurrentLineFillInactive)] = get_color_u32("surface");
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); editor.SetPalette(palette);
} }
void apply_to_imgui(const clrsync::core::palette& current) void apply_to_imgui(const clrsync::core::palette &current)
{ {
auto getColor = [&](const std::string &key) -> ImVec4 { auto getColor = [&](const std::string &key) -> ImVec4 {
const auto &col = current.get_color(key); const auto &col = current.get_color(key);
@@ -61,13 +71,25 @@ void apply_to_imgui(const clrsync::core::palette& current)
ImGuiStyle &style = ImGui::GetStyle(); ImGuiStyle &style = ImGui::GetStyle();
const ImVec4 bg = getColor("background"); const ImVec4 bg = getColor("background");
const ImVec4 onBg = getColor("on_background");
const ImVec4 surface = getColor("surface"); const ImVec4 surface = getColor("surface");
const ImVec4 onSurface = getColor("on_surface");
const ImVec4 surfaceVariant = getColor("surface_variant"); const ImVec4 surfaceVariant = getColor("surface_variant");
const ImVec4 onSurfaceVariant = getColor("on_surface_variant");
const ImVec4 fg = getColor("foreground"); const ImVec4 fg = getColor("foreground");
const ImVec4 fgInactive = getColor("editor_inactive"); const ImVec4 fgInactive = getColor("editor_inactive");
const ImVec4 accent = getColor("accent"); const ImVec4 accent = getColor("accent");
const ImVec4 border = getColor("border"); 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_WindowBg] = bg;
style.Colors[ImGuiCol_ChildBg] = surface; style.Colors[ImGuiCol_ChildBg] = surface;
style.Colors[ImGuiCol_PopupBg] = surface; style.Colors[ImGuiCol_PopupBg] = surface;
@@ -75,8 +97,9 @@ void apply_to_imgui(const clrsync::core::palette& current)
style.Colors[ImGuiCol_Border] = border; style.Colors[ImGuiCol_Border] = border;
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0, 0, 0, 0); style.Colors[ImGuiCol_BorderShadow] = ImVec4(0, 0, 0, 0);
style.Colors[ImGuiCol_Text] = fg; style.Colors[ImGuiCol_Text] = onSurface;
style.Colors[ImGuiCol_TextDisabled] = fgInactive; style.Colors[ImGuiCol_TextDisabled] = onSurfaceVariant;
style.Colors[ImGuiCol_TextSelectedBg] = accent;
style.Colors[ImGuiCol_Header] = surfaceVariant; style.Colors[ImGuiCol_Header] = surfaceVariant;
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(accent.x, accent.y, accent.z, 0.8f); style.Colors[ImGuiCol_HeaderHovered] = ImVec4(accent.x, accent.y, accent.z, 0.8f);
@@ -123,7 +146,8 @@ void apply_to_imgui(const clrsync::core::palette& current)
ImVec4(border.x * 0.7f, border.y * 0.7f, border.z * 0.7f, border.w); 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_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_Separator] = border;
style.Colors[ImGuiCol_SeparatorHovered] = accent; style.Colors[ImGuiCol_SeparatorHovered] = accent;

View File

@@ -1,13 +1,13 @@
#ifndef CLRSYNC_GUI_THEME_APPLIER_HPP #ifndef CLRSYNC_GUI_THEME_APPLIER_HPP
#define CLRSYNC_GUI_THEME_APPLIER_HPP #define CLRSYNC_GUI_THEME_APPLIER_HPP
#include "core/palette/palette.hpp"
#include "color_text_edit/TextEditor.h" #include "color_text_edit/TextEditor.h"
#include "core/palette/palette.hpp"
namespace theme_applier namespace theme_applier
{ {
void apply_to_imgui(const clrsync::core::palette& pal); void apply_to_imgui(const clrsync::core::palette &pal);
void apply_to_editor(TextEditor& editor, const clrsync::core::palette& pal); void apply_to_editor(TextEditor &editor, const clrsync::core::palette &pal);
} } // namespace theme_applier
#endif // CLRSYNC_GUI_THEME_APPLIER_HPP #endif // CLRSYNC_GUI_THEME_APPLIER_HPP

View File

@@ -1,338 +0,0 @@
#include "file_browser.hpp"
#include <filesystem>
#ifdef _WIN32
#include <windows.h>
#include <commdlg.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <cstring>
namespace file_dialogs {
std::string open_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
OPENFILENAMEA ofn;
char file[MAX_PATH] = "";
std::string filter_str = "All Files (*.*)\0*.*\0";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFile = file;
ofn.nMaxFile = sizeof(file);
ofn.lpstrFilter = filter_str.c_str();
ofn.nFilterIndex = 1;
ofn.lpstrTitle = title.c_str();
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
if (!initial_path.empty() && std::filesystem::exists(initial_path)) {
std::filesystem::path p(initial_path);
if (std::filesystem::is_directory(p)) {
ofn.lpstrInitialDir = initial_path.c_str();
} else {
std::string dir = p.parent_path().string();
std::string name = p.filename().string();
ofn.lpstrInitialDir = dir.c_str();
strncpy(file, name.c_str(), sizeof(file) - 1);
}
}
if (GetOpenFileNameA(&ofn)) {
return std::string(file);
}
return "";
}
std::string save_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
OPENFILENAMEA ofn;
char file[MAX_PATH] = "";
std::string filter_str = "All Files\0*.*\0\0";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFile = file;
ofn.nMaxFile = sizeof(file);
ofn.lpstrFilter = filter_str.c_str();
ofn.nFilterIndex = 1;
ofn.lpstrTitle = title.c_str();
ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR;
if (!initial_path.empty()) {
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p) && std::filesystem::is_directory(p)) {
ofn.lpstrInitialDir = initial_path.c_str();
} else {
std::string dir = p.parent_path().string();
std::string name = p.filename().string();
if (std::filesystem::exists(dir)) {
ofn.lpstrInitialDir = dir.c_str();
strncpy(file, name.c_str(), sizeof(file) - 1);
}
}
}
if (GetSaveFileNameA(&ofn)) {
return std::string(file);
}
return "";
}
std::string select_folder_dialog(const std::string& title,
const std::string& initial_path) {
IFileOpenDialog *pFileOpen;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr)) {
DWORD dwFlags;
if (SUCCEEDED(pFileOpen->GetOptions(&dwFlags))) {
pFileOpen->SetOptions(dwFlags | FOS_PICKFOLDERS);
}
std::wstring wtitle(title.begin(), title.end());
pFileOpen->SetTitle(wtitle.c_str());
if (!initial_path.empty() && std::filesystem::exists(initial_path)) {
IShellItem *psi = NULL;
std::wstring winitial(initial_path.begin(), initial_path.end());
hr = SHCreateItemFromParsingName(winitial.c_str(), NULL, IID_IShellItem, (void**)&psi);
if (SUCCEEDED(hr)) {
pFileOpen->SetFolder(psi);
psi->Release();
}
}
hr = pFileOpen->Show(GetActiveWindow());
if (SUCCEEDED(hr)) {
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr)) {
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
if (SUCCEEDED(hr)) {
std::wstring wpath(pszFilePath);
std::string result(wpath.begin(), wpath.end());
CoTaskMemFree(pszFilePath);
pItem->Release();
pFileOpen->Release();
return result;
}
pItem->Release();
}
}
pFileOpen->Release();
}
return "";
}
}
#else
#ifdef __APPLE__
#include <Cocoa/Cocoa.h>
namespace file_dialogs {
std::string open_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:YES];
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string save_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSSavePanel* panel = [NSSavePanel savePanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
if (!initial_path.empty()) {
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p.parent_path())) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:p.parent_path().c_str()]];
[panel setDirectoryURL:url];
[panel setNameFieldStringValue:[NSString stringWithUTF8String:p.filename().c_str()]];
}
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [panel URL];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string select_folder_dialog(const std::string& title,
const std::string& initial_path) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
}
#else
#include <gtk/gtk.h>
namespace file_dialogs {
std::string open_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
if (!gtk_init_check(nullptr, nullptr)) {
return "";
}
GtkWidget* dialog = gtk_file_chooser_dialog_new(
title.c_str(),
nullptr,
GTK_FILE_CHOOSER_ACTION_OPEN,
"Cancel", GTK_RESPONSE_CANCEL,
"Open", GTK_RESPONSE_ACCEPT,
nullptr);
if (!initial_path.empty()) {
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p)) {
if (std::filesystem::is_directory(p)) {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), initial_path.c_str());
} else {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), p.parent_path().c_str());
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), p.filename().c_str());
}
}
}
std::string result;
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
if (filename) {
result = filename;
g_free(filename);
}
}
gtk_widget_destroy(dialog);
return result;
}
std::string save_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
if (!gtk_init_check(nullptr, nullptr)) {
return "";
}
GtkWidget* dialog = gtk_file_chooser_dialog_new(
title.c_str(),
nullptr,
GTK_FILE_CHOOSER_ACTION_SAVE,
"Cancel", GTK_RESPONSE_CANCEL,
"Save", GTK_RESPONSE_ACCEPT,
nullptr);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
if (!initial_path.empty()) {
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p.parent_path())) {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), p.parent_path().c_str());
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), p.filename().c_str());
}
}
std::string result;
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
if (filename) {
result = filename;
g_free(filename);
}
}
gtk_widget_destroy(dialog);
return result;
}
std::string select_folder_dialog(const std::string& title,
const std::string& initial_path) {
if (!gtk_init_check(nullptr, nullptr)) {
return "";
}
GtkWidget* dialog = gtk_file_chooser_dialog_new(
title.c_str(),
nullptr,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
"Cancel", GTK_RESPONSE_CANCEL,
"Select", GTK_RESPONSE_ACCEPT,
nullptr);
if (!initial_path.empty() && std::filesystem::exists(initial_path)) {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), initial_path.c_str());
}
std::string result;
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
if (filename) {
result = filename;
g_free(filename);
}
}
gtk_widget_destroy(dialog);
return result;
}
}
#endif
#endif

View File

@@ -1,20 +0,0 @@
#ifndef CLRSYNC_GUI_FILE_BROWSER_HPP
#define CLRSYNC_GUI_FILE_BROWSER_HPP
#include <string>
#include <vector>
namespace file_dialogs {
std::string open_file_dialog(const std::string& title = "Open File",
const std::string& initial_path = "",
const std::vector<std::string>& filters = {});
std::string save_file_dialog(const std::string& title = "Save File",
const std::string& initial_path = "",
const std::vector<std::string>& filters = {});
std::string select_folder_dialog(const std::string& title = "Select Folder",
const std::string& initial_path = "");
}
#endif // CLRSYNC_GUI_FILE_BROWSER_HPP

View File

@@ -1,331 +0,0 @@
#include "font_loader.hpp"
#include "core/config/config.hpp"
#include "imgui_internal.h"
#include <imgui.h>
#include <algorithm>
#if defined(_WIN32)
#include <algorithm>
#include <windows.h>
#include <winreg.h>
static std::string search_registry_for_font(HKEY root_key, const char* subkey, const std::string& font_name_lower, const char* default_font_dir)
{
HKEY hKey;
LONG result = RegOpenKeyExA(root_key, subkey, 0, KEY_READ, &hKey);
if (result != ERROR_SUCCESS)
return {};
char value_name[512];
BYTE value_data[512];
DWORD value_name_size, value_data_size, type;
DWORD index = 0;
std::string found_path;
while (true)
{
value_name_size = sizeof(value_name);
value_data_size = sizeof(value_data);
result = RegEnumValueA(hKey, index++, value_name, &value_name_size, nullptr, &type, value_data, &value_data_size);
if (result != ERROR_SUCCESS)
break;
if (type != REG_SZ)
continue;
std::string reg_font_name = value_name;
std::transform(reg_font_name.begin(), reg_font_name.end(), reg_font_name.begin(), ::tolower);
std::string reg_font_name_clean = reg_font_name;
size_t type_pos = reg_font_name_clean.find(" (");
if (type_pos != std::string::npos)
reg_font_name_clean = reg_font_name_clean.substr(0, type_pos);
if (reg_font_name_clean == font_name_lower)
{
std::string font_file = reinterpret_cast<char*>(value_data);
// If path is not absolute, prepend default font directory
if (font_file.find(":\\") == std::string::npos)
{
found_path = std::string(default_font_dir) + "\\" + font_file;
}
else
{
found_path = font_file;
}
break;
}
}
RegCloseKey(hKey);
return found_path;
}
std::string font_loader::find_font_windows(const char* font_name)
{
std::string font_name_lower = font_name;
std::transform(font_name_lower.begin(), font_name_lower.end(), font_name_lower.begin(), ::tolower);
char windows_dir[MAX_PATH];
GetWindowsDirectoryA(windows_dir, MAX_PATH);
std::string system_fonts_dir = std::string(windows_dir) + "\\Fonts";
// First, try system-wide fonts (HKEY_LOCAL_MACHINE)
std::string path = search_registry_for_font(
HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
font_name_lower,
system_fonts_dir.c_str()
);
if (!path.empty())
return path;
// If not found, try per-user fonts (HKEY_CURRENT_USER)
char local_appdata[MAX_PATH];
if (GetEnvironmentVariableA("LOCALAPPDATA", local_appdata, MAX_PATH) > 0)
{
std::string user_fonts_dir = std::string(local_appdata) + "\\Microsoft\\Windows\\Fonts";
path = search_registry_for_font(
HKEY_CURRENT_USER,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
font_name_lower,
user_fonts_dir.c_str()
);
}
return path;
}
#endif
#if defined(__APPLE__)
#include <CoreText/CoreText.h>
std::vector<unsigned char> font_loader::load_font_macos(const char* font_name)
{
std::vector<unsigned char> out;
CFStringRef cf_name = CFStringCreateWithCString(nullptr, font_name, kCFStringEncodingUTF8);
if (!cf_name)
return out;
CTFontDescriptorRef desc = CTFontDescriptorCreateWithNameAndSize(cf_name, 12);
CFRelease(cf_name);
if (!desc)
return out;
CTFontRef font = CTFontCreateWithFontDescriptor(desc, 0, nullptr);
CFRelease(desc);
if (!font)
return out;
CFDataRef data = CTFontCopyTable(font, kCTFontTableCFF, 0);
if (!data)
data = CTFontCopyTable(font, kCTFontTableHead, 0);
if (data)
{
CFIndex size = CFDataGetLength(data);
out.resize(size);
CFDataGetBytes(data, CFRangeMake(0, size), out.data());
CFRelease(data);
}
CFRelease(font);
return out;
}
#endif
#if !defined(_WIN32) && !defined(__APPLE__)
#include <fontconfig/fontconfig.h>
std::string font_loader::find_font_linux(const char* font_name)
{
FcInit();
FcPattern* pattern = FcNameParse(reinterpret_cast<const FcChar8*>(font_name));
if (!pattern)
return {};
FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
FcResult result;
FcPattern* match = FcFontMatch(nullptr, pattern, &result);
std::string out;
if (match)
{
FcChar8* file = nullptr;
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch)
out = reinterpret_cast<const char*>(file);
FcPatternDestroy(match);
}
FcPatternDestroy(pattern);
return out;
}
#endif
std::string font_loader::find_font_path(const char* font_name)
{
#if defined(_WIN32)
return find_font_windows(font_name);
#elif defined(__APPLE__)
(void)font_name;
return {};
#else
return find_font_linux(font_name);
#endif
}
ImFont* font_loader::load_font(const char* font_name, float size_px)
{
#if defined(__APPLE__)
std::vector<unsigned char> buf = load_font_macos(font_name);
if (buf.empty())
return nullptr;
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(
buf.data(),
static_cast<int>(buf.size()),
size_px
);
#else
std::string path = find_font_path(font_name);
if (path.empty())
return nullptr;
float scale = ImGui::GetIO().DisplayFramebufferScale.y;
return ImGui::GetIO().Fonts->AddFontFromFileTTF(
path.c_str(),
size_px * scale
);
#endif
}
void font_loader::push_default_font()
{
ImGui::PushFont(ImGui::GetDefaultFont(), clrsync::core::config::instance().font_size());
}
void font_loader::pop_font()
{
ImGui::PopFont();
}
std::vector<std::string> font_loader::get_system_fonts()
{
std::vector<std::string> fonts;
#if defined(_WIN32)
auto enumerate_registry_fonts = [&fonts](HKEY root_key, const char* subkey)
{
HKEY hKey;
if (RegOpenKeyExA(root_key, subkey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
return;
char value_name[512];
DWORD value_name_size;
DWORD index = 0;
while (true)
{
value_name_size = sizeof(value_name);
LONG result = RegEnumValueA(hKey, index++, value_name, &value_name_size, nullptr, nullptr, nullptr, nullptr);
if (result != ERROR_SUCCESS)
break;
std::string font_name = value_name;
size_t pos = font_name.find(" (");
if (pos != std::string::npos)
font_name = font_name.substr(0, pos);
if (std::find(fonts.begin(), fonts.end(), font_name) == fonts.end())
fonts.push_back(font_name);
}
RegCloseKey(hKey);
};
enumerate_registry_fonts(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
enumerate_registry_fonts(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
#elif defined(__APPLE__)
CTFontCollectionRef collection = CTFontCollectionCreateFromAvailableFonts(nullptr);
if (collection)
{
CFArrayRef fontDescriptors = CTFontCollectionCreateMatchingFontDescriptors(collection);
CFRelease(collection);
if (fontDescriptors)
{
CFIndex count = CFArrayGetCount(fontDescriptors);
for (CFIndex i = 0; i < count; i++)
{
CTFontDescriptorRef descriptor = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fontDescriptors, i);
CFStringRef fontName = (CFStringRef)CTFontDescriptorCopyAttribute(descriptor, kCTFontDisplayNameAttribute);
if (fontName)
{
char buffer[256];
if (CFStringGetCString(fontName, buffer, sizeof(buffer), kCFStringEncodingUTF8))
{
std::string font_name = buffer;
if (std::find(fonts.begin(), fonts.end(), font_name) == fonts.end())
fonts.push_back(font_name);
}
CFRelease(fontName);
}
}
CFRelease(fontDescriptors);
}
}
#else
FcInit();
FcPattern* pattern = FcPatternCreate();
FcObjectSet* os = FcObjectSetBuild(FC_FAMILY, nullptr);
FcFontSet* fs = FcFontList(nullptr, pattern, os);
if (fs)
{
for (int i = 0; i < fs->nfont; i++)
{
FcChar8* family = nullptr;
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch)
{
std::string font_name = reinterpret_cast<const char*>(family);
if (std::find(fonts.begin(), fonts.end(), font_name) == fonts.end())
fonts.push_back(font_name);
}
}
FcFontSetDestroy(fs);
}
FcObjectSetDestroy(os);
FcPatternDestroy(pattern);
#endif
std::sort(fonts.begin(), fonts.end());
return fonts;
}

View File

@@ -2,7 +2,7 @@
#include <string> #include <string>
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
#include "gui/settings_window.hpp" #include "gui/views/settings_window.hpp"
#include "imgui_impl_glfw.h" #include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h" #include "imgui_impl_opengl3.h"
@@ -10,9 +10,9 @@
#include "imgui_internal.h" #include "imgui_internal.h"
GLFWwindow * init_glfw() GLFWwindow *init_glfw()
{ {
glfwSetErrorCallback([](int error, const char* description) { glfwSetErrorCallback([](int error, const char *description) {
std::cerr << "GLFW Error " << error << ": " << description << std::endl; std::cerr << "GLFW Error " << error << ": " << description << std::endl;
}); });
@@ -23,10 +23,14 @@ GLFWwindow * init_glfw()
} }
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
#ifdef __APPLE__
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
#else
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
#endif
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
GLFWwindow* w = glfwCreateWindow(1280, 720, "clrsync", nullptr, nullptr); GLFWwindow *w = glfwCreateWindow(1280, 720, "clrsync", nullptr, nullptr);
if (!w) if (!w)
{ {
std::cerr << "Failed to create GLFW window\n"; std::cerr << "Failed to create GLFW window\n";
@@ -38,18 +42,22 @@ GLFWwindow * init_glfw()
return w; return w;
} }
void init_imgui(GLFWwindow* window, const std::string& ini_path) void init_imgui(GLFWwindow *window, const std::string &ini_path)
{ {
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.IniFilename = ini_path.c_str(); io.IniFilename = ini_path.c_str();
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 130"); #ifdef __APPLE__
ImGui_ImplOpenGL3_Init("#version 150");
#else
ImGui_ImplOpenGL3_Init("#version 120");
#endif
} }
void begin_frame() void begin_frame()
@@ -59,7 +67,7 @@ void begin_frame()
ImGui::NewFrame(); ImGui::NewFrame();
} }
void render_menu_bar(about_window* about, settings_window* settings) void render_menu_bar(about_window *about, settings_window *settings)
{ {
if (ImGui::BeginMainMenuBar()) if (ImGui::BeginMainMenuBar())
{ {
@@ -91,25 +99,21 @@ void render_menu_bar(about_window* about, settings_window* settings)
} }
} }
void setup_main_dockspace(bool& first_time) void setup_main_dockspace(bool &first_time)
{ {
const ImGuiViewport* viewport = ImGui::GetMainViewport(); const ImGuiViewport *viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos); ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size); ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID); ImGui::SetNextWindowViewport(viewport->ID);
constexpr ImGuiWindowFlags flags = constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_MenuBar;
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoNavFocus |
ImGuiWindowFlags_MenuBar;
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0,0)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::Begin("MainDockSpace", nullptr, flags); ImGui::Begin("MainDockSpace", nullptr, flags);
ImGui::PopStyleVar(3); ImGui::PopStyleVar(3);
@@ -126,24 +130,24 @@ void setup_main_dockspace(bool& first_time)
ImGuiID center, right; ImGuiID center, right;
ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Right, 0.5f, &right, &center); ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Right, 0.5f, &right, &center);
ImGuiDockNode* center_node = ImGui::DockBuilderGetNode(center); ImGuiDockNode *center_node = ImGui::DockBuilderGetNode(center);
if (center_node) if (center_node)
{ {
center_node->LocalFlags |= ImGuiDockNodeFlags_CentralNode; center_node->LocalFlags |= ImGuiDockNodeFlags_CentralNode;
} }
ImGui::DockBuilderDockWindow("Color Schemes", right); ImGui::DockBuilderDockWindow("Color Schemes", right);
ImGui::DockBuilderDockWindow("Templates", center);
ImGui::DockBuilderDockWindow("Color Preview", center); ImGui::DockBuilderDockWindow("Color Preview", center);
ImGui::DockBuilderDockWindow("Templates", center);
ImGui::DockBuilderFinish(dockspace_id); ImGui::DockBuilderFinish(dockspace_id);
} }
ImGui::DockSpace(dockspace_id, ImVec2{0,0}, ImGuiDockNodeFlags_None); ImGui::DockSpace(dockspace_id, ImVec2{0, 0}, ImGuiDockNodeFlags_None);
ImGui::End(); ImGui::End();
} }
void end_frame(GLFWwindow* window) void end_frame(GLFWwindow *window)
{ {
ImGui::Render(); ImGui::Render();
int w, h; int w, h;
@@ -156,7 +160,7 @@ void end_frame(GLFWwindow* window)
glfwSwapBuffers(window); glfwSwapBuffers(window);
} }
void shutdown(GLFWwindow* window) void shutdown(GLFWwindow *window)
{ {
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();
@@ -168,7 +172,8 @@ void shutdown(GLFWwindow* window)
namespace palette_utils namespace palette_utils
{ {
ImVec4 get_color(const clrsync::core::palette& pal, const std::string& key, const std::string& fallback) ImVec4 get_color(const clrsync::core::palette &pal, const std::string &key,
const std::string &fallback)
{ {
auto colors = pal.colors(); auto colors = pal.colors();
if (colors.empty()) if (colors.empty())
@@ -182,7 +187,7 @@ ImVec4 get_color(const clrsync::core::palette& pal, const std::string& key, cons
if (it != colors.end()) if (it != colors.end())
{ {
const auto& col = it->second; const auto &col = it->second;
const uint32_t hex = col.hex(); const uint32_t hex = col.hex();
const float r = ((hex >> 24) & 0xFF) / 255.0f; const float r = ((hex >> 24) & 0xFF) / 255.0f;
const float g = ((hex >> 16) & 0xFF) / 255.0f; const float g = ((hex >> 16) & 0xFF) / 255.0f;
@@ -193,7 +198,8 @@ ImVec4 get_color(const clrsync::core::palette& pal, const std::string& key, cons
return ImVec4(1.0f, 1.0f, 1.0f, 1.0f); return ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
} }
uint32_t get_color_u32(const clrsync::core::palette& pal, const std::string& key, const std::string& fallback) uint32_t get_color_u32(const clrsync::core::palette &pal, const std::string &key,
const std::string &fallback)
{ {
auto colors = pal.colors(); auto colors = pal.colors();
if (colors.empty()) if (colors.empty())
@@ -207,7 +213,7 @@ uint32_t get_color_u32(const clrsync::core::palette& pal, const std::string& key
if (it != colors.end()) if (it != colors.end())
{ {
const auto& col = it->second; const auto &col = it->second;
const uint32_t hex = col.hex(); const uint32_t hex = col.hex();
const uint32_t r = (hex >> 24) & 0xFF; const uint32_t r = (hex >> 24) & 0xFF;
const uint32_t g = (hex >> 16) & 0xFF; const uint32_t g = (hex >> 16) & 0xFF;
@@ -218,15 +224,17 @@ uint32_t get_color_u32(const clrsync::core::palette& pal, const std::string& key
return 0xFFFFFFFF; return 0xFFFFFFFF;
} }
bool render_delete_confirmation_popup(const std::string& popup_title, const std::string& item_name, bool render_delete_confirmation_popup(const std::string &popup_title, const std::string &item_name,
const std::string& item_type, const clrsync::core::palette& pal, const std::string &item_type,
const std::function<void()>& on_delete) const clrsync::core::palette &pal,
const std::function<void()> &on_delete)
{ {
bool result = false; bool result = false;
if (ImGui::BeginPopupModal(popup_title.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) if (ImGui::BeginPopupModal(popup_title.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize))
{ {
ImVec4 warning_color = get_color(pal, "warning", "accent"); ImVec4 warning_color = get_color(pal, "warning", "accent");
ImGui::TextColored(warning_color, "Are you sure you want to delete '%s'?", item_name.c_str()); ImGui::TextColored(warning_color, "Are you sure you want to delete '%s'?",
item_name.c_str());
ImGui::Text("This action cannot be undone."); ImGui::Text("This action cannot be undone.");
ImGui::Spacing(); ImGui::Spacing();
@@ -255,4 +263,4 @@ bool render_delete_confirmation_popup(const std::string& popup_title, const std:
return result; return result;
} }
} } // namespace palette_utils

View File

@@ -0,0 +1,42 @@
#ifndef CLRSYNC_IMGUI_HELPERS_HPP
#define CLRSYNC_IMGUI_HELPERS_HPP
#include "core/palette/palette.hpp"
#include "gui/views/about_window.hpp"
#include "imgui.h"
#include <functional>
#include <string>
struct GLFWwindow;
class settings_window;
GLFWwindow *init_glfw();
void init_imgui(GLFWwindow *window, const std::string &ini_path);
void begin_frame();
void setup_main_dockspace(bool &first_time);
void end_frame(GLFWwindow *window);
void shutdown(GLFWwindow *window);
void render_menu_bar(about_window *about, settings_window *settings);
namespace palette_utils
{
ImVec4 get_color(const clrsync::core::palette &pal, const std::string &key,
const std::string &fallback = "");
uint32_t get_color_u32(const clrsync::core::palette &pal, const std::string &key,
const std::string &fallback = "");
bool render_delete_confirmation_popup(const std::string &popup_title, const std::string &item_name,
const std::string &item_type,
const clrsync::core::palette &pal,
const std::function<void()> &on_delete);
} // namespace palette_utils
namespace imgui_helpers
{
inline ImVec4 get_palette_color(const clrsync::core::palette &pal, const std::string &key,
const std::string &fallback = "")
{
return palette_utils::get_color(pal, key, fallback);
}
} // namespace imgui_helpers
#endif // CLRSYNC_IMGUI_HELPERS_HPP

View File

@@ -1,37 +0,0 @@
#ifndef CLRSYNC_IMGUI_HELPERS_HPP
#define CLRSYNC_IMGUI_HELPERS_HPP
#include "gui/about_window.hpp"
#include "core/palette/palette.hpp"
#include "imgui.h"
#include <functional>
#include <string>
struct GLFWwindow;
class settings_window;
GLFWwindow * init_glfw();
void init_imgui(GLFWwindow* window, const std::string& ini_path);
void begin_frame();
void setup_main_dockspace(bool& first_time);
void end_frame(GLFWwindow* window);
void shutdown(GLFWwindow* window);
void render_menu_bar(about_window* about, settings_window* settings);
namespace palette_utils
{
ImVec4 get_color(const clrsync::core::palette& pal, const std::string& key, const std::string& fallback = "");
uint32_t get_color_u32(const clrsync::core::palette& pal, const std::string& key, const std::string& fallback = "");
bool render_delete_confirmation_popup(const std::string& popup_title, const std::string& item_name,
const std::string& item_type, const clrsync::core::palette& pal,
const std::function<void()>& on_delete);
}
namespace imgui_helpers
{
inline ImVec4 get_palette_color(const clrsync::core::palette& pal, const std::string& key, const std::string& fallback = "") {
return palette_utils::get_color(pal, key, fallback);
}
}
#endif // CLRSYNC_IMGUI_HELPERS_HPP

View File

@@ -1,23 +1,24 @@
#include <iostream>
#include <memory> #include <memory>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h> #include <GLFW/glfw3native.h>
#include "core/common/error.hpp"
#include "core/common/utils.hpp"
#include "core/config/config.hpp" #include "core/config/config.hpp"
#include "core/io/toml_file.hpp" #include "core/io/toml_file.hpp"
#include "core/utils.hpp"
#include "core/error.hpp"
#include "color_scheme_editor.hpp" #include "gui/backend/glfw_opengl.hpp"
#include "gui/font_loader.hpp" #include "gui/helpers/imgui_helpers.hpp"
#include "gui/settings_window.hpp" #include "gui/platform/font_loader.hpp"
#include "imgui_helpers.hpp" #include "gui/ui_manager.hpp"
#include "template_editor.hpp" #include "gui/views/about_window.hpp"
#include "about_window.hpp" #include "gui/views/color_scheme_editor.hpp"
#include "gui/views/settings_window.hpp"
#include "gui/views/template_editor.hpp"
int main(int, char **)
int main(int, char**)
{ {
auto config_path = clrsync::core::get_default_config_path(); auto config_path = clrsync::core::get_default_config_path();
auto conf = std::make_unique<clrsync::core::io::toml_file>(config_path); auto conf = std::make_unique<clrsync::core::io::toml_file>(config_path);
@@ -26,7 +27,9 @@ int main(int, char**)
if (!init_result) if (!init_result)
{ {
std::cerr << "Fatal error: " << init_result.error().description() << std::endl; std::cerr << "Fatal error: " << init_result.error().description() << std::endl;
std::cerr << "Hint: Set CLRSYNC_CONFIG_PATH environment variable or ensure config exists at: " << config_path << std::endl; std::cerr
<< "Hint: Set CLRSYNC_CONFIG_PATH environment variable or ensure config exists at: "
<< config_path << std::endl;
return 1; return 1;
} }
@@ -34,10 +37,20 @@ int main(int, char**)
static std::string ini_path = (base.parent_path() / "layout.ini").string(); static std::string ini_path = (base.parent_path() / "layout.ini").string();
bool first_time = !std::filesystem::exists(ini_path); bool first_time = !std::filesystem::exists(ini_path);
GLFWwindow* window = init_glfw(); printf("GLFW Version: %s\n", glfwGetVersionString());
if (!window) return 1;
printf("GLFV Version: %s\n", glfwGetVersionString()); auto backend = clrsync::gui::backend::glfw_opengl_backend();
auto window_config = clrsync::gui::backend::window_config();
window_config.title = "clrsync";
window_config.width = 1280;
window_config.height = 720;
window_config.transparent_framebuffer = true;
if (!backend.initialize(window_config))
{
std::cerr << "Failed to initialize backend." << std::endl;
return 1;
}
std::cout << "GLFW runtime platform: "; std::cout << "GLFW runtime platform: ";
switch (glfwGetPlatform()) { switch (glfwGetPlatform()) {
@@ -48,13 +61,23 @@ int main(int, char**)
default: std::cout << "Unknown\n"; default: std::cout << "Unknown\n";
} }
clrsync::gui::ui_manager ui_manager(&backend);
init_imgui(window, ini_path); clrsync::gui::ui_config ui_cfg;
ui_cfg.ini_path = ini_path;
ui_cfg.enable_docking = true;
ui_cfg.enable_keyboard_nav = true;
if (!ui_manager.initialize(ui_cfg))
{
std::cerr << "Failed to initialize UI manager." << std::endl;
return 1;
}
font_loader loader; font_loader loader;
ImFont* font = ImFont *font = loader.load_font(clrsync::core::config::instance().font().c_str(),
loader.load_font(clrsync::core::config::instance().font().c_str(), clrsync::core::config::instance().font_size()); clrsync::core::config::instance().font_size());
if (font) if (font)
ImGui::GetIO().FontDefault = font; ImGui::GetIO().FontDefault = font;
@@ -69,23 +92,28 @@ int main(int, char**)
templateEditor.apply_current_palette(colorEditor.controller().current_palette()); templateEditor.apply_current_palette(colorEditor.controller().current_palette());
settingsWindow.set_palette(colorEditor.controller().current_palette()); settingsWindow.set_palette(colorEditor.controller().current_palette());
while (!glfwWindowShouldClose(window)) while (!backend.should_close())
{ {
glfwPollEvents(); backend.begin_frame();
loader.push_default_font(); loader.push_default_font();
begin_frame(); ui_manager.begin_frame();
render_menu_bar(&aboutWindow, &settingsWindow); render_menu_bar(&aboutWindow, &settingsWindow);
setup_main_dockspace(first_time); setup_main_dockspace(first_time);
templateEditor.render();
colorEditor.render_controls_and_colors(); colorEditor.render_controls_and_colors();
colorEditor.render_preview(); colorEditor.render_preview();
templateEditor.render();
aboutWindow.render(colorEditor.controller().current_palette()); aboutWindow.render(colorEditor.controller().current_palette());
settingsWindow.render(); settingsWindow.render();
loader.pop_font(); loader.pop_font();
end_frame(window);
ui_manager.end_frame();
backend.end_frame();
} }
shutdown(window);
ui_manager.shutdown();
backend.shutdown();
return 0; return 0;
} }

View File

@@ -0,0 +1,21 @@
#ifndef CLRSYNC_GUI_FILE_BROWSER_HPP
#define CLRSYNC_GUI_FILE_BROWSER_HPP
#include <string>
#include <vector>
namespace file_dialogs
{
std::string open_file_dialog(const std::string &title = "Open File",
const std::string &initial_path = "",
const std::vector<std::string> &filters = {});
std::string save_file_dialog(const std::string &title = "Save File",
const std::string &initial_path = "",
const std::vector<std::string> &filters = {});
std::string select_folder_dialog(const std::string &title = "Select Folder",
const std::string &initial_path = "");
} // namespace file_dialogs
#endif // CLRSYNC_GUI_FILE_BROWSER_HPP

View File

@@ -1,30 +1,30 @@
#ifndef CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP #ifndef CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP
#define CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP #define CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP
#include <imgui.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <imgui.h>
class font_loader class font_loader
{ {
public: public:
font_loader() = default; font_loader() = default;
ImFont* load_font(const char* font_name, float size_px); ImFont *load_font(const char *font_name, float size_px);
void push_default_font(); void push_default_font();
void pop_font(); void pop_font();
std::vector<std::string> get_system_fonts(); std::vector<std::string> get_system_fonts();
private: private:
std::string find_font_path(const char* font_name); std::string find_font_path(const char *font_name);
#if defined(_WIN32) #if defined(_WIN32)
static std::string find_font_windows(const char* font_name); static std::string find_font_windows(const char *font_name);
#elif defined(__APPLE__) #elif defined(__APPLE__)
std::vector<unsigned char> load_font_macos(const char* font_name); std::vector<unsigned char> load_font_macos(const char *font_name);
#else #else
std::string find_font_linux(const char* font_name); std::string find_font_linux(const char *font_name);
#endif #endif
}; };

View File

@@ -0,0 +1,133 @@
#ifdef __linux__
#include "gui/platform/file_browser.hpp"
#include <gtk/gtk.h>
#include <filesystem>
namespace file_dialogs
{
std::string open_file_dialog(const std::string &title, const std::string &initial_path,
const std::vector<std::string> &filters)
{
if (!gtk_init_check(nullptr, nullptr))
{
return "";
}
GtkFileChooserNative *native = gtk_file_chooser_native_new(
title.c_str(), nullptr, GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", "_Cancel");
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
if (!initial_path.empty())
{
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p))
{
if (std::filesystem::is_directory(p))
{
gtk_file_chooser_set_current_folder(chooser, initial_path.c_str());
}
else
{
gtk_file_chooser_set_current_folder(chooser, p.parent_path().c_str());
gtk_file_chooser_set_current_name(chooser, p.filename().c_str());
}
}
}
std::string result;
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)) == GTK_RESPONSE_ACCEPT)
{
char *filename = gtk_file_chooser_get_filename(chooser);
if (filename)
{
result = filename;
g_free(filename);
}
}
g_object_unref(native);
while (gtk_events_pending())
gtk_main_iteration();
return result;
}
std::string save_file_dialog(const std::string &title, const std::string &initial_path,
const std::vector<std::string> &filters)
{
if (!gtk_init_check(nullptr, nullptr))
{
return "";
}
GtkFileChooserNative *native = gtk_file_chooser_native_new(
title.c_str(), nullptr, GTK_FILE_CHOOSER_ACTION_SAVE, "_Save", "_Cancel");
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
if (!initial_path.empty())
{
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p.parent_path()))
{
gtk_file_chooser_set_current_folder(chooser, p.parent_path().c_str());
gtk_file_chooser_set_current_name(chooser, p.filename().c_str());
}
}
std::string result;
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)) == GTK_RESPONSE_ACCEPT)
{
char *filename = gtk_file_chooser_get_filename(chooser);
if (filename)
{
result = filename;
g_free(filename);
}
}
g_object_unref(native);
while (gtk_events_pending())
gtk_main_iteration();
return result;
}
std::string select_folder_dialog(const std::string &title, const std::string &initial_path)
{
if (!gtk_init_check(nullptr, nullptr))
{
return "";
}
GtkFileChooserNative *native = gtk_file_chooser_native_new(
title.c_str(), nullptr, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Select", "_Cancel");
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
if (!initial_path.empty() && std::filesystem::exists(initial_path))
{
gtk_file_chooser_set_current_folder(chooser, initial_path.c_str());
}
std::string result;
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)) == GTK_RESPONSE_ACCEPT)
{
char *filename = gtk_file_chooser_get_filename(chooser);
if (filename)
{
result = filename;
g_free(filename);
}
}
g_object_unref(native);
while (gtk_events_pending())
gtk_main_iteration();
return result;
}
} // namespace file_dialogs
#endif

View File

@@ -0,0 +1,95 @@
#ifdef __linux__
#include "core/config/config.hpp"
#include "gui/platform/font_loader.hpp"
#include "imgui_internal.h"
#include <algorithm>
#include <fontconfig/fontconfig.h>
#include <imgui.h>
std::string font_loader::find_font_linux(const char *font_name)
{
FcInit();
FcPattern *pattern = FcNameParse(reinterpret_cast<const FcChar8 *>(font_name));
if (!pattern)
return {};
FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
FcResult result;
FcPattern *match = FcFontMatch(nullptr, pattern, &result);
std::string out;
if (match)
{
FcChar8 *file = nullptr;
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch)
out = reinterpret_cast<const char *>(file);
FcPatternDestroy(match);
}
FcPatternDestroy(pattern);
return out;
}
std::string font_loader::find_font_path(const char *font_name)
{
return find_font_linux(font_name);
}
ImFont *font_loader::load_font(const char *font_name, float size_px)
{
std::string path = find_font_path(font_name);
if (path.empty())
return nullptr;
float scale = ImGui::GetIO().DisplayFramebufferScale.y;
return ImGui::GetIO().Fonts->AddFontFromFileTTF(path.c_str(), size_px * scale);
}
void font_loader::push_default_font()
{
ImGui::PushFont(ImGui::GetDefaultFont(), clrsync::core::config::instance().font_size());
}
void font_loader::pop_font()
{
ImGui::PopFont();
}
std::vector<std::string> font_loader::get_system_fonts()
{
std::vector<std::string> fonts;
FcInit();
FcPattern *pattern = FcPatternCreate();
FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, nullptr);
FcFontSet *fs = FcFontList(nullptr, pattern, os);
if (fs)
{
for (int i = 0; i < fs->nfont; i++)
{
FcChar8 *family = nullptr;
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch)
{
std::string font_name = reinterpret_cast<const char *>(family);
if (std::find(fonts.begin(), fonts.end(), font_name) == fonts.end())
fonts.push_back(font_name);
}
}
FcFontSetDestroy(fs);
}
FcObjectSetDestroy(os);
FcPatternDestroy(pattern);
std::sort(fonts.begin(), fonts.end());
return fonts;
}
#endif

View File

@@ -0,0 +1,78 @@
#ifdef __APPLE__
#include "gui/platform/file_browser.hpp"
#include <filesystem>
#include <Cocoa/Cocoa.h>
namespace file_dialogs {
std::string open_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:YES];
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string save_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSSavePanel* panel = [NSSavePanel savePanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
if (!initial_path.empty()) {
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p.parent_path())) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:p.parent_path().c_str()]];
[panel setDirectoryURL:url];
[panel setNameFieldStringValue:[NSString stringWithUTF8String:p.filename().c_str()]];
}
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [panel URL];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string select_folder_dialog(const std::string& title,
const std::string& initial_path) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
}
#endif

View File

@@ -0,0 +1,115 @@
#ifdef __APPLE__
#include "core/config/config.hpp"
#include "gui/platform/font_loader.hpp"
#include "imgui_internal.h"
#include <CoreText/CoreText.h>
#include <algorithm>
#include <imgui.h>
std::vector<unsigned char> font_loader::load_font_macos(const char *font_name)
{
std::vector<unsigned char> out;
CFStringRef cf_name = CFStringCreateWithCString(nullptr, font_name, kCFStringEncodingUTF8);
if (!cf_name)
return out;
CTFontDescriptorRef desc = CTFontDescriptorCreateWithNameAndSize(cf_name, 12);
CFRelease(cf_name);
if (!desc)
return out;
CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(desc, kCTFontURLAttribute);
CFRelease(desc);
if (!url)
return out;
CFDataRef data = nullptr;
Boolean success = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, url, &data,
nullptr, nullptr, nullptr);
CFRelease(url);
if (success && data)
{
CFIndex size = CFDataGetLength(data);
if (size > 100)
{
out.resize(size);
CFDataGetBytes(data, CFRangeMake(0, size), out.data());
}
CFRelease(data);
}
return out;
}
std::string font_loader::find_font_path(const char *font_name)
{
(void)font_name;
return {};
}
ImFont *font_loader::load_font(const char *font_name, float size_px)
{
std::vector<unsigned char> buf = load_font_macos(font_name);
if (buf.empty())
return nullptr;
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(buf.data(), static_cast<int>(buf.size()),
size_px);
}
void font_loader::push_default_font()
{
ImGui::PushFont(ImGui::GetDefaultFont(), clrsync::core::config::instance().font_size());
}
void font_loader::pop_font()
{
ImGui::PopFont();
}
std::vector<std::string> font_loader::get_system_fonts()
{
std::vector<std::string> fonts;
CTFontCollectionRef collection = CTFontCollectionCreateFromAvailableFonts(nullptr);
if (collection)
{
CFArrayRef fontDescriptors = CTFontCollectionCreateMatchingFontDescriptors(collection);
CFRelease(collection);
if (fontDescriptors)
{
CFIndex count = CFArrayGetCount(fontDescriptors);
for (CFIndex i = 0; i < count; i++)
{
CTFontDescriptorRef descriptor =
(CTFontDescriptorRef)CFArrayGetValueAtIndex(fontDescriptors, i);
CFStringRef fontName = (CFStringRef)CTFontDescriptorCopyAttribute(
descriptor, kCTFontDisplayNameAttribute);
if (fontName)
{
char buffer[256];
if (CFStringGetCString(fontName, buffer, sizeof(buffer), kCFStringEncodingUTF8))
{
std::string font_name = buffer;
if (std::find(fonts.begin(), fonts.end(), font_name) == fonts.end())
fonts.push_back(font_name);
}
CFRelease(fontName);
}
}
CFRelease(fontDescriptors);
}
}
std::sort(fonts.begin(), fonts.end());
return fonts;
}
#endif

View File

@@ -0,0 +1,167 @@
#ifdef _WIN32
// clang-format off
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commdlg.h>
#include <shlobj.h>
#include <shlwapi.h>
// clang-format on
#include "gui/platform/file_browser.hpp"
#include <filesystem>
namespace file_dialogs
{
std::string open_file_dialog(const std::string &title, const std::string &initial_path,
const std::vector<std::string> &filters)
{
OPENFILENAMEA ofn;
char file[MAX_PATH] = "";
std::string filter_str = "All Files (*.*)\0*.*\0";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFile = file;
ofn.nMaxFile = sizeof(file);
ofn.lpstrFilter = filter_str.c_str();
ofn.nFilterIndex = 1;
ofn.lpstrTitle = title.c_str();
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
if (!initial_path.empty() && std::filesystem::exists(initial_path))
{
std::filesystem::path p(initial_path);
if (std::filesystem::is_directory(p))
{
ofn.lpstrInitialDir = initial_path.c_str();
}
else
{
std::string dir = p.parent_path().string();
std::string name = p.filename().string();
ofn.lpstrInitialDir = dir.c_str();
strncpy(file, name.c_str(), sizeof(file) - 1);
}
}
if (GetOpenFileNameA(&ofn))
{
return std::string(file);
}
return "";
}
std::string save_file_dialog(const std::string &title, const std::string &initial_path,
const std::vector<std::string> &filters)
{
OPENFILENAMEA ofn;
char file[MAX_PATH] = "";
std::string filter_str = "All Files\0*.*\0\0";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFile = file;
ofn.nMaxFile = sizeof(file);
ofn.lpstrFilter = filter_str.c_str();
ofn.nFilterIndex = 1;
ofn.lpstrTitle = title.c_str();
ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR;
if (!initial_path.empty())
{
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p) && std::filesystem::is_directory(p))
{
ofn.lpstrInitialDir = initial_path.c_str();
}
else
{
std::string dir = p.parent_path().string();
std::string name = p.filename().string();
if (std::filesystem::exists(dir))
{
ofn.lpstrInitialDir = dir.c_str();
strncpy(file, name.c_str(), sizeof(file) - 1);
}
}
}
if (GetSaveFileNameA(&ofn))
{
return std::string(file);
}
return "";
}
std::string select_folder_dialog(const std::string &title, const std::string &initial_path)
{
IFileOpenDialog *pFileOpen;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog,
reinterpret_cast<void **>(&pFileOpen));
if (SUCCEEDED(hr))
{
DWORD dwFlags;
if (SUCCEEDED(pFileOpen->GetOptions(&dwFlags)))
{
pFileOpen->SetOptions(dwFlags | FOS_PICKFOLDERS);
}
std::wstring wtitle(title.begin(), title.end());
pFileOpen->SetTitle(wtitle.c_str());
if (!initial_path.empty() && std::filesystem::exists(initial_path))
{
IShellItem *psi = NULL;
std::wstring winitial(initial_path.begin(), initial_path.end());
hr = SHCreateItemFromParsingName(winitial.c_str(), NULL, IID_IShellItem, (void **)&psi);
if (SUCCEEDED(hr))
{
pFileOpen->SetFolder(psi);
psi->Release();
}
}
hr = pFileOpen->Show(GetActiveWindow());
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
if (SUCCEEDED(hr))
{
std::wstring wpath(pszFilePath);
int size = WideCharToMultiByte(CP_UTF8, 0, wpath.c_str(), -1, nullptr, 0,
nullptr, nullptr);
std::string result(size - 1, 0);
WideCharToMultiByte(CP_UTF8, 0, wpath.c_str(), -1, &result[0], size, nullptr,
nullptr);
CoTaskMemFree(pszFilePath);
pItem->Release();
pFileOpen->Release();
return result;
}
pItem->Release();
}
}
pFileOpen->Release();
}
return "";
}
} // namespace file_dialogs
#endif

View File

@@ -0,0 +1,170 @@
#ifdef _WIN32
#include "core/config/config.hpp"
#include "gui/platform/font_loader.hpp"
#include "imgui_internal.h"
#include <algorithm>
#include <imgui.h>
#include <windows.h>
#include <winreg.h>
static std::string search_registry_for_font(HKEY root_key, const char *subkey,
const std::string &font_name_lower,
const char *default_font_dir)
{
HKEY hKey;
LONG result = RegOpenKeyExA(root_key, subkey, 0, KEY_READ, &hKey);
if (result != ERROR_SUCCESS)
return {};
char value_name[512];
BYTE value_data[512];
DWORD value_name_size, value_data_size, type;
DWORD index = 0;
std::string found_path;
while (true)
{
value_name_size = sizeof(value_name);
value_data_size = sizeof(value_data);
result = RegEnumValueA(hKey, index++, value_name, &value_name_size, nullptr, &type,
value_data, &value_data_size);
if (result != ERROR_SUCCESS)
break;
if (type != REG_SZ)
continue;
std::string reg_font_name = value_name;
std::transform(reg_font_name.begin(), reg_font_name.end(), reg_font_name.begin(),
::tolower);
std::string reg_font_name_clean = reg_font_name;
size_t type_pos = reg_font_name_clean.find(" (");
if (type_pos != std::string::npos)
reg_font_name_clean = reg_font_name_clean.substr(0, type_pos);
if (reg_font_name_clean == font_name_lower)
{
std::string font_file = reinterpret_cast<char *>(value_data);
// If path is not absolute, prepend default font directory
if (font_file.find(":\\") == std::string::npos)
{
found_path = std::string(default_font_dir) + "\\" + font_file;
}
else
{
found_path = font_file;
}
break;
}
}
RegCloseKey(hKey);
return found_path;
}
std::string font_loader::find_font_windows(const char *font_name)
{
std::string font_name_lower = font_name;
std::transform(font_name_lower.begin(), font_name_lower.end(), font_name_lower.begin(),
::tolower);
char windows_dir[MAX_PATH];
GetWindowsDirectoryA(windows_dir, MAX_PATH);
std::string system_fonts_dir = std::string(windows_dir) + "\\Fonts";
// First, try system-wide fonts (HKEY_LOCAL_MACHINE)
std::string path = search_registry_for_font(
HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
font_name_lower, system_fonts_dir.c_str());
if (!path.empty())
return path;
// If not found, try per-user fonts (HKEY_CURRENT_USER)
char local_appdata[MAX_PATH];
if (GetEnvironmentVariableA("LOCALAPPDATA", local_appdata, MAX_PATH) > 0)
{
std::string user_fonts_dir = std::string(local_appdata) + "\\Microsoft\\Windows\\Fonts";
path = search_registry_for_font(HKEY_CURRENT_USER,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
font_name_lower, user_fonts_dir.c_str());
}
return path;
}
std::string font_loader::find_font_path(const char *font_name)
{
return find_font_windows(font_name);
}
ImFont *font_loader::load_font(const char *font_name, float size_px)
{
std::string path = find_font_path(font_name);
if (path.empty())
return nullptr;
float scale = ImGui::GetIO().DisplayFramebufferScale.y;
return ImGui::GetIO().Fonts->AddFontFromFileTTF(path.c_str(), size_px * scale);
}
void font_loader::push_default_font()
{
ImGui::PushFont(ImGui::GetDefaultFont(), clrsync::core::config::instance().font_size());
}
void font_loader::pop_font()
{
ImGui::PopFont();
}
std::vector<std::string> font_loader::get_system_fonts()
{
std::vector<std::string> fonts;
auto enumerate_registry_fonts = [&fonts](HKEY root_key, const char *subkey) {
HKEY hKey;
if (RegOpenKeyExA(root_key, subkey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
return;
char value_name[512];
DWORD value_name_size;
DWORD index = 0;
while (true)
{
value_name_size = sizeof(value_name);
LONG result = RegEnumValueA(hKey, index++, value_name, &value_name_size, nullptr,
nullptr, nullptr, nullptr);
if (result != ERROR_SUCCESS)
break;
std::string font_name = value_name;
size_t pos = font_name.find(" (");
if (pos != std::string::npos)
font_name = font_name.substr(0, pos);
if (std::find(fonts.begin(), fonts.end(), font_name) == fonts.end())
fonts.push_back(font_name);
}
RegCloseKey(hKey);
};
enumerate_registry_fonts(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
enumerate_registry_fonts(HKEY_CURRENT_USER,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
std::sort(fonts.begin(), fonts.end());
return fonts;
}
#endif

View File

@@ -1,145 +0,0 @@
#include "preview_renderer.hpp"
#include "theme_applier.hpp"
#include "imgui.h"
#include <algorithm>
preview_renderer::preview_renderer()
{
m_editor.SetLanguageDefinition(TextEditor::LanguageDefinition::CPlusPlus());
m_editor.SetText(R"(#include <iostream>
#include <string>
#include <vector>
#include <filesystem>
#include <cstdlib>
namespace fs = std::filesystem;
std::string expand_user(const std::string &path)
{
if (path.empty()) return "";
std::string result;
if (path[0] == '~')
{
#ifdef _WIN32
const char* home = std::getenv("USERPROFILE");
#else
const char* home = std::getenv("HOME");
#endif
result = home ? std::string(home) : "~";
result += path.substr(1);
}
else
{
result = path;
}
return result;
}
std::vector<std::string> list_files(const std::string &dir_path)
{
std::vector<std::string> files;
try
{
for (const auto &entry : fs::directory_iterator(dir_path))
{
if (entry.is_regular_file())
files.push_back(entry.path().string());
}
}
catch (const std::exception &e)
{
std::cerr << "Error: " << e.what() << std::endl;
}
return files;
}
int main()
{
std::string path = expand_user("~/Documents");
std::cout << "Listing files in: " << path << std::endl;
auto files = list_files(path);
for (const auto &f : files)
std::cout << " " << f << std::endl;
return 0;
})");
m_editor.SetShowWhitespaces(false);
}
void preview_renderer::apply_palette(const clrsync::core::palette& palette)
{
theme_applier::apply_to_editor(m_editor, 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);
ImGui::Text("Code Editor:");
m_editor.Render("##CodeEditor", ImVec2(0, code_preview_height), true);
}
void preview_renderer::render_terminal_preview(const clrsync::core::palette& current)
{
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};
};
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");
ImGui::Spacing();
ImGui::Text("Terminal Preview:");
ImGui::PushStyleColor(ImGuiCol_ChildBg, editor_bg);
ImGui::BeginChild("TerminalPreview", ImVec2(0, 0), true);
ImGui::PushStyleColor(ImGuiCol_Border, border);
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},
};
for (auto &[text, col] : term_lines)
{
ImGui::TextColored(col, "%s", text);
}
ImGui::PopStyleColor(2);
ImGui::EndChild();
}
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");
return;
}
render_code_preview();
render_terminal_preview(current);
}

71
src/gui/ui_manager.cpp Normal file
View File

@@ -0,0 +1,71 @@
#include "gui/ui_manager.hpp"
#include "gui/backend/backend.hpp"
#include <imgui.h>
namespace clrsync::gui
{
ui_manager::ui_manager(backend::backend_interface* backend)
: m_backend(backend)
{
}
ui_manager::~ui_manager()
{
shutdown();
}
bool ui_manager::initialize(const ui_config& config)
{
IMGUI_CHECKVERSION();
m_imgui_context = ImGui::CreateContext();
if (!m_imgui_context)
{
return false;
}
ImGuiIO& io = ImGui::GetIO();
if (config.enable_docking)
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
if (config.enable_keyboard_nav)
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
if (!config.ini_path.empty())
io.IniFilename = config.ini_path.c_str();
ImGui::StyleColorsDark();
if (!m_backend->init_imgui_backend())
{
ImGui::DestroyContext(static_cast<ImGuiContext*>(m_imgui_context));
m_imgui_context = nullptr;
return false;
}
return true;
}
void ui_manager::shutdown()
{
if (m_imgui_context)
{
m_backend->shutdown_imgui_backend();
ImGui::DestroyContext(static_cast<ImGuiContext*>(m_imgui_context));
m_imgui_context = nullptr;
}
}
void ui_manager::begin_frame()
{
m_backend->imgui_new_frame();
ImGui::NewFrame();
}
void ui_manager::end_frame()
{
ImGui::Render();
m_backend->imgui_render_draw_data(ImGui::GetDrawData());
}
}

38
src/gui/ui_manager.hpp Normal file
View File

@@ -0,0 +1,38 @@
#ifndef CLRSYNC_UI_MANAGER_HPP
#define CLRSYNC_UI_MANAGER_HPP
#include <string>
namespace clrsync::gui::backend
{
class backend_interface;
}
namespace clrsync::gui
{
struct ui_config
{
std::string ini_path = "";
bool enable_docking = true;
bool enable_keyboard_nav = true;
};
class ui_manager
{
public:
explicit ui_manager(backend::backend_interface *backend);
~ui_manager();
bool initialize(const ui_config& config = ui_config());
void shutdown();
void begin_frame();
void end_frame();
private:
backend::backend_interface *m_backend;
void *m_imgui_context = nullptr;
};
}
#endif

View File

@@ -1,13 +1,13 @@
#include "about_window.hpp" #include "gui/views/about_window.hpp"
#include "core/version.hpp" #include "core/common/version.hpp"
#include "imgui_helpers.hpp" #include "gui/helpers/imgui_helpers.hpp"
#include "imgui.h" #include "imgui.h"
about_window::about_window() about_window::about_window()
{ {
} }
void about_window::render(const clrsync::core::palette& pal) void about_window::render(const clrsync::core::palette &pal)
{ {
if (!m_visible) if (!m_visible)
return; return;

View File

@@ -0,0 +1,33 @@
#ifndef CLRSYNC_GUI_ABOUT_WINDOW_HPP
#define CLRSYNC_GUI_ABOUT_WINDOW_HPP
#include "core/palette/palette.hpp"
class about_window
{
public:
about_window();
void render(const clrsync::core::palette &pal);
void render()
{
render(m_default_palette);
}
void show()
{
m_visible = true;
}
void hide()
{
m_visible = false;
}
bool is_visible() const
{
return m_visible;
}
private:
bool m_visible{false};
clrsync::core::palette m_default_palette;
};
#endif // CLRSYNC_GUI_ABOUT_WINDOW_HPP

View File

@@ -1,13 +1,12 @@
#include "color_scheme_editor.hpp" #include "color_scheme_editor.hpp"
#include "gui/controllers/theme_applier.hpp"
#include "gui/helpers/imgui_helpers.hpp"
#include "imgui.h" #include "imgui.h"
#include "imgui_helpers.hpp"
#include "template_editor.hpp"
#include "settings_window.hpp" #include "settings_window.hpp"
#include "theme_applier.hpp" #include "template_editor.hpp"
#include <iostream> #include <iostream>
#include <ranges> #include <ranges>
color_scheme_editor::color_scheme_editor() color_scheme_editor::color_scheme_editor()
{ {
const auto &current = m_controller.current_palette(); const auto &current = m_controller.current_palette();
@@ -161,10 +160,8 @@ void color_scheme_editor::render_controls()
ImGui::SameLine(); ImGui::SameLine();
auto error = palette_utils::get_color(current, "error"); auto error = palette_utils::get_color(current, "error");
auto error_hover = ImVec4(error.x * 1.1f, error.y * 1.1f, error.z * 1.1f, auto error_hover = ImVec4(error.x * 1.1f, error.y * 1.1f, error.z * 1.1f, error.w);
error.w); auto error_active = ImVec4(error.x * 0.8f, error.y * 0.8f, error.z * 0.8f, error.w);
auto error_active = ImVec4(error.x * 0.8f, error.y * 0.8f, error.z * 0.8f,
error.w);
auto on_error = palette_utils::get_color(current, "on_error"); auto on_error = palette_utils::get_color(current, "on_error");
ImGui::PushStyleColor(ImGuiCol_Button, error); ImGui::PushStyleColor(ImGuiCol_Button, error);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, error_hover); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, error_hover);

View File

@@ -0,0 +1,44 @@
#ifndef CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP
#define CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP
#include "gui/controllers/palette_controller.hpp"
#include "gui/views/color_table_renderer.hpp"
#include "gui/views/preview_renderer.hpp"
class template_editor;
class settings_window;
class color_scheme_editor
{
public:
color_scheme_editor();
void render_controls_and_colors();
void render_preview();
void set_template_editor(template_editor *editor)
{
m_template_editor = editor;
}
void set_settings_window(settings_window *window)
{
m_settings_window = window;
}
const palette_controller &controller() const
{
return m_controller;
}
private:
void render_controls();
void apply_themes();
void notify_palette_changed();
palette_controller m_controller;
color_table_renderer m_color_table;
preview_renderer m_preview;
template_editor *m_template_editor{nullptr};
settings_window *m_settings_window{nullptr};
bool m_show_delete_confirmation{false};
};
#endif // CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP

View File

@@ -1,11 +1,11 @@
#include "color_table_renderer.hpp" #include "gui/views/color_table_renderer.hpp"
#include "imgui_helpers.hpp" #include "gui/helpers/imgui_helpers.hpp"
#include "imgui.h" #include "imgui.h"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <vector> #include <vector>
bool color_table_renderer::matches_filter(const std::string& name) const bool color_table_renderer::matches_filter(const std::string &name) const
{ {
if (m_filter_text[0] == '\0') if (m_filter_text[0] == '\0')
return true; return true;
@@ -22,9 +22,9 @@ bool color_table_renderer::matches_filter(const std::string& name) const
} }
void color_table_renderer::render_color_row(const std::string &name, void color_table_renderer::render_color_row(const std::string &name,
const clrsync::core::palette& current, const clrsync::core::palette &current,
palette_controller& controller, palette_controller &controller,
const OnColorChangedCallback& on_changed) const OnColorChangedCallback &on_changed)
{ {
if (!matches_filter(name)) if (!matches_filter(name))
return; return;
@@ -101,13 +101,14 @@ void color_table_renderer::render_color_row(const std::string &name,
ImGui::PopID(); ImGui::PopID();
} }
void color_table_renderer::render(const clrsync::core::palette& current, void color_table_renderer::render(const clrsync::core::palette &current,
palette_controller& controller, palette_controller &controller,
const OnColorChangedCallback& on_changed) const OnColorChangedCallback &on_changed)
{ {
if (current.colors().empty()) 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; return;
} }
@@ -117,7 +118,7 @@ void color_table_renderer::render(const clrsync::core::palette& current,
ImGui::SameLine(); ImGui::SameLine();
ImGui::SetNextItemWidth(200); ImGui::SetNextItemWidth(200);
bool filter_changed = ImGui::InputTextWithHint("##color_filter", "Search colors...", bool filter_changed = ImGui::InputTextWithHint("##color_filter", "Search colors...",
m_filter_text, sizeof(m_filter_text)); m_filter_text, sizeof(m_filter_text));
if (m_filter_text[0] != '\0') if (m_filter_text[0] != '\0')
{ {
@@ -131,23 +132,14 @@ void color_table_renderer::render(const clrsync::core::palette& current,
ImGui::SetTooltip("Clear filter"); 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::PopStyleVar();
ImGui::Spacing(); ImGui::Spacing();
ImGui::Separator(); ImGui::Separator();
ImGui::Spacing(); ImGui::Spacing();
auto draw_table = [&](const char *title, const char* id, const std::vector<const char *> &keys) { auto draw_table = [&](const char *title, const char *id,
const std::vector<const char *> &keys) {
bool has_matches = false; bool has_matches = false;
for (auto *k : keys) for (auto *k : keys)
{ {
@@ -162,13 +154,15 @@ void color_table_renderer::render(const clrsync::core::palette& current,
return; return;
ImGui::PushStyleColor(ImGuiCol_Text, palette_utils::get_color(current, "accent")); ImGui::PushStyleColor(ImGuiCol_Text, palette_utils::get_color(current, "accent"));
bool header_open = ImGui::TreeNodeEx(title, ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth); bool header_open = ImGui::TreeNodeEx(title, ImGuiTreeNodeFlags_DefaultOpen |
ImGuiTreeNodeFlags_SpanAvailWidth);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
if (header_open) if (header_open)
{ {
if (ImGui::BeginTable(id, 3, if (ImGui::BeginTable(id, 3,
ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingStretchProp)) ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg |
ImGuiTableFlags_SizingStretchProp))
{ {
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 160.0f); ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 160.0f);
ImGui::TableSetupColumn("HEX", ImGuiTableColumnFlags_WidthFixed, 95.0f); ImGui::TableSetupColumn("HEX", ImGuiTableColumnFlags_WidthFixed, 95.0f);
@@ -186,23 +180,23 @@ void color_table_renderer::render(const clrsync::core::palette& current,
ImGui::Spacing(); ImGui::Spacing();
}; };
draw_table("General UI", "##general_ui", {"background", "on_background", "surface", "on_surface", draw_table("General UI", "##general_ui",
"surface_variant", "on_surface_variant", "foreground", {"background", "on_background", "surface", "on_surface", "surface_variant",
"cursor", "accent"}); "on_surface_variant", "foreground", "cursor", "accent"});
draw_table("Borders", "##borders", {"border_focused", "border"}); draw_table("Borders", "##borders", {"border_focused", "border"});
draw_table("Semantic Colors", "##semantic", {"success", "info", "warning", "error", draw_table(
"on_success", "on_info", "on_warning", "on_error"}); "Semantic Colors", "##semantic",
{"success", "info", "warning", "error", "on_success", "on_info", "on_warning", "on_error"});
draw_table("Editor", "##editor", {"editor_background", "editor_command", "editor_comment", draw_table("Editor", "##editor",
"editor_disabled", "editor_emphasis", "editor_error", {"editor_background", "editor_command", "editor_comment", "editor_disabled",
"editor_inactive", "editor_line_number", "editor_link", "editor_emphasis", "editor_error", "editor_inactive", "editor_line_number",
"editor_main", "editor_selected", "editor_selection_inactive", "editor_link", "editor_main", "editor_selected", "editor_selection_inactive",
"editor_string", "editor_success", "editor_warning"}); "editor_string", "editor_success", "editor_warning"});
draw_table("Terminal (Base16)", "##terminal", {"base00", "base01", "base02", "base03", draw_table("Terminal (Base16)", "##terminal",
"base04", "base05", "base06", "base07", {"base00", "base01", "base02", "base03", "base04", "base05", "base06", "base07",
"base08", "base09", "base0A", "base0B", "base08", "base09", "base0A", "base0B", "base0C", "base0D", "base0E", "base0F"});
"base0C", "base0D", "base0E", "base0F"});
} }

View File

@@ -0,0 +1,27 @@
#ifndef CLRSYNC_GUI_COLOR_TABLE_RENDERER_HPP
#define CLRSYNC_GUI_COLOR_TABLE_RENDERER_HPP
#include "core/palette/palette.hpp"
#include "gui/controllers/palette_controller.hpp"
#include <functional>
#include <string>
class color_table_renderer
{
public:
using OnColorChangedCallback = std::function<void()>;
void render(const clrsync::core::palette &palette, palette_controller &controller,
const OnColorChangedCallback &on_changed);
private:
void render_color_row(const std::string &name, const clrsync::core::palette &palette,
palette_controller &controller, const OnColorChangedCallback &on_changed);
bool matches_filter(const std::string &name) const;
char m_filter_text[128] = {0};
bool m_show_only_modified{false};
};
#endif // CLRSYNC_GUI_COLOR_TABLE_RENDERER_HPP

View File

@@ -0,0 +1,246 @@
#include "gui/views/preview_renderer.hpp"
#include "gui/controllers/theme_applier.hpp"
#include "gui/helpers/imgui_helpers.hpp"
#include "imgui.h"
#include <algorithm>
#include <array>
preview_renderer::preview_renderer()
{
m_editor.SetLanguageDefinition(TextEditor::LanguageDefinition::CPlusPlus());
m_editor.SetText(R"(#include <iostream>
#include <string>
#include <vector>
#include <filesystem>
#include <cstdlib>
namespace fs = std::filesystem;
std::string expand_user(const std::string &path)
{
if (path.empty()) return "";
std::string result;
if (path[0] == '~')
{
#ifdef _WIN32
const char* home = std::getenv("USERPROFILE");
#else
const char* home = std::getenv("HOME");
#endif
result = home ? std::string(home) : "~";
result += path.substr(1);
}
else
{
result = path;
}
return result;
}
std::vector<std::string> list_files(const std::string &dir_path)
{
std::vector<std::string> files;
try
{
for (const auto &entry : fs::directory_iterator(dir_path))
{
if (entry.is_regular_file())
files.push_back(entry.path().string());
}
}
catch (const std::exception &e)
{
std::cerr << "Error: " << e.what() << std::endl;
}
return files;
}
int main()
{
std::string path = expand_user("~/Documents");
std::cout << "Listing files in: " << path << std::endl;
auto files = list_files(path);
for (const auto &f : files)
std::cout << " " << f << std::endl;
return 0;
})");
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);
}
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.50f);
ImGui::Text("Code Editor Preview:");
ImGui::SameLine();
ImGui::TextDisabled("(editor_* colors)");
m_editor.Render("##CodeEditor", ImVec2(0, code_preview_height), true);
}
void preview_renderer::render_terminal_preview(const clrsync::core::palette &current)
{
auto get_color = [&](const std::string &key) -> ImVec4 {
const auto &col = current.get_color(key);
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 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);
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++)
{
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();
}
void preview_renderer::render(const clrsync::core::palette &current)
{
if (current.colors().empty())
{
ImVec4 error_color = palette_utils::get_color(current, "error", "accent");
ImGui::TextColored(error_color, "Current palette is empty");
return;
}
render_code_preview();
render_terminal_preview(current);
}

View File

@@ -1,20 +1,20 @@
#ifndef CLRSYNC_GUI_PREVIEW_RENDERER_HPP #ifndef CLRSYNC_GUI_PREVIEW_RENDERER_HPP
#define CLRSYNC_GUI_PREVIEW_RENDERER_HPP #define CLRSYNC_GUI_PREVIEW_RENDERER_HPP
#include "core/palette/palette.hpp"
#include "color_text_edit/TextEditor.h" #include "color_text_edit/TextEditor.h"
#include "core/palette/palette.hpp"
class preview_renderer class preview_renderer
{ {
public: public:
preview_renderer(); preview_renderer();
void render(const clrsync::core::palette& palette); void render(const clrsync::core::palette &palette);
void apply_palette(const clrsync::core::palette& palette); void apply_palette(const clrsync::core::palette &palette);
private: private:
void render_code_preview(); void render_code_preview();
void render_terminal_preview(const clrsync::core::palette& palette); void render_terminal_preview(const clrsync::core::palette &palette);
TextEditor m_editor; TextEditor m_editor;
}; };

View File

@@ -1,9 +1,9 @@
#include "settings_window.hpp" #include "gui/views/settings_window.hpp"
#include "core/common/error.hpp"
#include "core/config/config.hpp" #include "core/config/config.hpp"
#include "core/error.hpp" #include "gui/helpers/imgui_helpers.hpp"
#include "gui/font_loader.hpp" #include "gui/platform/file_browser.hpp"
#include "gui/imgui_helpers.hpp" #include "gui/platform/font_loader.hpp"
#include "gui/file_browser.hpp"
#include "imgui.h" #include "imgui.h"
#include <cstring> #include <cstring>
@@ -26,7 +26,8 @@ void settings_window::render()
return; return;
ImGui::SetNextWindowSize(ImVec2(700, 500), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(700, 500), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f)); ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_FirstUseEver,
ImVec2(0.5f, 0.5f));
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoCollapse; ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoCollapse;
if (ImGui::Begin("Settings", &m_visible, window_flags)) if (ImGui::Begin("Settings", &m_visible, window_flags))
@@ -58,7 +59,7 @@ void settings_window::render()
void settings_window::load_settings() void settings_window::load_settings()
{ {
auto& cfg = clrsync::core::config::instance(); auto &cfg = clrsync::core::config::instance();
std::string default_theme = cfg.default_theme(); std::string default_theme = cfg.default_theme();
strncpy(m_default_theme, default_theme.c_str(), sizeof(m_default_theme) - 1); strncpy(m_default_theme, default_theme.c_str(), sizeof(m_default_theme) - 1);
@@ -90,7 +91,7 @@ void settings_window::load_settings()
void settings_window::apply_settings() void settings_window::apply_settings()
{ {
auto& cfg = clrsync::core::config::instance(); auto &cfg = clrsync::core::config::instance();
if (strlen(m_default_theme) == 0) if (strlen(m_default_theme) == 0)
{ {
@@ -184,8 +185,10 @@ void settings_window::render_general_tab()
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Browse")) if (ImGui::Button("Browse"))
{ {
std::string selected_path = file_dialogs::select_folder_dialog("Select Palettes Directory", m_palettes_path); std::string selected_path =
if (!selected_path.empty()) { file_dialogs::select_folder_dialog("Select Palettes Directory", m_palettes_path);
if (!selected_path.empty())
{
strncpy(m_palettes_path, selected_path.c_str(), sizeof(m_palettes_path) - 1); strncpy(m_palettes_path, selected_path.c_str(), sizeof(m_palettes_path) - 1);
m_palettes_path[sizeof(m_palettes_path) - 1] = '\0'; m_palettes_path[sizeof(m_palettes_path) - 1] = '\0';
m_settings_changed = true; m_settings_changed = true;
@@ -250,12 +253,41 @@ void settings_window::render_status_messages()
if (!m_error_message.empty()) if (!m_error_message.empty())
{ {
ImGui::Spacing(); ImGui::Spacing();
auto error_color = palette_utils::get_color(m_current_palette, "error");
ImGui::PushStyleColor(ImGuiCol_Text, error_color); auto error_bg_color = palette_utils::get_color(m_current_palette, "error");
ImGui::TextWrapped("Error: %s", m_error_message.c_str()); auto error_text_color = palette_utils::get_color(m_current_palette, "on_error");
ImGui::PopStyleColor();
if (ImGui::Button("Dismiss##error")) ImGui::PushStyleColor(ImGuiCol_ChildBg, error_bg_color);
m_error_message.clear(); 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);
} }
} }
@@ -323,7 +355,7 @@ void settings_window::render_action_buttons()
} }
} }
void settings_window::show_help_marker(const char* desc) void settings_window::show_help_marker(const char *desc)
{ {
ImGui::TextDisabled("(?)"); ImGui::TextDisabled("(?)");
if (ImGui::BeginItemTooltip()) if (ImGui::BeginItemTooltip())

View File

@@ -7,14 +7,23 @@
class settings_window class settings_window
{ {
public: public:
settings_window(); settings_window();
void render(); void render();
void show() { m_visible = true; } void show()
void hide() { m_visible = false; } {
bool is_visible() const { return m_visible; } m_visible = true;
}
void hide()
{
m_visible = false;
}
bool is_visible() const
{
return m_visible;
}
private: private:
void load_settings(); void load_settings();
void save_settings(); void save_settings();
void apply_settings(); void apply_settings();
@@ -22,11 +31,12 @@ private:
void render_appearance_tab(); void render_appearance_tab();
void render_status_messages(); void render_status_messages();
void render_action_buttons(); void render_action_buttons();
void show_help_marker(const char* desc); void show_help_marker(const char *desc);
void reset_to_defaults(); void reset_to_defaults();
public: public:
void set_palette(const clrsync::core::palette& palette) { void set_palette(const clrsync::core::palette &palette)
{
m_current_palette = palette; m_current_palette = palette;
} }

View File

@@ -1,24 +1,21 @@
#include "template_editor.hpp" #include "template_editor.hpp"
#include "core/common/utils.hpp"
#include "core/config/config.hpp" #include "core/config/config.hpp"
#include "core/theme/theme_template.hpp"
#include "core/palette/color_keys.hpp" #include "core/palette/color_keys.hpp"
#include "core/utils.hpp" #include "core/theme/theme_template.hpp"
#include "imgui_helpers.hpp" #include "gui/helpers/imgui_helpers.hpp"
#include "file_browser.hpp" #include "gui/platform/file_browser.hpp"
#include "imgui.h" #include "imgui.h"
#include <algorithm> #include <algorithm>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <ranges> #include <ranges>
namespace { namespace
const std::vector<std::string> COLOR_FORMATS = { {
"hex", "hex_stripped", "hexa", "hexa_stripped", const std::vector<std::string> COLOR_FORMATS = {
"r", "g", "b", "a", "hex", "hex_stripped", "hexa", "hexa_stripped", "r", "g", "b", "a", "rgb", "rgba", "h", "s",
"rgb", "rgba", "l", "hsl", "hsla"};
"h", "s", "l",
"hsl", "hsla"
};
} }
template_editor::template_editor() : m_template_name("new_template") template_editor::template_editor() : m_template_name("new_template")
@@ -102,13 +99,14 @@ void template_editor::apply_current_palette(const clrsync::core::palette &pal)
m_editor.SetPalette(palette); 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_bg_color.w = 0.98f;
m_autocomplete_border_color = palette_utils::get_color(pal, "border", "editor_inactive"); m_autocomplete_border_color = palette_utils::get_color(pal, "border", "surface_variant");
m_autocomplete_selected_color = palette_utils::get_color(pal, "editor_selected", "surface_variant"); m_autocomplete_selected_color = palette_utils::get_color(pal, "accent", "surface_variant");
m_autocomplete_text_color = palette_utils::get_color(pal, "editor_main", "foreground"); m_autocomplete_text_color = palette_utils::get_color(pal, "on_surface", "foreground");
m_autocomplete_selected_text_color = palette_utils::get_color(pal, "foreground", "editor_main"); m_autocomplete_selected_text_color = palette_utils::get_color(pal, "on_surface", "foreground");
m_autocomplete_dim_text_color = palette_utils::get_color(pal, "editor_comment", "editor_inactive"); m_autocomplete_dim_text_color =
palette_utils::get_color(pal, "on_surface_variant", "editor_inactive");
} }
void template_editor::update_autocomplete_suggestions() void template_editor::update_autocomplete_suggestions()
@@ -148,8 +146,7 @@ void template_editor::update_autocomplete_suggestions()
{ {
bool should_reset_dismissal = false; bool should_reset_dismissal = false;
if (cursor.mLine != m_dismiss_position.mLine || if (cursor.mLine != m_dismiss_position.mLine || brace_pos != m_dismiss_brace_pos ||
brace_pos != m_dismiss_brace_pos ||
abs(cursor.mColumn - m_dismiss_position.mColumn) > 3) abs(cursor.mColumn - m_dismiss_position.mColumn) > 3)
{ {
should_reset_dismissal = true; should_reset_dismissal = true;
@@ -190,8 +187,7 @@ void template_editor::update_autocomplete_suggestions()
{ {
for (const auto &fmt : COLOR_FORMATS) for (const auto &fmt : COLOR_FORMATS)
{ {
if (format_prefix.empty() || if (format_prefix.empty() || fmt.find(format_prefix) == 0 ||
fmt.find(format_prefix) == 0 ||
fmt.find(format_prefix) != std::string::npos) fmt.find(format_prefix) != std::string::npos)
{ {
m_autocomplete_suggestions.push_back(color_key + "." + fmt); m_autocomplete_suggestions.push_back(color_key + "." + fmt);
@@ -204,8 +200,7 @@ void template_editor::update_autocomplete_suggestions()
for (size_t i = 0; i < clrsync::core::NUM_COLOR_KEYS; ++i) for (size_t i = 0; i < clrsync::core::NUM_COLOR_KEYS; ++i)
{ {
std::string key = clrsync::core::COLOR_KEYS[i]; std::string key = clrsync::core::COLOR_KEYS[i];
if (m_autocomplete_prefix.empty() || if (m_autocomplete_prefix.empty() || key.find(m_autocomplete_prefix) == 0 ||
key.find(m_autocomplete_prefix) == 0 ||
key.find(m_autocomplete_prefix) != std::string::npos) key.find(m_autocomplete_prefix) != std::string::npos)
{ {
m_autocomplete_suggestions.push_back(key); m_autocomplete_suggestions.push_back(key);
@@ -214,13 +209,13 @@ void template_editor::update_autocomplete_suggestions()
} }
std::sort(m_autocomplete_suggestions.begin(), m_autocomplete_suggestions.end(), std::sort(m_autocomplete_suggestions.begin(), m_autocomplete_suggestions.end(),
[this](const std::string &a, const std::string &b) { [this](const std::string &a, const std::string &b) {
bool a_prefix = a.find(m_autocomplete_prefix) == 0; bool a_prefix = a.find(m_autocomplete_prefix) == 0;
bool b_prefix = b.find(m_autocomplete_prefix) == 0; bool b_prefix = b.find(m_autocomplete_prefix) == 0;
if (a_prefix != b_prefix) if (a_prefix != b_prefix)
return a_prefix; return a_prefix;
return a < b; return a < b;
}); });
m_show_autocomplete = !m_autocomplete_suggestions.empty(); m_show_autocomplete = !m_autocomplete_suggestions.empty();
if (m_show_autocomplete && m_autocomplete_selected >= (int)m_autocomplete_suggestions.size()) if (m_show_autocomplete && m_autocomplete_selected >= (int)m_autocomplete_suggestions.size())
@@ -229,7 +224,7 @@ void template_editor::update_autocomplete_suggestions()
} }
} }
void template_editor::render_autocomplete(const ImVec2& editor_pos) void template_editor::render_autocomplete(const ImVec2 &editor_pos)
{ {
if (!m_show_autocomplete || m_autocomplete_suggestions.empty()) if (!m_show_autocomplete || m_autocomplete_suggestions.empty())
return; return;
@@ -241,7 +236,8 @@ void template_editor::render_autocomplete(const ImVec2& editor_pos)
const float line_number_width = 50.0f; const float line_number_width = 50.0f;
ImVec2 popup_pos; ImVec2 popup_pos;
popup_pos.x = editor_pos.x + line_number_width + (m_autocomplete_start_pos.mColumn * char_width); popup_pos.x =
editor_pos.x + line_number_width + (m_autocomplete_start_pos.mColumn * char_width);
popup_pos.y = editor_pos.y + ((cursor.mLine + 1) * line_height); popup_pos.y = editor_pos.y + ((cursor.mLine + 1) * line_height);
ImGui::SetNextWindowPos(popup_pos, ImGuiCond_Always); ImGui::SetNextWindowPos(popup_pos, ImGuiCond_Always);
@@ -249,7 +245,8 @@ void template_editor::render_autocomplete(const ImVec2& editor_pos)
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_AlwaysAutoResize; ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_AlwaysAutoResize;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(6, 6)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(6, 6));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
@@ -295,8 +292,8 @@ void template_editor::render_autocomplete(const ImVec2& editor_pos)
std::string display_text = " " + suggestion; std::string display_text = " " + suggestion;
if (ImGui::Selectable(display_text.c_str(), is_selected, if (ImGui::Selectable(display_text.c_str(), is_selected, ImGuiSelectableFlags_None,
ImGuiSelectableFlags_None, ImVec2(0, 0))) ImVec2(0, 0)))
{ {
auto start = m_autocomplete_start_pos; auto start = m_autocomplete_start_pos;
auto end = m_editor.GetCursorPosition(); auto end = m_editor.GetCursorPosition();
@@ -362,8 +359,7 @@ void template_editor::render()
} }
palette_utils::render_delete_confirmation_popup( palette_utils::render_delete_confirmation_popup(
"Delete Template?", m_template_name, "template", m_current_palette, "Delete Template?", m_template_name, "template", m_current_palette, [this]() {
[this]() {
bool success = m_template_controller.remove_template(m_template_name); bool success = m_template_controller.remove_template(m_template_name);
if (success) if (success)
{ {
@@ -408,10 +404,8 @@ void template_editor::render_controls()
{ {
ImGui::SameLine(); ImGui::SameLine();
auto error = palette_utils::get_color(m_current_palette, "error"); auto error = palette_utils::get_color(m_current_palette, "error");
auto error_hover = ImVec4(error.x * 1.1f, error.y * 1.1f, error.z * 1.1f, auto error_hover = ImVec4(error.x * 1.1f, error.y * 1.1f, error.z * 1.1f, error.w);
error.w); auto error_active = ImVec4(error.x * 0.8f, error.y * 0.8f, error.z * 0.8f, error.w);
auto error_active = ImVec4(error.x * 0.8f, error.y * 0.8f, error.z * 0.8f,
error.w);
auto on_error = palette_utils::get_color(m_current_palette, "on_error"); auto on_error = palette_utils::get_color(m_current_palette, "on_error");
ImGui::PushStyleColor(ImGuiCol_Button, error); ImGui::PushStyleColor(ImGuiCol_Button, error);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, error_hover); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, error_hover);
@@ -433,20 +427,26 @@ void template_editor::render_controls()
if (m_enabled) if (m_enabled)
{ {
ImVec4 success_color = palette_utils::get_color(m_current_palette, "success", "accent"); ImVec4 success_color = palette_utils::get_color(m_current_palette, "success", "accent");
ImVec4 success_hover = ImVec4(success_color.x * 1.2f, success_color.y * 1.2f, success_color.z * 1.2f, 0.6f); ImVec4 success_on_color =
ImVec4 success_check = ImVec4(success_color.x * 1.5f, success_color.y * 1.5f, success_color.z * 1.5f, 1.0f); palette_utils::get_color(m_current_palette, "on_success", "on_surface");
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(success_color.x, success_color.y, success_color.z, 0.5f)); ImVec4 success_hover =
ImVec4(success_color.x * 1.2f, success_color.y * 1.2f, success_color.z * 1.2f, 0.6f);
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_FrameBgHovered, success_hover);
ImGui::PushStyleColor(ImGuiCol_CheckMark, success_check); ImGui::PushStyleColor(ImGuiCol_CheckMark, success_on_color);
} }
else else
{ {
ImVec4 error_color = palette_utils::get_color(m_current_palette, "error", "accent"); ImVec4 error_color = palette_utils::get_color(m_current_palette, "error", "accent");
ImVec4 error_hover = ImVec4(error_color.x * 1.2f, error_color.y * 1.2f, error_color.z * 1.2f, 0.6f); ImVec4 error_on_color =
ImVec4 error_check = ImVec4(error_color.x * 1.5f, error_color.y * 1.5f, error_color.z * 1.5f, 1.0f); palette_utils::get_color(m_current_palette, "on_error", "on_surface");
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(error_color.x, error_color.y, error_color.z, 0.5f)); ImVec4 error_hover =
ImVec4(error_color.x * 1.2f, error_color.y * 1.2f, error_color.z * 1.2f, 0.6f);
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_FrameBgHovered, error_hover);
ImGui::PushStyleColor(ImGuiCol_CheckMark, error_check); ImGui::PushStyleColor(ImGuiCol_CheckMark, error_on_color);
} }
enabled_changed = ImGui::Checkbox("Enabled", &m_enabled); enabled_changed = ImGui::Checkbox("Enabled", &m_enabled);
@@ -486,8 +486,8 @@ void template_editor::render_controls()
ImGui::SetNextItemWidth(-120.0f); ImGui::SetNextItemWidth(-120.0f);
char input_path_buf[512] = {0}; char input_path_buf[512] = {0};
snprintf(input_path_buf, sizeof(input_path_buf), "%s", m_input_path.c_str()); snprintf(input_path_buf, sizeof(input_path_buf), "%s", m_input_path.c_str());
if (ImGui::InputTextWithHint("##input_path", "Path to template file...", if (ImGui::InputTextWithHint("##input_path", "Path to template file...", input_path_buf,
input_path_buf, sizeof(input_path_buf))) sizeof(input_path_buf)))
{ {
m_input_path = input_path_buf; m_input_path = input_path_buf;
if (!m_input_path.empty()) if (!m_input_path.empty())
@@ -502,10 +502,13 @@ void template_editor::render_controls()
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Browse##input")) if (ImGui::Button("Browse##input"))
{ {
std::string selected_path = file_dialogs::open_file_dialog("Select Template File", m_input_path); std::string selected_path =
if (!selected_path.empty()) { file_dialogs::open_file_dialog("Select Template File", m_input_path);
if (!selected_path.empty())
{
m_input_path = selected_path; m_input_path = selected_path;
if (m_is_editing_existing) { if (m_is_editing_existing)
{
m_template_controller.set_template_input_path(m_template_name, m_input_path); m_template_controller.set_template_input_path(m_template_name, m_input_path);
} }
m_validation_error = ""; m_validation_error = "";
@@ -520,8 +523,8 @@ void template_editor::render_controls()
ImGui::SetNextItemWidth(-120.0f); ImGui::SetNextItemWidth(-120.0f);
char path_buf[512] = {0}; char path_buf[512] = {0};
snprintf(path_buf, sizeof(path_buf), "%s", m_output_path.c_str()); snprintf(path_buf, sizeof(path_buf), "%s", m_output_path.c_str());
if (ImGui::InputTextWithHint("##output_path", "Path for generated config...", if (ImGui::InputTextWithHint("##output_path", "Path for generated config...", path_buf,
path_buf, sizeof(path_buf))) sizeof(path_buf)))
{ {
m_output_path = path_buf; m_output_path = path_buf;
if (!m_output_path.empty()) if (!m_output_path.empty())
@@ -536,10 +539,13 @@ void template_editor::render_controls()
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Browse##output")) if (ImGui::Button("Browse##output"))
{ {
std::string selected_path = file_dialogs::save_file_dialog("Select Output File", m_output_path); std::string selected_path =
if (!selected_path.empty()) { file_dialogs::save_file_dialog("Select Output File", m_output_path);
if (!selected_path.empty())
{
m_output_path = selected_path; m_output_path = selected_path;
if (m_is_editing_existing) { if (m_is_editing_existing)
{
m_template_controller.set_template_output_path(m_template_name, m_output_path); m_template_controller.set_template_output_path(m_template_name, m_output_path);
} }
m_validation_error = ""; m_validation_error = "";
@@ -554,8 +560,8 @@ void template_editor::render_controls()
ImGui::SetNextItemWidth(-FLT_MIN); ImGui::SetNextItemWidth(-FLT_MIN);
char reload_buf[512] = {0}; char reload_buf[512] = {0};
snprintf(reload_buf, sizeof(reload_buf), "%s", m_reload_command.c_str()); snprintf(reload_buf, sizeof(reload_buf), "%s", m_reload_command.c_str());
if (ImGui::InputTextWithHint("##reload_cmd", "Command to reload app (optional)...", if (ImGui::InputTextWithHint("##reload_cmd", "Command to reload app (optional)...", reload_buf,
reload_buf, sizeof(reload_buf))) sizeof(reload_buf)))
{ {
m_reload_command = reload_buf; m_reload_command = reload_buf;
if (m_is_editing_existing) if (m_is_editing_existing)
@@ -569,7 +575,8 @@ void template_editor::render_controls()
if (!m_validation_error.empty()) if (!m_validation_error.empty())
{ {
ImGui::Spacing(); 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::TextWrapped("%s", m_validation_error.c_str());
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
@@ -581,7 +588,8 @@ void template_editor::render_editor()
if (!m_is_editing_existing) 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::Text(" New Template");
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
@@ -600,35 +608,13 @@ void template_editor::render_editor()
if (m_has_unsaved_changes) if (m_has_unsaved_changes)
{ {
ImGui::SameLine(); 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::Text("(unsaved)");
ImGui::PopStyleColor(); 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::PopStyleVar();
ImGui::Separator(); ImGui::Separator();
@@ -728,7 +714,9 @@ void template_editor::render_template_list()
if (!tmpl.enabled()) 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)) if (ImGui::Selectable(key.c_str(), selected))
@@ -857,7 +845,7 @@ void template_editor::save_template()
{ {
std::filesystem::create_directories(parent_dir); std::filesystem::create_directories(parent_dir);
} }
catch (const std::exception& e) catch (const std::exception &e)
{ {
m_validation_error = "Error: Could not create directory for input path"; m_validation_error = "Error: Could not create directory for input path";
return; return;

View File

@@ -1,25 +1,25 @@
#ifndef CLRSYNC_GUI_TEMPLATE_EDITOR_HPP #ifndef CLRSYNC_GUI_TEMPLATE_EDITOR_HPP
#define CLRSYNC_GUI_TEMPLATE_EDITOR_HPP #define CLRSYNC_GUI_TEMPLATE_EDITOR_HPP
#include "template_controller.hpp"
#include <core/palette/palette.hpp>
#include "color_text_edit/TextEditor.h" #include "color_text_edit/TextEditor.h"
#include "core/palette/palette.hpp"
#include "gui/controllers/template_controller.hpp"
#include "imgui.h" #include "imgui.h"
#include <string> #include <string>
#include <vector> #include <vector>
class template_editor class template_editor
{ {
public: public:
template_editor(); template_editor();
void render(); void render();
void apply_current_palette(const clrsync::core::palette& pal); void apply_current_palette(const clrsync::core::palette &pal);
private: private:
void render_controls(); void render_controls();
void render_editor(); void render_editor();
void render_template_list(); void render_template_list();
void render_autocomplete(const ImVec2& editor_pos); void render_autocomplete(const ImVec2 &editor_pos);
void update_autocomplete_suggestions(); void update_autocomplete_suggestions();
void save_template(); void save_template();