25#include <initializer_list>
29#include <unordered_map>
48 ThemeValues(std::initializer_list<std::pair<std::string, NVGcolor>> list);
51 void addColor(
const std::string&, NVGcolor color);
58 void setOverlay(
const std::unordered_map<std::string, NVGcolor>& overlay);
61 const std::unordered_map<std::string, NVGcolor>&
getColors()
const {
return this->values; }
62 const std::unordered_map<std::string, NVGcolor>&
getBaseColors()
const {
return this->base; }
65 std::unordered_map<std::string, NVGcolor> base;
66 std::unordered_map<std::string, NVGcolor> overlay;
67 std::unordered_map<std::string, NVGcolor> values;
93 bool hasImage()
const {
return !this->image.empty(); }
113 std::map<std::string, ThemeIcon>
icons;
114 std::map<std::string, std::string>
images;
116 bool empty()
const {
return this->logo.empty() && this->preview.empty() && this->icons.empty() && this->images.empty(); }
149 bool hasImage()
const {
return !this->image.empty(); }
279 bool ok()
const {
return this->errors.empty(); }
415 static bool resolveAsset(
const std::string& name,
const std::string& directory,
const std::string& root,
416 std::string* path, std::string* error);
426 static bool recheckAsset(
const std::string& path, std::string* error =
nullptr);
449 static void addImageSlot(
const std::string& key,
const std::string& fallback =
"",
int maxSide = 0);
465 static std::shared_ptr<ThemeImage>
image(
const std::string& key);
472 static std::shared_ptr<ThemeImage>
logo();
479 static std::shared_ptr<ThemeImage>
icon(
const std::string& name,
bool* tint =
nullptr);
507 static std::vector<ThemeInfo>
listThemes(
const std::string& directory,
bool decodePictures =
false);
530 static void addContrastCheck(
const std::string& ink,
const std::string& surface,
float minimum = 4.5f);
void setOverlay(const std::unordered_map< std::string, NVGcolor > &overlay)
The theme file's colours, over the base (empty: the base alone).
const std::unordered_map< std::string, NVGcolor > & getColors() const
Every colour as drawn now, and the base alone.
Definition theme.hpp:61
void addColor(const std::string &, NVGcolor color)
A colour of the base: what the variant is without a theme file.
NVGcolor getColor(const std::string &)
A colour as drawn now; an unknown key is fatal (check with hasColor()).
bool hasColor(const std::string &) const
Whether the key exists.
const std::unordered_map< std::string, NVGcolor > & getBaseColors() const
Definition theme.hpp:62
ThemeValues(std::initializer_list< std::pair< std::string, NVGcolor > > list)
The base colours.
static void addSurfaceKey(const std::string &key)
ThemeValues * getValues()
The colours behind the handle.
Definition theme.hpp:312
static bool load(const std::string &text, ThemeVariant *variant=nullptr, const std::string &directory="")
static std::shared_ptr< ThemeImage > image(const std::string &key)
static void followCalendar()
static std::string seasonalTheme(std::time_t when)
static std::shared_ptr< ThemeImage > icon(const std::string &name, bool *tint=nullptr)
static std::vector< std::string > checkContrast(ThemeVariant variant)
static std::shared_ptr< ThemeImage > logo()
static Theme & getLightTheme()
The light variant's colours.
static void addIconNames(const std::vector< std::string > &names)
static std::vector< ThemeInfo > listThemes(const std::string &directory, bool decodePictures=false)
static bool loadFile(const std::string &path, ThemeVariant *variant=nullptr)
void addColor(const std::string &, NVGcolor color)
A colour of the base (see ThemeValues::addColor).
static ThemePictures getPictures(ThemeVariant variant)
static void addContrastCheck(const std::string &ink, const std::string &surface, float minimum=4.5f)
static float contrast(NVGcolor a, NVGcolor b)
static std::vector< std::string > getImageSlots()
static bool styles(ThemeVariant variant)
static Theme & get(ThemeVariant variant)
The colours of variant.
static ThemeInfo inspect(const std::string &path, bool decodePictures=false)
static void addImageSlot(const std::string &key, const std::string &fallback="", int maxSide=0)
static const std::string & getCurrentPath()
static std::string getBackgroundImage()
static std::vector< std::string > checkBackgroundContrast(ThemeVariant variant)
static bool recheckAsset(const std::string &path, std::string *error=nullptr)
NVGcolor getColor(const std::string &name)
The colour name as drawn now; an unknown key is fatal (check with hasColor()).
NVGcolor operator[](const std::string &name)
The colour name (getColor()).
static uint64_t getGeneration()
Theme(ThemeValues *values)
A handle on one variant's colours (not owned).
static ThemeDecor getDecor(ThemeVariant variant)
static ThemeBackground getBackground(ThemeVariant variant)
bool hasColor(const std::string &name)
Whether the key exists.
static Theme & getDarkTheme()
The dark variant's colours.
static bool parseColor(const std::string &text, NVGcolor *color)
static bool resolveAsset(const std::string &name, const std::string &directory, const std::string &root, std::string *path, std::string *error)
static std::vector< ThemeInfo > builtinThemes()
Definition actions.hpp:25
ThemeVariant
The two sets of colours every theme has: light and dark.
Definition theme.hpp:37
ParticleKind
The particles a theme may draw (particles in a theme file).
Definition theme.hpp:154
BackgroundFit
How a theme's background_image fills the window (background_fit)
Definition theme.hpp:72
@ CONTAIN
scaled to fit in it whole, centred, aurore/clear around it
@ COVER
scaled to cover it, centred, cut at the edges (the default)
@ TILE
repeated from the top left, one pixel per unit of the layout
constexpr int THEME_AREA_COUNT
HEADER to BOTTOM.
Definition theme.hpp:137
ThemeArea
What a decoration picture is drawn in (View::setThemeArea)
Definition theme.hpp:129
@ BOTTOM
decor.bottom: along its bottom edge
@ DIALOG
backdrop.dialog: dialogs, dropdowns, Cadran's sheets
@ TOP
decor.top: a strip along the top edge of the screen
@ SIDEBAR
backdrop.sidebar: the sidebar (Cadran's rail)
@ HEADER
backdrop.header: a screen's header, its whole width
ParticleLayer
Definition theme.hpp:169
A variant's background, as a theme file sets it (docs/themes.md)
Definition theme.hpp:81
BackgroundFit fit
Definition theme.hpp:86
float surfaceOpacity
Definition theme.hpp:91
static constexpr float DEFAULT_DIM
Definition theme.hpp:82
float dim
background_dim: how much of aurore/background veils the image (0 to 1)
Definition theme.hpp:88
bool hasImage() const
Definition theme.hpp:93
std::string image
background_image: its path (Theme::resolveAsset), "" without one
Definition theme.hpp:85
A variant's decorations: one picture per area, and particles.
Definition theme.hpp:193
const ThemePicture & picture(ThemeArea area) const
The picture of area.
Definition theme.hpp:198
bool hasPictures() const
Definition theme.hpp:199
ThemePicture pictures[THEME_AREA_COUNT]
by ThemeArea, HEADER first
Definition theme.hpp:194
ThemeParticles particles
Definition theme.hpp:195
A Cadran icon a theme draws as a picture (icon.<name>, docs/themes.md)
Definition theme.hpp:98
std::string image
Definition theme.hpp:99
bool tint
Definition theme.hpp:102
bool operator==(const ThemeIcon &) const =default
Definition theme_image.hpp:49
A few colours to show it in a picker, per variant it styles.
Definition theme.hpp:236
NVGcolor accent
Definition theme.hpp:240
NVGcolor text
Definition theme.hpp:239
NVGcolor highlight
Definition theme.hpp:241
NVGcolor background
Definition theme.hpp:237
NVGcolor surface
Definition theme.hpp:238
A theme file as listThemes() or inspect() read it, without applying it.
Definition theme.hpp:210
const ThemeBackground & background(ThemeVariant variant) const
Definition theme.hpp:249
std::string icon
Definition theme.hpp:222
std::string author
its author
Definition theme.hpp:214
bool dark
Definition theme.hpp:232
std::string name
its name, else the id
Definition theme.hpp:213
std::string path
as given to loadFile(); "builtin:<id>" for a preset
Definition theme.hpp:211
std::string backgroundImage
Definition theme.hpp:219
bool ok() const
Whether it was read without errors.
Definition theme.hpp:279
std::string counterpart
Definition theme.hpp:227
std::vector< std::string > warnings
Definition theme.hpp:276
ThemePictures darkPictures
Definition theme.hpp:256
bool light
Definition theme.hpp:231
Preview darkPreview
Definition theme.hpp:244
std::string version
its version
Definition theme.hpp:215
const ThemePictures & pictures(ThemeVariant variant) const
Definition theme.hpp:257
std::string description
Definition theme.hpp:216
Preview lightPreview
Definition theme.hpp:243
ThemeDecor darkDecor
Definition theme.hpp:264
ThemeBackground lightBackground
Each variant's background (image, fit, dim, surface opacity)
Definition theme.hpp:247
ThemePictures lightPictures
Each variant's logo, icons, preview and image slots' pictures.
Definition theme.hpp:255
std::vector< std::string > errors
"line 4: #12 is not a colour"…: lines skipped, files not found.
Definition theme.hpp:271
bool styles(ThemeVariant variant) const
Whether it styles variant.
Definition theme.hpp:283
ThemeVariant variant() const
The variant to show it in when it styles one only.
Definition theme.hpp:281
ThemeDecor lightDecor
Each variant's decorations (backdrops, strips, particles)
Definition theme.hpp:263
const ThemeDecor & decor(ThemeVariant variant) const
Definition theme.hpp:265
ThemeBackground darkBackground
Definition theme.hpp:248
std::string id
the file's name without its extension
Definition theme.hpp:212
A variant's particles, as a theme file sets them (docs/themes.md).
Definition theme.hpp:176
static constexpr int MAX_COLORS
Definition theme.hpp:178
float speed
0.25 to 4
Definition theme.hpp:182
std::vector< NVGcolor > colors
particles_color: up to MAX_COLORS; empty: from the palette
Definition theme.hpp:185
ParticleKind kind
Definition theme.hpp:180
static constexpr float LOW
Definition theme.hpp:177
bool enabled() const
Whether any particle is drawn.
Definition theme.hpp:188
float density
0 to 1, of ThemeDecorations::MAX_PARTICLES
Definition theme.hpp:181
static constexpr float HIGH
Definition theme.hpp:177
static constexpr float MEDIUM
Definition theme.hpp:177
ParticleLayer layer
Definition theme.hpp:183
A picture of the decorations, as a theme file sets it.
Definition theme.hpp:141
bool hasImage() const
Definition theme.hpp:149
float opacity
Definition theme.hpp:144
float height
Definition theme.hpp:147
std::string image
its path (Theme::resolveAsset), "" without one
Definition theme.hpp:142
BackgroundFit fit
Definition theme.hpp:143
std::string logo
logo: the app's mark, "" for the app's own
Definition theme.hpp:111
bool operator==(const ThemePictures &) const =default
bool empty() const
Definition theme.hpp:116
std::map< std::string, std::string > images
image.<key>, by image slot
Definition theme.hpp:114
std::string preview
preview: the theme's thumbnail in a picker
Definition theme.hpp:112
std::map< std::string, ThemeIcon > icons
icon.<name>, by icon name
Definition theme.hpp:113