HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
theme.hpp
1// Copyright Take Vos 2020-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "theme_mode.hpp"
8#include "../required.hpp"
9#include "../text/text_style.hpp"
10#include "../URL.hpp"
11#include "../numeric_array.hpp"
12#include "../datum.hpp"
13#include "../color/color.hpp"
14#include <array>
15
16namespace tt {
17
18class theme {
19public:
20 static inline theme *global;
21
22 static constexpr OperatingSystem operatingSystem = OperatingSystem::Windows;
23
24 float toolbarHeight =
25 (operatingSystem == OperatingSystem::Windows) ? 30.0f : 20.0f;
26
30 (operatingSystem == OperatingSystem::Windows) ? 30.0f : 20.0f;
31
34 float margin = 6.0f;
35
36 f32x4 margin2D = f32x4{margin, margin};
37 f32x4 margin2Dx2 = f32x4{margin * 2.0f, margin * 2.0f};
38
39 float scroll_bar_thickness = margin * 2.0f;
40
43 float borderWidth = 1.0f;
44
47 float roundingRadius = 5.0f;
48
51 float smallSize = 15.0f;
52
55 float height = 22.0f;
56
59 float width = 50.0f;
60
63 float maxLabelWidth = 300.0f;
64
67 float small_icon_size = 10.0f;
68
71 float icon_size = 20.0f;
72
75 float large_icon_size = 30.0f;
76
77
78 std::string name;
79 theme_mode mode;
80
81 // Themed bright colors.
82 color blue;
83 color green;
84 color indigo;
85 color orange;
86 color pink;
87 color purple;
88 color red;
89 color teal;
90 color yellow;
91
92 // Semantic colors
93 color foregroundColor;
94 color accentColor;
95 color textSelectColor;
96 color cursorColor;
97 color incompleteGlyphColor;
98
99 text_style labelStyle;
100 text_style smallLabelStyle;
101 text_style warningLabelStyle;
102 text_style errorLabelStyle;
103 text_style helpLabelStyle;
104 text_style placeholderLabelStyle;
105 text_style linkLabelStyle;
106
107 theme() noexcept = delete;
108 theme(theme const &) noexcept = delete;
109 theme(theme &&) noexcept = delete;
110 theme &operator=(theme const &) noexcept = delete;
111 theme &operator=(theme &&) noexcept = delete;
112
115 theme(URL const &url);
116
120 [[nodiscard]] color fillColor(ssize_t nesting_level) const noexcept
121 {
122 nesting_level = std::max(ssize_t{0}, nesting_level);
123 tt_axiom(std::ssize(fillShades) > 0);
124 return fillShades[nesting_level % std::ssize(fillShades)];
125 }
126
130 [[nodiscard]] color borderColor(ssize_t nesting_level) const noexcept
131 {
132 nesting_level = std::max(ssize_t{0}, nesting_level);
133 tt_axiom(std::ssize(borderShades) > 0);
134 return borderShades[nesting_level % std::ssize(borderShades)];
135 }
136
137
143 [[nodiscard]] color gray(ssize_t level) const noexcept
144 {
145 if (level < 0) {
146 level = std::ssize(grayShades) + level;
147 }
148
149 level = std::clamp(level, ssize_t{0}, std::ssize(grayShades) - 1);
150 return grayShades[level];
151 }
152
153private:
154 std::vector<color> fillShades;
155 std::vector<color> borderShades;
156 std::vector<color> grayShades;
157
158 [[nodiscard]] float parseFloat(datum const &data, char const *name);
159 [[nodiscard]] bool parseBool(datum const &data, char const *name);
160 [[nodiscard]] std::string parseString(datum const &data, char const *name);
161 [[nodiscard]] color parseColorValue(datum const &data);
162 [[nodiscard]] std::vector<color> parseColorList(datum const &data, char const *name);
163 [[nodiscard]] color parseColor(datum const &data, char const *name);
164 [[nodiscard]] text_style parsetext_styleValue(datum const &data);
165 [[nodiscard]] font_weight parsefont_weight(datum const &data, char const *name);
166 [[nodiscard]] text_style parsetext_style(datum const &data, char const *name);
167 void parse(datum const &data);
168
169 [[nodiscard]] friend std::string to_string(theme const &rhs) noexcept {
170 return fmt::format("{}:{}", rhs.name, rhs.mode);
171 }
172
173 friend std::ostream &operator<<(std::ostream &lhs, theme const &rhs) {
174 return lhs << to_string(rhs);
175 }
176};
177
178}
This is a RGBA floating point color.
Definition color.hpp:39
Definition theme.hpp:18
color gray(ssize_t level) const noexcept
Get grey scale color This color is reversed between light and dark themes.
Definition theme.hpp:143
color fillColor(ssize_t nesting_level) const noexcept
Get fill color of elements of widgets and child widgets.
Definition theme.hpp:120
float large_icon_size
Size of icons representing the length of am average word of a label's text.
Definition theme.hpp:75
float small_icon_size
Size of icons that represents the size of label's text.
Definition theme.hpp:67
float height
The height of the larger widgets like buttons, text-input and drop-down-lists.
Definition theme.hpp:55
float borderWidth
The line-width of a border.
Definition theme.hpp:43
float width
The width of the larger widgets and smaller widgets with included labels.
Definition theme.hpp:59
color borderColor(ssize_t nesting_level) const noexcept
Get border color of elements of widgets and child widgets.
Definition theme.hpp:130
float roundingRadius
The rounding radius of boxes with rounded corners.
Definition theme.hpp:47
float maxLabelWidth
Max width of labels in widgets.
Definition theme.hpp:63
float smallSize
The size of small square widgets.
Definition theme.hpp:51
float icon_size
Size of icons extending from the ascender to descender of a label's text.
Definition theme.hpp:71
float margin
Distance between widgets and between widgets and the border of the container.
Definition theme.hpp:34
float toolbarDecorationButtonWidth
The width of a close, minimize, maximize, system menu button.
Definition theme.hpp:29
Definition text_style.hpp:16
Definition URL.hpp:46
T max(T... args)