HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Theme.hpp
1// Copyright 2020 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "TTauri/Foundation/required.hpp"
7#include "TTauri/Foundation/mat.hpp"
8#include "TTauri/Text/TextStyle.hpp"
9#include "TTauri/GUI/ThemeMode.hpp"
10#include <array>
11
12namespace tt {
13
14class Theme {
15private:
16 std::vector<vec> fillShades;
17 std::vector<vec> borderShades;
18 std::vector<vec> grayShades;
19
20public:
21 static constexpr OperatingSystem operatingSystem = OperatingSystem::Windows;
22
23 static inline float toolbarHeight =
24 (operatingSystem == OperatingSystem::Windows) ? 30.0f : 20.0f;
25
28 static inline float toolbarDecorationButtonWidth =
29 (operatingSystem == OperatingSystem::Windows) ? 30.0f : 20.0f;
30
33 static constexpr float margin = 6.0f;
34
35 static inline const vec margin2D = vec{margin, margin};
36
39 static constexpr float borderWidth = 1.0f;
40
43 static constexpr float roundingRadius = 5.0f;
44
47 static constexpr float smallHeight = 15.0f;
48
53 static constexpr float smallWidth = smallHeight * 2.0f;
54
57 static constexpr float height = 22.0f;
58
61 static constexpr float width = 50.0f;
62
65 static constexpr float maxLabelWidth = 300.0f;
66
69 static constexpr float iconSize = 10.0;
70
71 std::string name;
72 ThemeMode mode;
73
74 // Themed bright colors.
75 vec blue;
76 vec green;
77 vec indigo;
78 vec orange;
79 vec pink;
80 vec purple;
81 vec red;
82 vec teal;
83 vec yellow;
84
85 // Semantic colors
86 vec foregroundColor;
87 vec accentColor;
88 vec textSelectColor;
89 vec cursorColor;
90 vec incompleteGlyphColor;
91
92 TextStyle labelStyle;
93 TextStyle smallLabelStyle;
94 TextStyle warningLabelStyle;
95 TextStyle errorLabelStyle;
96 TextStyle helpLabelStyle;
97 TextStyle placeholderLabelStyle;
98 TextStyle linkLabelStyle;
99
100 Theme() noexcept = delete;
101 Theme(Theme const &) noexcept = delete;
102 Theme(Theme &&) noexcept = delete;
103 Theme &operator=(Theme const &) noexcept = delete;
104 Theme &operator=(Theme &&) noexcept = delete;
105
108 Theme(URL const &url);
109
113 [[nodiscard]] vec fillColor(ssize_t nestingLevel) const noexcept {
114 tt_assume(nestingLevel >= 0);
115 tt_assume(ssize(fillShades) > 0);
116 return fillShades[nestingLevel % ssize(fillShades)];
117 }
118
122 [[nodiscard]] vec borderColor(ssize_t nestingLevel) const noexcept {
123 tt_assume(nestingLevel >= 0);
124 tt_assume(ssize(borderShades) > 0);
125 return borderShades[nestingLevel % ssize(borderShades)];
126 }
127
128
134 [[nodiscard]] vec gray(ssize_t level) const noexcept {
135 if (level < 0) {
136 level = ssize(grayShades) + level;
137 }
138
139 level = std::clamp(level, ssize_t{0}, ssize(grayShades) - 1);
140 return grayShades[level];
141 }
142
143private:
144 [[nodiscard]] float parseFloat(datum const &data, char const *name);
145 [[nodiscard]] bool parseBool(datum const &data, char const *name);
146 [[nodiscard]] std::string parseString(datum const &data, char const *name);
147 [[nodiscard]] vec parseColorValue(datum const &data);
148 [[nodiscard]] std::vector<vec> parseColorList(datum const &data, char const *name);
149 [[nodiscard]] vec parseColor(datum const &data, char const *name);
150 [[nodiscard]] TextStyle parseTextStyleValue(datum const &data);
151 [[nodiscard]] FontWeight parseFontWeight(datum const &data, char const *name);
152 [[nodiscard]] TextStyle parseTextStyle(datum const &data, char const *name);
153 void parse(datum const &data);
154
155 [[nodiscard]] friend std::string to_string(Theme const &rhs) noexcept {
156 return fmt::format("{}:{}", rhs.name, rhs.mode);
157 }
158
159 friend std::ostream &operator<<(std::ostream &lhs, Theme const &rhs) {
160 return lhs << to_string(rhs);
161 }
162};
163
164inline Theme *theme;
165
166}
Definition URL.hpp:45
A 4D vector.
Definition vec.hpp:37
Definition Theme.hpp:14
static constexpr float iconSize
Size of icons in buttons, based on the original 1EM.
Definition Theme.hpp:69
static constexpr float smallHeight
The height of smaller widget like labels, toggles, checkboxes and radio buttons.
Definition Theme.hpp:47
static constexpr float width
The width of the larger widgets and smaller widgets with included labels.
Definition Theme.hpp:61
static constexpr float maxLabelWidth
Max width of labels in widgets.
Definition Theme.hpp:65
static constexpr float roundingRadius
The rounding radius of boxes with rounded corners.
Definition Theme.hpp:43
vec fillColor(ssize_t nestingLevel) const noexcept
Get fill color of elements of widgets and child widgets.
Definition Theme.hpp:113
static constexpr float smallWidth
The width of smaller widget like labels, toggles, checkboxes and radio buttons.
Definition Theme.hpp:53
static float toolbarDecorationButtonWidth
The width of a close, minimize, maximize, system menu button.
Definition Theme.hpp:28
static constexpr float margin
Distance between widgets and between widgets and the border of the container.
Definition Theme.hpp:33
static constexpr float borderWidth
The line-width of a border.
Definition Theme.hpp:39
vec gray(ssize_t level) const noexcept
Get grey scale color This color is reversed between light and dark themes.
Definition Theme.hpp:134
static constexpr float height
The height of the larger widgets like buttons, text-input and drop-down-lists.
Definition Theme.hpp:57
vec borderColor(ssize_t nestingLevel) const noexcept
Get border color of elements of widgets and child widgets.
Definition Theme.hpp:122
Definition TextStyle.hpp:15