HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
tab_widget.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2021-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 "grid_widget.hpp"
13#include "tab_delegate.hpp"
14
15namespace hi { inline namespace v1 {
16
36class tab_widget final : public widget {
37public:
38 using super = widget;
39 using delegate_type = tab_delegate;
40
42
44
51
58 tab_widget(widget *parent, different_from<std::shared_ptr<delegate_type>> auto&& value) noexcept
59 requires requires { make_default_tab_delegate(hi_forward(value)); }
61 {
62 }
63
72 template<typename WidgetType, typename Key, typename... Args>
73 WidgetType& make_widget(Key const& key, Args&&...args)
74 {
75 hi_axiom(loop::main().on_thread());
76
77 auto tmp = std::make_unique<WidgetType>(this, std::forward<Args>(args)...);
78 auto& ref = *tmp;
79
80 hi_assert_not_null(delegate);
81 delegate->add_tab(*this, static_cast<std::size_t>(key), size(_children));
82 _children.push_back(std::move(tmp));
83 ++global_counter<"tab_widget:make_widget:constrain">;
85 return ref;
86 }
87
89 [[nodiscard]] generator<widget const &> children(bool include_invisible) const noexcept override
90 {
91 for (hilet& child : _children) {
92 co_yield *child;
93 }
94 }
95
96 [[nodiscard]] box_constraints update_constraints() noexcept override;
97 void set_layout(widget_layout const& context) noexcept override;
98 void draw(draw_context const& context) noexcept override;
99 [[nodiscard]] hitbox hitbox_test(point2i position) const noexcept override;
100 [[nodiscard]] widget_id find_next_widget(
101 widget_id current_widget,
102 keyboard_focus_group group,
103 keyboard_focus_direction direction) const noexcept override;
105private:
106 widget const *_previous_selected_child = nullptr;
107 std::vector<std::unique_ptr<widget>> _children;
108 notifier<>::callback_token _delegate_cbt;
109
110 using const_iterator = decltype(_children)::const_iterator;
111
112 [[nodiscard]] const_iterator find_selected_child() const noexcept;
113 [[nodiscard]] widget& selected_child() const noexcept;
114};
115
116}} // namespace hi::v1
Defines widget.
Defines grid_widget.
Defines delegate_delegate and some default tab delegates.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:223
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
@ window_reconstrain
Request that widget get constraint on the next frame.
std::shared_ptr< tab_delegate > make_default_tab_delegate(auto &&value) noexcept
Create a shared pointer to a default tab delegate.
Definition tab_delegate.hpp:102
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A delegate that controls the state of a tab_widget.
Definition tab_delegate.hpp:21
A graphical element that shows only one of a predefined set of mutually exclusive child widgets.
Definition tab_widget.hpp:36
tab_widget(widget *parent, different_from< std::shared_ptr< delegate_type > > auto &&value) noexcept
Construct a tab widget with an observer value.
Definition tab_widget.hpp:58
WidgetType & make_widget(Key const &key, Args &&...args)
Make and add a child widget.
Definition tab_widget.hpp:73
tab_widget(widget *parent, std::shared_ptr< delegate_type > delegate) noexcept
Construct a tab widget with a delegate.
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
T move(T... args)