7#include "abstract_container_widget.hpp"
8#include "grid_layout_widget.hpp"
20 template<
typename Value>
26 ttlet lock = std::scoped_lock(gui_system_mutex);
32 _value_callback = value.subscribe([
this](
auto...) {
33 this->_request_reconstrain =
true;
44 if (has_updated_contraints) {
45 ttlet &child = selected_child();
46 tt_axiom(&child.parent() ==
this);
47 if (compare_then_assign(_preferred_size, child.preferred_size())) {
53 return has_updated_contraints;
60 auto &child = selected_child();
61 tt_axiom(&child.parent() ==
this);
63 need_layout |= std::exchange(_request_relayout,
false);
65 child.set_layout_parameters_from_parent(
rectangle());
67 child.update_layout(display_time_point, need_layout);
77 draw_child(context, display_time_point, selected_child());
84 ttlet &child = selected_child();
85 return child.hitbox_test(
point2{child.parent_to_local() * position});
90 keyboard_focus_group group,
91 keyboard_focus_direction direction)
const noexcept
93 ttlet lock = std::scoped_lock(gui_system_mutex);
100 ttlet lock = std::scoped_lock(gui_system_mutex);
102 auto widget = super::make_widget<WidgetType>(std::forward<Args>(args)...);
108 typename decltype(value)::callback_ptr_type _value_callback;
112 [[nodiscard]]
auto find_child(value_type index)
const noexcept
115 tt_axiom(std::size(_children_keys) == std::size(_children));
118 if (child_key_it != _children_keys.
cend()) {
120 return _children.begin() + child_index;
122 return _children.cend();
126 [[nodiscard]]
auto find_child(value_type index)
noexcept
129 tt_axiom(std::size(_children_keys) == std::size(_children));
132 if (child_key_it != _children_keys.
cend()) {
134 return _children.cbegin() + child_index;
136 return _children.cend();
140 [[nodiscard]]
auto find_selected_child() const noexcept
143 return find_child(*value);
146 [[nodiscard]]
auto find_selected_child() noexcept
149 return find_child(*value);
152 [[nodiscard]]
widget const &selected_child() const noexcept
155 tt_axiom(std::ssize(_children) != 0);
157 auto i = find_selected_child();
158 if (i != _children.cend()) {
161 return *_children.front();
165 [[nodiscard]]
widget &selected_child() noexcept
168 tt_axiom(std::ssize(_children) != 0);
170 auto i = find_selected_child();
171 if (i != _children.cend()) {
174 return *_children.front();
178 void draw_child(draw_context context, hires_utc_clock::time_point displayTimePoint,
widget &child)
noexcept
182 context.make_child_context(child.parent_to_local(), child.local_to_window(), child.clipping_rectangle());
183 child.draw(child_context, displayTimePoint);
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:33
Definition gui_window.hpp:37
std::atomic< bool > requestResize
When set to true the window will resize to the size of the contained widget.
Definition gui_window.hpp:58
Definition hit_box.hpp:15
Definition observable.hpp:20
int recurse_lock_count() const noexcept
This function should be used in tt_axiom() to check if the lock is held by current thread.
Definition unfair_recursive_mutex.hpp:60
Definition abstract_container_widget.hpp:11
bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept
Update the constraints of the widget.
Definition abstract_container_widget.hpp:95
Definition grid_layout_widget.hpp:16
Definition tab_view_widget.hpp:13
std::shared_ptr< widget > find_next_widget(std::shared_ptr< widget > const ¤t_widget, keyboard_focus_group group, keyboard_focus_direction direction) const noexcept
Find the next widget that handles keyboard focus.
Definition tab_view_widget.hpp:88
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override
Draw the widget.
Definition tab_view_widget.hpp:73
bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept override
Update the constraints of the widget.
Definition tab_view_widget.hpp:39
hit_box hitbox_test(point2 position) const noexcept override
Find the widget that is under the mouse cursor.
Definition tab_view_widget.hpp:81
void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept override
Update the internal layout of the widget.
Definition tab_view_widget.hpp:56
float draw_layer() const noexcept
The first drawing layer of the widget.
Definition widget.hpp:149
virtual void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept
Update the internal layout of the widget.
widget(gui_window &window, std::shared_ptr< abstract_container_widget > parent) noexcept
virtual std::shared_ptr< widget > find_next_widget(std::shared_ptr< widget > const ¤t_keyboard_widget, keyboard_focus_group group, keyboard_focus_direction direction) const noexcept
Find the next widget that handles keyboard focus.
aarectangle rectangle() const noexcept
Get the rectangle in local coordinates.
Definition widget.hpp:342
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:101
abstract_container_widget const & parent() const noexcept
Get a reference to the parent.
int semantic_layer() const noexcept
The semantic layer of the widget.
Definition widget.hpp:189