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 "theme_color.hpp"
9#include "theme_text_style.hpp"
10#include "../required.hpp"
11#include "../text/text_style.hpp"
12#include "../URL.hpp"
13#include "../datum.hpp"
14#include "../color/color.hpp"
15#include "../geometry/extent.hpp"
16#include "../subsystem.hpp"
17#include <array>
18
19namespace tt {
20
21class theme {
22public:
23 operating_system operating_system = operating_system::windows;
24
25 float toolbar_height = (operating_system == operating_system::windows) ? 30.0f : 20.0f;
26
29 float toolbar_decoration_button_width = (operating_system == operating_system::windows) ? 30.0f : 20.0f;
30
33 float margin = 6.0f;
34
37 float border_width = 1.0f;
38
41 float rounding_radius = 5.0f;
42
45 float size = 15.0f;
46
49 float large_size = 25.0f;
50
53 float icon_size = 10.0f;
54
57 float large_icon_size = 30.0f;
58
61 float label_icon_size = 20.0f;
62
63
64 std::string name;
65 theme_mode mode;
66
67 theme() noexcept = delete;
68 theme(theme const &) noexcept = delete;
69 theme(theme &&) noexcept = delete;
70 theme &operator=(theme const &) noexcept = delete;
71 theme &operator=(theme &&) noexcept = delete;
72
75 theme(URL const &url);
76
77 [[nodiscard]] tt::color color(theme_color theme_color, ssize_t nesting_level = 0) const noexcept;
78 [[nodiscard]] tt::text_style const &text_style(theme_text_style theme_color) const noexcept;
79
80 static void set_global(theme *theme) noexcept
81 {
82 _global.store(theme);
83 }
84
85 [[nodiscard]] static theme &global() noexcept;
86
87 [[nodiscard]] static tt::color global(theme_color color, ssize_t nesting_level = 0) noexcept
88 {
89 return global().color(color, nesting_level);
90 }
91
92 [[nodiscard]] static tt::text_style const &global(theme_text_style text_style) noexcept
93 {
94 return global().text_style(text_style);
95 }
96
97private:
98 static inline std::atomic<theme *>_global = nullptr;
99
100 std::array<std::vector<tt::color>, num_theme_colors> _colors;
102
103 [[nodiscard]] float parse_float(datum const &data, char const *object_name);
104 [[nodiscard]] bool parse_bool(datum const &data, char const *object_name);
105 [[nodiscard]] std::string parse_string(datum const &data, char const *object_name);
106 [[nodiscard]] tt::color parse_color_value(datum const &data);
107 [[nodiscard]] tt::color parse_color(datum const &data, char const *object_name);
108 [[nodiscard]] std::vector<tt::color> parse_color_list(datum const &data, char const *object_name);
109 [[nodiscard]] tt::text_style parse_text_style_value(datum const &data);
110 [[nodiscard]] font_weight parse_font_weight(datum const &data, char const *object_name);
111 [[nodiscard]] tt::text_style parse_text_style(datum const &data, char const *object_name);
112 void parse(datum const &data);
113
114 [[nodiscard]] friend std::string to_string(theme const &rhs) noexcept {
115 return std::format("{}:{}", rhs.name, rhs.mode);
116 }
117
118 friend std::ostream &operator<<(std::ostream &lhs, theme const &rhs) {
119 return lhs << to_string(rhs);
120 }
121};
122
123}
This is a RGBA floating point color.
Definition color.hpp:36
Definition theme.hpp:21
float label_icon_size
Size of icons being inline with a label's text.
Definition theme.hpp:61
float large_icon_size
Size of icons representing the length of am average word of a label's text.
Definition theme.hpp:57
float large_size
The size of large widgets.
Definition theme.hpp:49
float size
The size of small square widgets.
Definition theme.hpp:45
float border_width
The line-width of a border.
Definition theme.hpp:37
float icon_size
Size of icons inside a widget.
Definition theme.hpp:53
float toolbar_decoration_button_width
The width of a close, minimize, maximize, system menu button.
Definition theme.hpp:29
float margin
Distance between widgets and between widgets and the border of the container.
Definition theme.hpp:33
float rounding_radius
The rounding radius of boxes with rounded corners.
Definition theme.hpp:41
Definition text_style.hpp:16
Definition URL.hpp:47