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 tt {
13
32class tab_widget final : public widget {
33public:
34 using super = widget;
36
44
52 template<typename Value>
53 tab_widget(gui_window &window, widget *parent, Value &&value) noexcept
54 requires(not std::is_convertible_v<Value, weak_or_unique_ptr<delegate_type>>) :
55 tab_widget(window, parent, make_unique_default_tab_delegate(std::forward<Value>(value)))
56 {
57 }
58
67 template<typename WidgetType, typename Key, typename... Args>
68 WidgetType &make_widget(Key const &key, Args &&...args) noexcept
69 {
70 tt_axiom(is_gui_thread());
71
72 if (auto delegate = _delegate.lock()) {
73 delegate->add_tab(*this, static_cast<size_t>(key), std::size(_children));
74 }
75 auto &widget = super::make_widget<WidgetType>(std::forward<Args>(args)...);
76 return widget;
77 }
78
80 void init() noexcept override;
81 void deinit() noexcept override;
82 [[nodiscard]] float margin() const noexcept override;
83 [[nodiscard]] bool constrain(utc_nanoseconds display_time_point, bool need_reconstrain) noexcept override;
84 [[nodiscard]] void layout(utc_nanoseconds display_time_point, bool need_layout) noexcept override;
85 [[nodiscard]] widget const *find_next_widget(
86 widget const *current_widget,
87 keyboard_focus_group group,
88 keyboard_focus_direction direction) const noexcept override;
90private:
91 weak_or_unique_ptr<delegate_type> _delegate;
92 typename delegate_type::callback_ptr_type _delegate_callback;
93
94 tab_widget(gui_window &window, widget *parent, weak_or_unique_ptr<delegate_type> delegate) noexcept;
95 [[nodiscard]] auto find_selected_child() const noexcept;
96 [[nodiscard]] auto find_selected_child() noexcept;
97 [[nodiscard]] widget const &selected_child() const noexcept;
98 void draw_child(draw_context context, utc_nanoseconds displayTimePoint, widget &child) noexcept;
99};
100
101} // namespace tt
STL namespace.
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:28
Definition gui_window.hpp:39
Class that hold either a weak_ptr or a unique_ptr This class is to hold a weak_ptr,...
Definition weak_or_unique_ptr.hpp:25
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) noexcept
Make and add a child widget.
Definition tab_widget.hpp:68
tab_widget(gui_window &window, widget *parent, Value &&value) noexcept
Construct a tab widget with an observable value.
Definition tab_widget.hpp:53
tab_widget(gui_window &window, widget *parent, std::weak_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:37
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:46
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:41
widget(gui_window &window, widget *parent) noexcept