12#include "../GFX/GFX.hpp"
13#include "../geometry/geometry.hpp"
14#include "../l10n/l10n.hpp"
15#include "../macros.hpp"
22hi_export_module(hikogui.widgets.icon_widget);
24hi_export
namespace hi {
inline namespace v1 {
26template<
typename Context>
55 set_attributes(std::forward<Attributes>(attributes)...);
60 template<icon_widget_attribute
First, icon_widget_attribute...
Rest>
64 icon = std::forward<First>(first);
68 color = std::forward<First>(first);
70 hi_static_no_default();
72 set_attributes(std::forward<Rest>(
rest)...);
80 if (_icon_has_modified.
exchange(
false)) {
81 _icon_type = icon_type::no;
87 _icon_type = icon_type::pixmap;
90 if (
not(_pixmap_backing = gfx_pipeline_image::paged_image{surface(), *pixmap})) {
92 _icon_has_modified =
true;
93 ++global_counter<
"icon_widget:no-backing-image:constrain">;
97 }
else if (
auto const g1 = std::get_if<font_book::font_glyph_type>(&
icon)) {
99 _icon_type = icon_type::glyph;
101 _glyph.get_metrics().bounding_rectangle.size() * theme().text_style(semantic_text_style::label)->size * theme().scale;
103 }
else if (
auto const g2 = std::get_if<elusive_icon>(&
icon)) {
105 _icon_type = icon_type::glyph;
107 _glyph.get_metrics().bounding_rectangle.size() * theme().text_style(semantic_text_style::label)->size * theme().scale;
109 }
else if (
auto const g3 = std::get_if<hikogui_icon>(&
icon)) {
111 _icon_type = icon_type::glyph;
113 _glyph.get_metrics().bounding_rectangle.size() * theme().text_style(semantic_text_style::label)->size * theme().scale;
117 auto const resolved_alignment = resolve(*
alignment, os_settings::left_to_right());
123 theme().margin<
float>()};
126 void set_layout(widget_layout
const&
context)
noexcept override
129 if (_icon_type == icon_type::no
or not _icon_size) {
130 _icon_rectangle = {};
137 auto const resolved_alignment = resolve(*
alignment, os_settings::left_to_right());
142 void draw(draw_context
const&
context)
noexcept override
145 switch (_icon_type) {
149 case icon_type::pixmap:
156 case icon_type::glyph:
169 enum class icon_type { no, glyph, pixmap };
171 icon_type _icon_type;
172 font_book::font_glyph_type _glyph;
173 gfx_pipeline_image::paged_image _pixmap_backing;
177 aarectangle _icon_rectangle;
179 callback<
void(hi::icon)> _icon_cbt;
184 _icon_has_modified =
true;
185 ++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_misc.hpp:20
hi_export hi_inline auto find_glyph(font const &font, grapheme grapheme) noexcept
Find a glyph using the given code-point.
Definition font_book.hpp:440
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:53
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
This is a RGBA floating point color.
Definition color_intf.hpp:49
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244
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:51
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:206
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
A 2D pixel-based image.
Definition pixmap.hpp:38
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32
callback< void(value_type)> subscribe(Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback to this observer.
Definition observer_intf.hpp:456
Definition not_null.hpp:22
An simple GUI widget that displays an icon.
Definition icon_widget.hpp:35
observer< icon > icon
The icon to be displayed.
Definition icon_widget.hpp:41
observer< alignment > alignment
Alignment of the icon inside the widget.
Definition icon_widget.hpp:49
observer< color > color
The color a non-color icon will be displayed with.
Definition icon_widget.hpp:45
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
observer< extent2 > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:41
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:135
widget(widget_intf const *parent) noexcept
Definition widget.hpp:49
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:124
observer< extent2 > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:45
True if T is a forwarded type of Forward.
Definition concepts.hpp:136
Definition icon_widget.hpp:27