HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
icon_widget.hpp
1// Copyright Take Vos 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 "widget.hpp"
8#include "../GFX/paged_image.hpp"
9#include "../GUI/theme_color.hpp"
10#include "../alignment.hpp"
11#include "../icon.hpp"
12#include <memory>
13#include <string>
14#include <array>
15#include <optional>
16#include <future>
17
18namespace hi::inline v1 {
19
25class icon_widget final : public widget {
26public:
27 using super = widget;
28
32
35 observable<theme_color> color = theme_color::foreground;
36
39 observable<alignment> alignment = hi::alignment{horizontal_alignment::center, vertical_alignment::middle};
40
41 template<typename Icon, typename Color = hi::theme_color>
42 icon_widget(gui_window &window, widget *parent, Icon &&icon, Color &&color = theme_color::foreground) noexcept :
43 icon_widget(window, parent)
44 {
45 this->icon = std::forward<Icon>(icon);
46 this->color = std::forward<Color>(color);
47 }
48
50 widget_constraints const &set_constraints() noexcept override;
51 void set_layout(widget_layout const &layout) noexcept override;
52 void draw(draw_context const &context) noexcept override;
54private:
55 enum class icon_type { no, glyph, pixmap };
56
57 icon_type _icon_type;
58 glyph_ids _glyph;
59 paged_image _pixmap_backing;
60 decltype(icon)::token_type _icon_cbt;
61 std::atomic<bool> _icon_has_modified = true;
62
63 extent2 _icon_size;
64 aarectangle _icon_rectangle;
65
66 icon_widget(gui_window &window, widget *parent) noexcept;
67};
68
69} // namespace hi::inline v1
Definition alignment.hpp:64
This is a RGBA floating point color.
Definition color.hpp:37
Definition gui_window.hpp:40
An image, in different formats.
Definition icon.hpp:19
An observable value.
Definition observable.hpp:356
An simple GUI widget that displays an icon.
Definition icon_widget.hpp:25
observable< icon > icon
The icon to be displayed.
Definition icon_widget.hpp:31
An interactive graphical object as part of the user-interface.
Definition widget.hpp:40