49 hi_assert_not_null(delegate);
50 delegate->deinit(*
this);
60 hi_axiom(loop::main().on_thread());
62 hi_assert_not_null(this->delegate);
63 _delegate_cbt = this->delegate->subscribe([&] {
64 ++global_counter<
"tab_widget:delegate:constrain">;
68 this->delegate->init(*
this);
77 template<incompatible_with<std::shared_ptr<delegate_type>> Value>
86 hi_assert_not_null(delegate);
88 child->set_parent(
this);
89 delegate->add_tab(*
this, index, _children.size());
92 ++global_counter<
"tab_widget:emplace:constrain">;
104 template<
typename WidgetType,
typename Key,
typename... Args>
105 WidgetType&
emplace(Key
const& key, Args&&...args)
107 hi_axiom(loop::main().on_thread());
111 add(
static_cast<size_t>(key),
std::move(tmp));
116 [[nodiscard]] generator<widget_intf &> children(
bool include_invisible)
noexcept override
118 for (
auto const& child : _children) {
127 auto& selected_child_ = selected_child();
129 if (_previous_selected_child != &selected_child_) {
130 _previous_selected_child = &selected_child_;
131 hi_log_info(
"tab_widget::update_constraints() selected tab changed");
135 for (
auto const& child : _children) {
139 return selected_child_.update_constraints();
142 void set_layout(widget_layout
const& context)
noexcept override
146 for (
auto const& child : _children) {
148 child->set_layout(context);
153 void draw(draw_context
const& context)
noexcept override
156 for (
auto const& child : _children) {
157 child->draw(context);
162 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
164 hi_axiom(loop::main().on_thread());
168 for (
auto const& child : _children) {
169 r = child->hitbox_test_from_parent(position, r);
177 [[nodiscard]] widget_id find_next_widget(
178 widget_id current_widget,
179 keyboard_focus_group group,
180 keyboard_focus_direction direction)
const noexcept override
182 hi_axiom(loop::main().on_thread());
183 return selected_child().find_next_widget(current_widget, group, direction);
187 widget const *_previous_selected_child =
nullptr;
188 std::vector<std::unique_ptr<widget>> _children;
189 callback<void()> _delegate_cbt;
191 using const_iterator =
decltype(_children)::const_iterator;
193 [[nodiscard]] const_iterator find_selected_child() const noexcept
195 hi_axiom(loop::main().on_thread());
196 hi_assert_not_null(delegate);
198 auto index = delegate->index(
const_cast<tab_widget&
>(*
this));
199 if (index >= 0 and index < ssize(_children)) {
200 return _children.begin() + index;
203 return _children.end();
205 [[nodiscard]]
widget& selected_child() const noexcept
207 hi_axiom(loop::main().on_thread());
208 hi_assert(not _children.empty());
210 auto i = find_selected_child();
211 if (i != _children.cend()) {
214 return *_children.front();
std::shared_ptr< tab_delegate > make_default_tab_delegate(Value &&value) noexcept
Create a shared pointer to a default tab delegate.
Definition tab_delegate.hpp:108
WidgetType & emplace(Key const &key, Args &&...args)
Make and add a child widget.
Definition tab_widget.hpp:105