mirror of
https://codeberg.org/vyn/selenite.git
synced 2025-07-01 09:13:19 +00:00
Add helpers to setup Selenite in C++ projects
This commit is contained in:
parent
e27b4c150b
commit
f3025d08cd
20 changed files with 24870 additions and 11 deletions
|
@ -29,15 +29,15 @@
|
|||
// ----
|
||||
|
||||
export global Palette {
|
||||
out property<brush> accent: Colors.cyan.darker(0.4);
|
||||
out property<brush> foreground: #abb2bf;
|
||||
out property<brush> foreground-hint: foreground.darker(0.2);
|
||||
out property<brush> background: #282c34;
|
||||
out property<brush> pane: #21252b;
|
||||
out property<brush> control-foreground: #abb2bf;
|
||||
out property<brush> control-background: #393f4a;
|
||||
out property<brush> card-background: background.brighter(0.2);
|
||||
out property<brush> green: Colors.greenyellow;
|
||||
out property<brush> orange: Colors.orange;
|
||||
out property<brush> red: Colors.red;
|
||||
in-out property<brush> accent: Colors.cyan.darker(0.4);
|
||||
in-out property<brush> foreground: #abb2bf;
|
||||
in-out property<brush> foreground-hint: foreground.darker(0.2);
|
||||
in-out property<brush> background: #282c34;
|
||||
in-out property<brush> pane: #21252b;
|
||||
in-out property<brush> control-foreground: #abb2bf;
|
||||
in-out property<brush> control-background: #393f4a;
|
||||
in-out property<brush> card-background: background.brighter(0.2);
|
||||
in-out property<brush> green: Colors.greenyellow;
|
||||
in-out property<brush> orange: Colors.orange;
|
||||
in-out property<brush> red: Colors.red;
|
||||
}
|
13
cpp/CMakeLists.txt
Normal file
13
cpp/CMakeLists.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
cmake_minimum_required(VERSION 3.21)
|
||||
project(selenite LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
|
||||
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
|
||||
|
||||
add_library(selenite
|
||||
src/palette.cpp
|
||||
)
|
||||
|
||||
target_include_directories(selenite PRIVATE "include")
|
27
cpp/include/selenite/palette.h
Normal file
27
cpp/include/selenite/palette.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace selenite
|
||||
{
|
||||
struct Color {
|
||||
int r, g, b;
|
||||
std::string hex;
|
||||
};
|
||||
|
||||
struct Palette {
|
||||
Color primary;
|
||||
Color secondary;
|
||||
Color background;
|
||||
Color background2;
|
||||
Color background3;
|
||||
Color background4;
|
||||
Color pane;
|
||||
Color foreground;
|
||||
Color foregroundHint;
|
||||
};
|
||||
|
||||
std::optional<Palette> parseJson(const std::string &path);
|
||||
|
||||
} // namespace selenite
|
2
cpp/include/selenite/selenite.h
Normal file
2
cpp/include/selenite/selenite.h
Normal file
|
@ -0,0 +1,2 @@
|
|||
#pragma once
|
||||
#include "palette.h"
|
24767
cpp/src/json.hpp
Normal file
24767
cpp/src/json.hpp
Normal file
File diff suppressed because it is too large
Load diff
50
cpp/src/palette.cpp
Normal file
50
cpp/src/palette.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "selenite/palette.h"
|
||||
#include "json.hpp"
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace selenite
|
||||
{
|
||||
Color hexStringToColor(const std::string &hexString)
|
||||
{
|
||||
int r, g, b;
|
||||
std::sscanf(hexString.c_str(), "#%02x%02x%02x", &r, &g, &b);
|
||||
return {
|
||||
.r = r,
|
||||
.g = g,
|
||||
.b = b,
|
||||
.hex = hexString,
|
||||
};
|
||||
}
|
||||
|
||||
std::optional<Palette> parseJson(const std::string &path)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
if (!file) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto json = nlohmann::json::parse(file);
|
||||
|
||||
if (!json.is_object() || !json["primary"].is_string() || !json["secondary"].is_string() ||
|
||||
!json["background"].is_string() || !json["background2"].is_string() ||
|
||||
!json["background4"].is_string() || !json["background3"].is_string() ||
|
||||
!json["pane"].is_string() || !json["foreground"].is_string() ||
|
||||
!json["foregroundHint"].is_string()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Palette palette{
|
||||
.primary = hexStringToColor(json["primary"].get<std::string>()),
|
||||
.secondary = hexStringToColor(json["secondary"].get<std::string>()),
|
||||
.background = hexStringToColor(json["background"].get<std::string>()),
|
||||
.background2 = hexStringToColor(json["background2"].get<std::string>()),
|
||||
.background3 = hexStringToColor(json["background3"].get<std::string>()),
|
||||
.background4 = hexStringToColor(json["background4"].get<std::string>()),
|
||||
.pane = hexStringToColor(json["pane"].get<std::string>()),
|
||||
.foreground = hexStringToColor(json["foreground"].get<std::string>()),
|
||||
.foregroundHint = hexStringToColor(json["foregroundHint"].get<std::string>()),
|
||||
};
|
||||
return palette;
|
||||
}
|
||||
} // namespace selenite
|
Loading…
Add table
Add a link
Reference in a new issue