HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
icon_widget.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2021-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
9#pragma once
10
11#include "widget.hpp"
12#include "../GFX/paged_image.hpp"
13#include "../alignment.hpp"
14#include "../label.hpp"
15#include <memory>
16#include <string>
17#include <array>
18#include <optional>
19#include <future>
20
21namespace hi { inline namespace v1 {
22
23template<typename Context>
24concept icon_widget_attribute = forward_of<Context, observer<hi::icon>, observer<hi::alignment>, observer<hi::color>>;
25
32class icon_widget final : public widget {
33public:
34 using super = widget;
35
38 observer<icon> icon = hi::icon{};
39
42 observer<color> color = color::foreground();
43
46 observer<alignment> alignment = hi::alignment::middle_center();
47
48 icon_widget(widget *parent, icon_widget_attribute auto&&...attributes) noexcept :
50 {
51 set_attributes(hi_forward(attributes)...);
52 }
53
54 void set_attributes() noexcept {}
55 void set_attributes(icon_widget_attribute auto&& first, icon_widget_attribute auto&&...rest) noexcept
56 {
57 if constexpr (forward_of<decltype(first), observer<hi::icon>>) {
58 icon = hi_forward(first);
59 } else if constexpr (forward_of<decltype(first), observer<hi::alignment>>) {
60 alignment = hi_forward(first);
61 } else if constexpr (forward_of<decltype(first), observer<hi::color>>) {
62 color = hi_forward(first);
63 } else {
65 }
66 set_attributes(hi_forward(rest)...);
67 }
68
70 widget_constraints const& set_constraints(set_constraints_context const& context) noexcept override;
71 void set_layout(widget_layout const& context) noexcept override;
72 void draw(draw_context const& context) noexcept override;
74private:
75 enum class icon_type { no, glyph, pixmap };
76
77 icon_type _icon_type;
78 glyph_ids _glyph;
79 paged_image _pixmap_backing;
80 decltype(icon)::callback_token _icon_cbt;
81 std::atomic<bool> _icon_has_modified = true;
82
83 extent2 _icon_size;
84 aarectangle _icon_rectangle;
85
86 icon_widget(widget *parent) noexcept;
87};
88
89}} // namespace hi::v1
#define hi_static_no_default()
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:172
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
Functionality for labels, text and icons.
Defines widget.
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
An simple GUI widget that displays an icon.
Definition icon_widget.hpp:32
observer< icon > icon
The icon to be displayed.
Definition icon_widget.hpp:38
observer< alignment > alignment
Alignment of the icon inside the widget.
Definition icon_widget.hpp:46
observer< color > color
The color a non-color icon will be displayed with.
Definition icon_widget.hpp:42
An interactive graphical object as part of the user-interface.
Definition widget.hpp:45
widget(widget *parent) noexcept
widget * parent
Pointer to the parent widget.
Definition widget.hpp:50
Definition icon_widget.hpp:24