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 "theme_mode.hpp"
8#include "../text/semantic_text_style.hpp"
9#include "../text/text_style.hpp"
10#include "../utility/module.hpp"
11#include "../datum.hpp"
12#include "../color/module.hpp"
13#include "../geometry/module.hpp"
14#include <array>
15#include <filesystem>
16#include <string>
17#include <vector>
18
19namespace hi::inline v1 {
20class font_book;
21
22class theme {
23public:
24 operating_system operating_system = operating_system::windows;
25
28 float dpi = 72;
29
32 float scale = 1.0f;
33
34 std::string name;
35 theme_mode mode = theme_mode::light;
36
37 theme() noexcept = default;
38 theme(theme const&) noexcept = default;
39 theme(theme&&) noexcept = default;
40 theme& operator=(theme const&) noexcept = default;
41 theme& operator=(theme&&) noexcept = default;
42
45 theme(hi::font_book const& font_book, std::filesystem::path const& url);
46
49 template<typename T = hi::marginsi>
50 [[nodiscard]] constexpr T margin() const noexcept
51 {
52 if constexpr (std::is_same_v<T, hi::marginsi>) {
53 return hi::marginsi{_margin};
54 } else {
55 return narrow_cast<T>(_margin);
56 }
57 }
58
61 template<arithmetic T = int>
62 [[nodiscard]] constexpr T border_width() const noexcept
63 {
64 return narrow_cast<T>(_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{narrow_cast<float>(_rounding_radius)};
74 } else {
75 return narrow_cast<T>(_rounding_radius);
76 }
77 }
78
81 template<arithmetic T = int>
82 [[nodiscard]] constexpr T size() const noexcept
83 {
84 return narrow_cast<T>(_size);
85 }
86
89 template<arithmetic T = int>
90 [[nodiscard]] constexpr T large_size() const noexcept
91 {
92 return narrow_cast<T>(_large_size);
93 }
94
97 template<arithmetic T = int>
98 [[nodiscard]] constexpr T icon_size() const noexcept
99 {
100 return narrow_cast<T>(_icon_size);
101 }
102
105 template<arithmetic T = int>
106 [[nodiscard]] constexpr T large_icon_size() const noexcept
107 {
108 return narrow_cast<T>(_large_icon_size);
109 }
110
113 template<arithmetic T = int>
114 [[nodiscard]] constexpr T label_icon_size() const noexcept
115 {
116 return narrow_cast<T>(_label_icon_size);
117 }
118
121 template<arithmetic T = int>
122 [[nodiscard]] constexpr T baseline_adjustment() const noexcept
123 {
124 return narrow_cast<T>(_baseline_adjustment);
125 }
126
137 [[nodiscard]] theme transform(float dpi) const noexcept;
138
139 [[nodiscard]] hi::color color(hi::semantic_color original_color, ssize_t nesting_level = 0) const noexcept;
140 [[nodiscard]] hi::color color(hi::color original_color, ssize_t nesting_level = 0) const noexcept;
141 [[nodiscard]] hi::text_style text_style(semantic_text_style theme_color) const noexcept;
142 [[nodiscard]] hi::text_style text_style(hi::text_style original_style) const noexcept;
143
144private:
147 int _margin = 5;
148
151 int _border_width = 1;
152
155 int _rounding_radius = 4;
156
159 int _size = 11;
160
163 int _large_size = 19;
164
167 int _icon_size = 8;
168
171 int _large_icon_size = 23;
172
175 int _label_icon_size = 15;
176
179 int _baseline_adjustment = 9;
180
181 std::array<std::vector<hi::color>, semantic_color_metadata.size()> _colors;
182 std::array<hi::text_style, semantic_text_style_metadata.size()> _text_styles;
183
184 [[nodiscard]] float parse_float(datum const& data, char const *object_name);
185 [[nodiscard]] long long parse_long_long(datum const& data, char const *object_name);
186 [[nodiscard]] int parse_int(datum const& data, char const *object_name);
187 [[nodiscard]] bool parse_bool(datum const& data, char const *object_name);
188 [[nodiscard]] std::string parse_string(datum const& data, char const *object_name);
189 [[nodiscard]] hi::color parse_color_value(datum const& data);
190 [[nodiscard]] hi::color parse_color(datum const& data, char const *object_name);
191 [[nodiscard]] std::vector<hi::color> parse_color_list(datum const& data, char const *object_name);
192 [[nodiscard]] hi::text_style parse_text_style_value(hi::font_book const& font_book, datum const& data);
193 [[nodiscard]] font_weight parse_font_weight(datum const& data, char const *object_name);
194 [[nodiscard]] hi::text_style parse_text_style(hi::font_book const& font_book, datum const& data, char const *object_name);
195 void parse(hi::font_book const& font_book, datum const& data);
196
197 [[nodiscard]] friend std::string to_string(theme const& rhs) noexcept
198 {
199 return std::format("{}:{}", rhs.name, rhs.mode);
200 }
201
202 friend std::ostream& operator<<(std::ostream& lhs, theme const& rhs)
203 {
204 return lhs << to_string(rhs);
205 }
206};
207
208} // namespace hi::inline v1
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
Definition theme.hpp:22
constexpr T rounding_radius() const noexcept
The rounding radius of boxes with rounded corners.
Definition theme.hpp:70
constexpr T label_icon_size() const noexcept
Size of icons being inline with a label's text.
Definition theme.hpp:114
constexpr T icon_size() const noexcept
Size of icons inside a widget.
Definition theme.hpp:98
theme transform(float dpi) const noexcept
Create a transformed copy of the theme.
constexpr T large_icon_size() const noexcept
Size of icons representing the length of am average word of a label's text.
Definition theme.hpp:106
constexpr T large_size() const noexcept
The size of large widgets.
Definition theme.hpp:90
constexpr T baseline_adjustment() const noexcept
The amount the base-line needs to be moved downwards when a label is aligned to top.
Definition theme.hpp:122
constexpr T size() const noexcept
The size of small square widgets.
Definition theme.hpp:82
constexpr T border_width() const noexcept
The line-width of a border.
Definition theme.hpp:62
Definition text_style.hpp:173