HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
theme.hpp
1// Copyright Take Vos 2020-2022.
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 "../settings/module.hpp"
8#include "../text/module.hpp"
9#include "../utility/module.hpp"
10#include "../color/module.hpp"
11#include "../geometry/module.hpp"
12#include "../datum.hpp"
13#include <array>
14#include <filesystem>
15#include <string>
16#include <vector>
17
18namespace hi::inline v1 {
19class font_book;
20
21class theme {
22public:
23 operating_system operating_system = operating_system::windows;
24
27 float dpi = 72;
28
31 float scale = 1.0f;
32
33 std::string name;
34 theme_mode mode = theme_mode::light;
35
36 theme() noexcept = default;
37 theme(theme const&) noexcept = default;
38 theme(theme&&) noexcept = default;
39 theme& operator=(theme const&) noexcept = default;
40 theme& operator=(theme&&) noexcept = default;
41
44 theme(hi::font_book const& font_book, std::filesystem::path const& url);
45
48 template<typename T = hi::margins>
49 [[nodiscard]] constexpr T margin() const noexcept
50 {
51 if constexpr (std::is_same_v<T, hi::margins>) {
52 return hi::margins{_margin};
53 } else if constexpr (std::is_same_v<T, float>) {
54 return _margin;
55 } else {
57 }
58 }
59
62 [[nodiscard]] constexpr float border_width() const noexcept
63 {
64 return _border_width;
65 }
66
69 template<typename T = hi::corner_radii>
70 [[nodiscard]] constexpr T rounding_radius() const noexcept
71 {
72 if constexpr (std::is_same_v<T, hi::corner_radii>) {
73 return T{_rounding_radius};
74 } else if constexpr (std::is_same_v<T, float>) {
75 return _rounding_radius;
76 } else {
78 }
79 }
80
83 [[nodiscard]] constexpr float size() const noexcept
84 {
85 return _size;
86 }
87
90 [[nodiscard]] constexpr float large_size() const noexcept
91 {
92 return _large_size;
93 }
94
97 [[nodiscard]] constexpr float icon_size() const noexcept
98 {
99 return _icon_size;
100 }
101
104 [[nodiscard]] constexpr float large_icon_size() const noexcept
105 {
106 return _large_icon_size;
107 }
108
111 [[nodiscard]] constexpr float label_icon_size() const noexcept
112 {
113 return _label_icon_size;
114 }
115
118 [[nodiscard]] constexpr float baseline_adjustment() const noexcept
119 {
120 return _baseline_adjustment;
121 }
122
133 [[nodiscard]] theme transform(float dpi) const noexcept;
134
135 [[nodiscard]] hi::color color(hi::semantic_color original_color, ssize_t nesting_level = 0) const noexcept;
136 [[nodiscard]] hi::color color(hi::color original_color, ssize_t nesting_level = 0) const noexcept;
137 [[nodiscard]] hi::text_style text_style(semantic_text_style theme_color) const noexcept;
138 [[nodiscard]] hi::text_style text_style(hi::text_style original_style) const noexcept;
139
140private:
143 float _margin = 5.0f;
144
147 float _border_width = 1.0f;
148
151 float _rounding_radius = 4.0f;
152
155 float _size = 11.0f;
156
159 float _large_size = 19.0f;
160
163 float _icon_size = 8.0f;
164
167 float _large_icon_size = 23.0f;
168
171 float _label_icon_size = 15.0f;
172
175 float _baseline_adjustment = 9.0f;
176
177 std::array<std::vector<hi::color>, semantic_color_metadata.size()> _colors;
178 std::array<hi::text_style, semantic_text_style_metadata.size()> _text_styles;
179
180 [[nodiscard]] float parse_float(datum const& data, char const *object_name);
181 [[nodiscard]] long long parse_long_long(datum const& data, char const *object_name);
182 [[nodiscard]] int parse_int(datum const& data, char const *object_name);
183 [[nodiscard]] bool parse_bool(datum const& data, char const *object_name);
184 [[nodiscard]] std::string parse_string(datum const& data, char const *object_name);
185 [[nodiscard]] hi::color parse_color_value(datum const& data);
186 [[nodiscard]] hi::color parse_color(datum const& data, char const *object_name);
187 [[nodiscard]] std::vector<hi::color> parse_color_list(datum const& data, char const *object_name);
188 [[nodiscard]] hi::text_style parse_text_style_value(hi::font_book const& font_book, datum const& data);
189 [[nodiscard]] font_weight parse_font_weight(datum const& data, char const *object_name);
190 [[nodiscard]] hi::text_style parse_text_style(hi::font_book const& font_book, datum const& data, char const *object_name);
191 void parse(hi::font_book const& font_book, datum const& data);
192
193 [[nodiscard]] friend std::string to_string(theme const& rhs) noexcept
194 {
195 return std::format("{}:{}", rhs.name, rhs.mode);
196 }
197
198 friend std::ostream& operator<<(std::ostream& lhs, theme const& rhs)
199 {
200 return lhs << to_string(rhs);
201 }
202};
203
204} // namespace hi::inline v1
#define hi_static_not_implemented(...)
This part of the code has not been implemented yet.
Definition assert.hpp:342
semantic_color
Semantic colors.
Definition semantic_color.hpp:20
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
font_weight
Definition font_weight.hpp:16
geometry/margins.hpp
Definition cache.hpp:11
This is a RGBA floating point color.
Definition color.hpp:42
A dynamic data type.
Definition datum.hpp:219
font_book keeps track of multiple fonts.
Definition font_book.hpp:31
The left, bottom, right and top margins.
Definition margins.hpp:20
Definition theme.hpp:21
constexpr float large_size() const noexcept
The size of large widgets.
Definition theme.hpp:90
constexpr float baseline_adjustment() const noexcept
The amount the base-line needs to be moved downwards when a label is aligned to top.
Definition theme.hpp:118
constexpr float label_icon_size() const noexcept
Size of icons being inline with a label's text.
Definition theme.hpp:111
constexpr T rounding_radius() const noexcept
The rounding radius of boxes with rounded corners.
Definition theme.hpp:70
constexpr float large_icon_size() const noexcept
Size of icons representing the length of am average word of a label's text.
Definition theme.hpp:104
theme transform(float dpi) const noexcept
Create a transformed copy of the theme.
constexpr float border_width() const noexcept
The line-width of a border.
Definition theme.hpp:62
constexpr float size() const noexcept
The size of small square widgets.
Definition theme.hpp:83
constexpr float icon_size() const noexcept
Size of icons inside a widget.
Definition theme.hpp:97
Definition text_style.hpp:172