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"
14#include "../alignment.hpp"
15#include "../label.hpp"
16#include <memory>
17#include <string>
18#include <array>
19#include <optional>
20#include <future>
21
22namespace hi { inline namespace v1 {
23
24template<typename Context>
26 forward_of<Context, observer<hi::label>, observer<hi::alignment>, observer<hi::semantic_text_style>>;
27
41class label_widget final : public widget {
42public:
43 using super = widget;
44
47 observer<label> label;
48
67 observer<alignment> alignment = hi::alignment::top_right();
68
71 observer<semantic_text_style> text_style = semantic_text_style::label;
72
81 label_widget(gui_window& window, widget *parent, label_widget_attribute auto&&...attributes) noexcept :
83 {
84 set_attributes(hi_forward(attributes)...);
85 }
86
88 [[nodiscard]] generator<widget *> children() const noexcept override
89 {
90 co_yield _icon_widget.get();
91 co_yield _text_widget.get();
92 }
93
94 widget_constraints const& set_constraints() noexcept override;
95 void set_layout(widget_layout const& layout) noexcept override;
96 void draw(draw_context const& context) noexcept;
97 [[nodiscard]] hitbox hitbox_test(point3 position) const noexcept;
99private:
100 float _icon_size;
101 float _inner_margin;
102
103 decltype(label)::callback_token _label_cbt;
104 decltype(text_style)::callback_token _text_style_cbt;
105
106 aarectangle _icon_rectangle;
107 widget_constraints _icon_constraints;
108 std::unique_ptr<icon_widget> _icon_widget;
109 aarectangle _text_rectangle;
110 widget_constraints _text_constraints;
111 std::unique_ptr<text_widget> _text_widget;
112
113 void set_attributes() noexcept {}
114 void set_attributes(label_widget_attribute auto&& first, label_widget_attribute auto&&...rest) noexcept
115 {
116 if constexpr (forward_of<decltype(first), observer<hi::label>>) {
117 label = hi_forward(first);
118 } else if constexpr (forward_of<decltype(first), observer<hi::alignment>>) {
119 alignment = hi_forward(first);
120 } else if constexpr (forward_of<decltype(first), observer<hi::semantic_text_style>>) {
121 text_style = hi_forward(first);
122 } else {
123 hi_static_no_default();
124 }
125
126 set_attributes(hi_forward(rest)...);
127 }
128
129 label_widget(gui_window& window, widget *parent) noexcept;
130};
131
132}} // namespace hi::v1
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
Functionality for labels, text and icons.
Defines widget.
Defines icon_widget.
Defines text_widget.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
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:41
observer< label > label
The label to display.
Definition label_widget.hpp:47
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(gui_window &window, widget *parent, label_widget_attribute auto &&...attributes) noexcept
Construct a label widget.
Definition label_widget.hpp:81
A text widget.
Definition text_widget.hpp:61
An interactive graphical object as part of the user-interface.
Definition widget.hpp:44
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget.hpp:198
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:53
widget(gui_window &window, widget *parent) noexcept
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:48
The constraints of a widget.
Definition widget_constraints.hpp:26
The layout of a widget.
Definition widget_layout.hpp:37
Definition label_widget.hpp:25