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