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
52
60 tab_widget(gui_window& window, widget *parent, different_from<std::shared_ptr<delegate_type>> auto&& value) noexcept requires
61 requires
62 {
65
74 template<typename WidgetType, typename Key, typename... Args>
75 WidgetType& make_widget(Key const& key, Args&&...args)
76 {
77 hi_axiom(is_gui_thread());
78
79 auto tmp = std::make_unique<WidgetType>(window, this, std::forward<Args>(args)...);
80 auto& ref = *tmp;
81
82 hi_axiom(delegate != nullptr);
83 delegate->add_tab(*this, static_cast<std::size_t>(key), size(_children));
84 _children.push_back(std::move(tmp));
85 hi_request_reconstrain("tab_widget::make_widget({})", key);
86 return ref;
87 }
88
90 [[nodiscard]] generator<widget *> children() const noexcept override
91 {
92 for (hilet& child : _children) {
93 co_yield child.get();
94 }
95 }
96
97 widget_constraints const& set_constraints() noexcept override;
98 void set_layout(widget_layout const& layout) noexcept override;
99 void draw(draw_context const& context) noexcept override;
100 [[nodiscard]] hitbox hitbox_test(point3 position) const noexcept override;
101 [[nodiscard]] widget const *find_next_widget(
102 widget const *current_widget,
103 keyboard_focus_group group,
104 keyboard_focus_direction direction) const noexcept override;
106private:
107 widget const *_previous_selected_child = nullptr;
108 std::vector<std::unique_ptr<widget>> _children;
109 notifier<>::callback_token _delegate_cbt;
110
111 using const_iterator = decltype(_children)::const_iterator;
112
113 [[nodiscard]] const_iterator find_selected_child() const noexcept;
114 [[nodiscard]] widget& selected_child() const noexcept;
115};
116
117}} // namespace hi::v1
#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
Defines widget.
Defines grid_widget.
Defines delegate_delegate and some default tab delegates.
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:15
The HikoGUI namespace.
Definition ascii.hpp:19
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(gui_window &window, widget *parent, std::shared_ptr< delegate_type > delegate) noexcept
Construct a tab widget with a delegate.
WidgetType & make_widget(Key const &key, Args &&...args)
Make and add a child widget.
Definition tab_widget.hpp:75
tab_widget(gui_window &window, widget *parent, different_from< std::shared_ptr< delegate_type > > auto &&value) noexcept
Construct a tab widget with an observer value.
Definition tab_widget.hpp:60
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
T move(T... args)