HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
label_widget.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2020-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 "text_widget.hpp"
13#include "icon_widget.hpp"
15#include "../layout/grid_layout.hpp"
16#include "../label.hpp"
17#include <memory>
18#include <string>
19#include <array>
20#include <optional>
21#include <future>
22
23namespace hi { inline namespace v1 {
24
25template<typename Context>
27 forward_of<Context, observer<hi::label>, observer<hi::alignment>, observer<hi::semantic_text_style>>;
28
42class label_widget final : public widget {
43public:
44 using super = widget;
45
48 observer<label> label;
49
67 observer<alignment> alignment = hi::alignment::top_flush();
68
71 observer<semantic_text_style> text_style = semantic_text_style::label;
72
81 {
82 set_attributes(hi_forward(attributes)...);
83 }
84
86 [[nodiscard]] generator<widget *> children() const noexcept override
87 {
88 co_yield _icon_widget.get();
89 co_yield _text_widget.get();
90 }
91
92 [[nodiscard]] box_constraints update_constraints() noexcept override;
93 void set_layout(widget_layout const& context) noexcept override;
94 void draw(draw_context const& context) noexcept;
95 [[nodiscard]] hitbox hitbox_test(point2i position) const noexcept;
97private:
98 float _icon_size;
99 float _inner_margin;
100
101 decltype(label)::callback_token _label_cbt;
102 decltype(text_style)::callback_token _text_style_cbt;
103 decltype(alignment)::callback_token _alignment_cbt;
104
105 std::shared_ptr<icon_widget> _icon_widget;
106 std::shared_ptr<text_widget> _text_widget;
107 grid_layout<widget *> _grid;
108
109 void set_attributes() noexcept {}
110 void set_attributes(label_widget_attribute auto&& first, label_widget_attribute auto&&...rest) noexcept
111 {
112 if constexpr (forward_of<decltype(first), observer<hi::label>>) {
113 label = hi_forward(first);
114 } else if constexpr (forward_of<decltype(first), observer<hi::alignment>>) {
115 alignment = hi_forward(first);
116 } else if constexpr (forward_of<decltype(first), observer<hi::semantic_text_style>>) {
117 text_style = hi_forward(first);
118 } else {
120 }
121
122 set_attributes(hi_forward(rest)...);
123 }
124
125 label_widget(widget *parent) noexcept;
126};
127
128}} // namespace hi::v1
#define hi_static_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:181
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
Functionality for labels, text and icons.
types and utilities for alignment.
Defines widget.
Defines icon_widget.
Defines text_widget.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
geometry/margins.hpp
Definition assert.hpp:18
2D constraints.
Definition box_constraints.hpp:25
Grid layout algorithm.
Definition grid_layout.hpp:932
An simple GUI widget that displays an icon.
Definition icon_widget.hpp:32
The GUI widget displays and lays out text together with an icon.
Definition label_widget.hpp:42
observer< label > label
The label to display.
Definition label_widget.hpp:48
observer< alignment > alignment
How the label and icon are aligned.
Definition label_widget.hpp:67
observer< semantic_text_style > text_style
The text style to display the label's text in and color of the label's (non-color) icon.
Definition label_widget.hpp:71
label_widget(widget *parent, label_widget_attribute auto &&...attributes) noexcept
Construct a label widget.
Definition label_widget.hpp:80
A text widget.
Definition text_widget.hpp:61
An interactive graphical object as part of the user-interface.
Definition widget.hpp:46
widget(widget *parent) noexcept
widget * parent
Pointer to the parent widget.
Definition widget.hpp:51
The layout of a widget.
Definition widget_layout.hpp:41
Definition label_widget.hpp:26