12#include "../GFX/GFX.hpp"
13#include "../geometry/module.hpp"
14#include "../l10n/l10n.hpp"
15#include "../macros.hpp"
22namespace hi {
inline namespace v1 {
24template<
typename Context>
56 void set_attributes(icon_widget_attribute
auto&& first, icon_widget_attribute
auto&&...
rest)
noexcept
59 icon = hi_forward(first);
63 color = hi_forward(first);
65 hi_static_no_default();
67 set_attributes(hi_forward(
rest)...);
75 if (_icon_has_modified.
exchange(
false)) {
76 _icon_type = icon_type::no;
82 _icon_type = icon_type::pixmap;
85 if (
not(_pixmap_backing = gfx_pipeline_image::paged_image{surface(), *pixmap})) {
87 _icon_has_modified =
true;
88 ++global_counter<
"icon_widget:no-backing-image:constrain">;
92 }
else if (hilet
g1 = std::get_if<font_book::font_glyph_type>(&
icon.read())) {
94 _icon_type = icon_type::glyph;
96 _glyph.get_metrics().bounding_rectangle.size() * theme().text_style(semantic_text_style::label)->size * theme().scale;
98 }
else if (hilet
g2 = std::get_if<elusive_icon>(&
icon.read())) {
100 _icon_type = icon_type::glyph;
102 _glyph.get_metrics().bounding_rectangle.size() * theme().text_style(semantic_text_style::label)->size * theme().scale;
104 }
else if (hilet
g3 = std::get_if<hikogui_icon>(&
icon.read())) {
106 _icon_type = icon_type::glyph;
108 _glyph.get_metrics().bounding_rectangle.size() * theme().text_style(semantic_text_style::label)->size * theme().scale;
112 hilet resolved_alignment = resolve(*
alignment, os_settings::left_to_right());
118 theme().margin<
float>()};
121 void set_layout(widget_layout
const&
context)
noexcept override
124 if (_icon_type == icon_type::no
or not _icon_size) {
125 _icon_rectangle = {};
132 hilet resolved_alignment = resolve(*
alignment, os_settings::left_to_right());
137 void draw(draw_context
const&
context)
noexcept override
140 switch (_icon_type) {
144 case icon_type::pixmap:
151 case icon_type::glyph:
164 enum class icon_type { no, glyph, pixmap };
166 icon_type _icon_type;
167 font_book::font_glyph_type _glyph;
168 gfx_pipeline_image::paged_image _pixmap_backing;
169 decltype(
icon)::callback_token _icon_cbt;
173 aarectangle _icon_rectangle;
177 _icon_cbt =
icon.subscribe([
this](
auto...) {
178 _icon_has_modified =
true;
179 ++global_counter<
"icon_widget:icon:constrain">;
@ window_reconstrain
Request that widget get constraint on the next frame.
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm.hpp:16
hi_export auto find_glyph(font const &font, grapheme grapheme) noexcept
Find a glyph using the given code-point.
Definition font_book.hpp:437
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:56
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
This is a RGBA floating point color.
Definition color.hpp:45
Horizontal/Vertical alignment combination.
Definition alignment.hpp:242
static constexpr scale2 uniform(extent2 src_extent, extent2 dst_extent) noexcept
Get a uniform-scale-transform to scale an extent to another extent.
Definition scale2.hpp:46
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:28
A 2D pixel-based image.
Definition pixmap.hpp:38
An simple GUI widget that displays an icon.
Definition icon_widget.hpp:33
observer< icon > icon
The icon to be displayed.
Definition icon_widget.hpp:39
observer< alignment > alignment
Alignment of the icon inside the widget.
Definition icon_widget.hpp:47
observer< color > color
The color a non-color icon will be displayed with.
Definition icon_widget.hpp:43
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget_layout const & layout() const noexcept override
Get the current layout for this widget.
Definition widget.hpp:169
observer< extent2 > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:79
widget(widget *parent) noexcept
Definition widget.hpp:87
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:189
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:178
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:42
observer< extent2 > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:83
True if T is a forwarded type of Forward.
Definition concepts.hpp:131
Definition icon_widget.hpp:25