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/draw_context.hpp"
9#include "../GFX/pipeline_image_image.hpp"
10#include "../GUI/theme_color.hpp"
11#include "../alignment.hpp"
12#include "../icon.hpp"
13#include <memory>
14#include <string>
15#include <array>
16#include <optional>
17#include <future>
18
19namespace tt {
20
26class icon_widget final : public widget {
27public:
28 using super = widget;
29
33
36 observable<theme_color> color = theme_color::foreground;
37
40 observable<alignment> alignment = alignment::middle_center;
41
42 template<typename Icon, typename Color = tt::theme_color>
45 widget *parent, Icon &&icon, Color &&color = theme_color::foreground) noexcept :
47 {
48 this->icon = std::forward<Icon>(icon);
49 this->color = std::forward<Color>(color);
50 }
51
53 void init() noexcept override;
54 [[nodiscard]] bool constrain(utc_nanoseconds display_time_point, bool need_reconstrain) noexcept override;
55 [[nodiscard]] void layout(utc_nanoseconds displayTimePoint, bool need_layout) noexcept override;
56 void draw(draw_context context, utc_nanoseconds display_time_point) noexcept override;
58private:
59 enum class icon_type { no, glyph, pixmap };
60
61 decltype(icon)::callback_ptr_type _icon_callback;
62
63 icon_type _icon_type;
64 font_glyph_ids _glyph;
65 size_t _pixmap_hash;
66 pipeline_image::image _pixmap_backing;
67
68 aarectangle _icon_bounding_box;
69 matrix2 _icon_transform;
70
71 icon_widget(gui_window &window, widget *parent) noexcept;
72};
73
74} // namespace tt
alignment
Vertical and horizontal alignment.
Definition alignment.hpp:47
This is a RGBA floating point color.
Definition color.hpp:36
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:28
Definition gui_window.hpp:39
An image, in different formats.
Definition icon.hpp:19
A value which can be observed for modifications.
Definition observable.hpp:464
An simple GUI widget that displays an icon.
Definition icon_widget.hpp:26
observable< icon > icon
The icon to be displayed.
Definition icon_widget.hpp:32
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:46
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:41
widget(gui_window &window, widget *parent) noexcept