14#include "../macros.hpp"
17hi_export_module(hikogui.widgets.tab_widget);
19hi_export
namespace hi {
inline namespace v1 {
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>
92 template<
typename WidgetType,
typename Key,
typename... Args>
93 WidgetType&
emplace(Key
const& key, Args&&...args)
95 hi_axiom(loop::main().on_thread());
100 hi_assert_not_null(delegate);
101 delegate->add_tab(*
this,
static_cast<std::size_t>(key), size(_children));
103 ++global_counter<
"tab_widget:emplace:constrain">;
109 [[nodiscard]] generator<widget_intf &> children(
bool include_invisible)
noexcept override
111 for (
auto const& child : _children) {
120 auto& selected_child_ = selected_child();
122 if (_previous_selected_child != &selected_child_) {
123 _previous_selected_child = &selected_child_;
124 hi_log_info(
"tab_widget::update_constraints() selected tab changed");
128 for (
auto const& child : _children) {
132 return selected_child_.update_constraints();
135 void set_layout(widget_layout
const& context)
noexcept override
139 for (
auto const& child : _children) {
141 child->set_layout(context);
146 void draw(draw_context
const& context)
noexcept override
149 for (
auto const& child : _children) {
150 child->draw(context);
155 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
157 hi_axiom(loop::main().on_thread());
161 for (
auto const& child : _children) {
162 r = child->hitbox_test_from_parent(position, r);
170 [[nodiscard]] widget_id find_next_widget(
171 widget_id current_widget,
172 keyboard_focus_group group,
173 keyboard_focus_direction direction)
const noexcept override
175 hi_axiom(loop::main().on_thread());
176 return selected_child().find_next_widget(current_widget, group, direction);
180 widget const *_previous_selected_child =
nullptr;
181 std::vector<std::unique_ptr<widget>> _children;
182 callback<void()> _delegate_cbt;
184 using const_iterator =
decltype(_children)::const_iterator;
186 [[nodiscard]] const_iterator find_selected_child() const noexcept
188 hi_axiom(loop::main().on_thread());
189 hi_assert_not_null(delegate);
191 auto index = delegate->index(
const_cast<tab_widget&
>(*
this));
192 if (index >= 0 and index < ssize(_children)) {
193 return _children.begin() + index;
196 return _children.end();
198 [[nodiscard]]
widget& selected_child() const noexcept
200 hi_axiom(loop::main().on_thread());
201 hi_assert(not _children.empty());
203 auto i = find_selected_child();
204 if (i != _children.cend()) {
207 return *_children.front();
Defines delegate_delegate and some default tab delegates.
@ window_reconstrain
Request that widget get constraint on the next frame.
Definition gui_event_type.hpp:48
@ window_resize
Request that the window resizes to desired constraints on the next frame.
Definition gui_event_type.hpp:49
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
@ partial
A widget is partially enabled.
Definition widget_state.hpp:72
@ invisible
The widget is invisible.
Definition widget_state.hpp:40
@ enabled
The widget is fully enabled.
Definition widget_state.hpp:80
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
The HikoGUI API version 1.
Definition recursive_iterator.hpp:16
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
Definition not_null.hpp:22
A delegate that controls the state of a tab_widget.
Definition tab_delegate.hpp:29
A graphical element that shows only one of a predefined set of mutually exclusive child widgets.
Definition tab_widget.hpp:40
tab_widget(not_null< widget_intf const * > parent, Value &&value) noexcept
Construct a tab widget with an observer value.
Definition tab_widget.hpp:78
tab_widget(not_null< widget_intf const * > parent, std::shared_ptr< delegate_type > delegate) noexcept
Construct a tab widget with a delegate.
Definition tab_widget.hpp:58
WidgetType & emplace(Key const &key, Args &&...args)
Make and add a child widget.
Definition tab_widget.hpp:93
box_constraints update_constraints() noexcept override
Update the constraints of the widget.
Definition widget.hpp:109
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