HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
theme_value.hpp
1
2#pragma once
3
4hi_export_module(hikogui.theme.theme_variable);
5
6hi_export namespace hi { inline namespace v1 {
7
8
9
10template<typename T, fixed_string Tag>
12public:
13 using value_type = T;
14 constexpr static auto tag = Tag;
15
21 static void set(theme_selector const& needle, value_type const &value) noexcept
22 {
23 for (auto *ptr : _values) {
24 if (match(needle, ptr->_selector)) {
25 ptr->_v = value;
26 }
27 }
28 }
29
30 theme_variable(theme_variable const&) = delete;
32 theme_variable& operator=(theme_variable const&) = delete;
33 theme_variable& operator=(theme_variable&&) = delete;
34
36 {
37 auto const it = std::lower_bound(_values.begin(), _values.end(), this);
38 hi_axiom(it != _values.end());
39 _values.erase(it);
40 }
41
42 theme_variable(theme_selector const& selector) noexcept : _selector(selector)
43 {
44 auto const it = std::lower_bound(_values.begin(), _values.end(), this);
45 hi_axiom(it == _values.end() or *it != this);
46 _values.insert(it, this);
47 }
48
49 [[nodiscard]] value_type const& operator*() const noexcept
50 {
51 return _v;
52 }
53
54 template<typename... Args>
55 [[nodiscard]] decltype(auto) operator()(Args const&... args) const noexcept
56 {
57 return _v(args...);
58 }
59
60 template<typename Arg>
61 [[nodiscard]] decltype(auto) operator[](Arg const& arg) const noexcept
62 {
63 return _v[arg];
64 }
65
66private:
67 theme_selector _selector;
68 value_type _v;
69
70 inline static std::vector<theme_variable> _values;
71};
72
73
74using margin_left = theme_variable<"margin-left", theme_length>;
75using margin_right = theme_variable<"margin-right", theme_length>;
76using margin_top = theme_variable<"margin-top", theme_length>;
77using margin_bottom = theme_variable<"margin-bottom", theme_length>;
78using margin = theme_variable<"margin", theme_length_quad>;
79
80}}
81
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition theme_value.hpp:11
static void set(theme_selector const &needle, value_type const &value) noexcept
Set the value for all variables matching a selector.
Definition theme_value.hpp:21
This selector allows access to member variable by name.
Definition type_traits.hpp:691
T lower_bound(T... args)