HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
row_column_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 "../GUI/GUI.hpp"
13#include "../geometry/module.hpp"
14#include "../layout/module.hpp"
15#include "../macros.hpp"
16#include <memory>
17#include <type_traits>
18
19namespace hi { inline namespace v1 {
20
40template<axis Axis>
42public:
43 static_assert(Axis == axis::horizontal or Axis == axis::vertical);
44
45 using super = widget;
46 constexpr static hi::axis axis = Axis;
47
49
55 {
56 hi_axiom(loop::main().on_thread());
57
58 if (parent) {
59 semantic_layer = parent->semantic_layer;
60 }
61 }
62
75 template<typename Widget, typename... Args>
77 {
78 auto tmp = std::make_unique<Widget>(this, std::forward<Args>(args)...);
79 auto& ref = *tmp;
80 _children.push_back(std::move(tmp));
81
82 ++global_counter<"row_column_widget:make_widget:constrain">;
84 return ref;
85 }
86
90 {
91 hi_axiom(loop::main().on_thread());
92 _children.clear();
93 ++global_counter<"row_column_widget:clear:constrain">;
95 }
96
98 [[nodiscard]] generator<widget_intf &> children(bool include_invisible) noexcept override
99 {
100 for (hilet& child : _children) {
101 co_yield *child.value;
102 }
103 }
104
105 [[nodiscard]] box_constraints update_constraints() noexcept override
106 {
107 _layout = {};
108
109 for (auto& child : _children) {
110 child.set_constraints(child.value->update_constraints());
111 }
112
113 return _children.constraints(os_settings::left_to_right());
114 }
115
116 void set_layout(widget_layout const& context) noexcept override
117 {
118 if (compare_store(_layout, context)) {
119 _children.set_layout(context.shape, theme().baseline_adjustment());
120
121 for (hilet& child : _children) {
122 child.value->set_layout(context.transform(child.shape, 0.0f));
123 }
124 }
125 }
126
127 void draw(draw_context const& context) noexcept override
128 {
130 for (hilet& child : _children) {
131 child.value->draw(context);
132 }
133 }
134 }
135
136 hitbox hitbox_test(point2 position) const noexcept override
137 {
138 hi_axiom(loop::main().on_thread());
139
140 if (*mode >= widget_mode::partial) {
141 auto r = hitbox{};
142 for (hilet& child : _children) {
143 r = child.value->hitbox_test_from_parent(position, r);
144 }
145 return r;
146 } else {
147 return {};
148 }
149 }
151private:
153};
154
159
164
165}} // namespace hi::v1
Defines widget.
axis
An enumeration of the 3 axis for 3D geometry.
Definition axis.hpp:19
@ window_reconstrain
Request that widget get constraint on the next frame.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm.hpp:16
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
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:28
A row/column widget lays out child widgets along a row or column.
Definition row_column_widget.hpp:41
Widget & make_widget(Args &&...args)
Add a widget directly to this grid-widget.
Definition row_column_widget.hpp:76
void clear() noexcept
Remove and deallocate all child widgets.
Definition row_column_widget.hpp:89
row_column_widget(widget *parent) noexcept
Constructs an empty row/column widget.
Definition row_column_widget.hpp:54
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
int semantic_layer
The draw layer of the widget.
Definition widget.hpp:66
widget(widget *parent) noexcept
Definition widget.hpp:87
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
T move(T... args)