HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
tab_widget.hpp
1// Copyright Take Vos 2020-2021.
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
5#pragma once
6
7#include "widget.hpp"
8#include "grid_widget.hpp"
9#include "tab_delegate.hpp"
10#include "default_tab_delegate.hpp"
11
12namespace hi::inline v1 {
13
32class tab_widget final : public widget {
33public:
34 using super = widget;
36
38
45 tab_widget(gui_window &window, widget *parent, std::weak_ptr<delegate_type> delegate) noexcept;
46
54 template<typename Value>
55 tab_widget(gui_window &window, widget *parent, Value &&value) noexcept
56 requires(not std::is_convertible_v<Value, weak_or_unique_ptr<delegate_type>>) :
57 tab_widget(window, parent, make_unique_default_tab_delegate(std::forward<Value>(value)))
58 {
59 }
60
69 template<typename WidgetType, typename Key, typename... Args>
70 WidgetType &make_widget(Key const &key, Args &&...args)
71 {
72 hi_axiom(is_gui_thread());
73
74 auto tmp = std::make_unique<WidgetType>(window, this, std::forward<Args>(args)...);
75 auto &ref = *tmp;
76 if (auto delegate = _delegate.lock()) {
77 delegate->add_tab(*this, static_cast<std::size_t>(key), size(_children));
78 }
79 _children.push_back(std::move(tmp));
80 request_reconstrain();
81 return ref;
82 }
83
85 [[nodiscard]] generator<widget *> children() const noexcept override
86 {
87 for (hilet &child : _children) {
88 co_yield child.get();
89 }
90 }
91
92 widget_constraints const &set_constraints() noexcept override;
93 void set_layout(widget_layout const &layout) noexcept override;
94 void draw(draw_context const &context) noexcept override;
95 [[nodiscard]] hitbox hitbox_test(point3 position) const noexcept override;
96 [[nodiscard]] widget const *find_next_widget(
97 widget const *current_widget,
98 keyboard_focus_group group,
99 keyboard_focus_direction direction) const noexcept override;
101private:
102 widget const *_previous_selected_child = nullptr;
103 std::vector<std::unique_ptr<widget>> _children;
104 weak_or_unique_ptr<delegate_type> _delegate;
105 notifier<>::token_type _delegate_cbt;
106
107 using const_iterator = decltype(_children)::const_iterator;
108
109 tab_widget(gui_window &window, widget *parent, weak_or_unique_ptr<delegate_type> delegate) noexcept;
110 [[nodiscard]] const_iterator find_selected_child() const noexcept;
111 [[nodiscard]] widget &selected_child() const noexcept;
112};
113
114} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
STL namespace.
A return value for a generator-function.
Definition generator.hpp:27
Definition gui_window.hpp:40
Definition tab_delegate.hpp:13
A graphical element that shows only one of a predefined set of mutually exclusive child widgets.
Definition tab_widget.hpp:32
WidgetType & make_widget(Key const &key, Args &&...args)
Make and add a child widget.
Definition tab_widget.hpp:70
tab_widget(gui_window &window, widget *parent, std::weak_ptr< delegate_type > delegate) noexcept
Construct a tab widget with a delegate.
tab_widget(gui_window &window, widget *parent, Value &&value) noexcept
Construct a tab widget with an observable value.
Definition tab_widget.hpp:55
An interactive graphical object as part of the user-interface.
Definition widget.hpp:40
T move(T... args)