7#include "abstract_container_widget.hpp"
20 ttlet lock = std::scoped_lock(gui_system_mutex);
37 using enum horizontal_alignment;
38 case left: _left_children.push_back(tmp);
break;
39 case right: _right_children.push_back(tmp);
break;
40 default: tt_no_default();
52 auto shared_height = 0.0f;
55 _layout.
reserve(std::ssize(_left_children) + 1 + std::ssize(_right_children));
58 for (ttlet &child : _left_children) {
59 update_constraints_for_child(*child, index++, shared_base_line, shared_height);
69 for (ttlet &child : std::views::reverse(_right_children)) {
70 update_constraints_for_child(*child, index++, shared_base_line, shared_height);
73 tt_axiom(index == std::ssize(_left_children) + 1 + std::ssize(_right_children));
75 extent2{_layout.minimum_size(), shared_height},
87 need_layout |= std::exchange(_request_relayout,
false);
92 for (ttlet &child : _left_children) {
93 update_layout_for_child(*child, index++);
99 for (ttlet &child : std::views::reverse(_right_children)) {
100 update_layout_for_child(*child, index++);
103 tt_axiom(index == std::ssize(_left_children) + 1 + std::ssize(_right_children));
112 if (overlaps(context, _clipping_rectangle)) {
113 context.draw_filled_quad(
rectangle(), theme::global->fillColor(_semantic_layer + 1));
125 if (_visible_rectangle.contains(position)) {
126 r =
hit_box{weak_from_this(), _draw_layer, hit_box::Type::MoveArea};
129 for (ttlet &child : _children) {
130 r =
std::max(r, child->hitbox_test(
point2{child->parent_to_local() * position}));
137 template<
typename T, horizontal_alignment Alignment = horizontal_alignment::left,
typename... Args>
140 auto widget = std::make_shared<T>(
window, shared_from_this(), std::forward<Args>(args)...);
145 [[nodiscard]]
bool is_toolbar() const noexcept
override
155 void update_constraints_for_child(
158 relative_base_line &shared_base_line,
159 float &shared_height)
noexcept
163 _layout.update(index, child.preferred_size().minimum().width(), child.width_resistance(), child.margin());
165 shared_height =
std::max(shared_height, child.preferred_size().minimum().height() + child.margin() * 2.0f);
168 void update_layout_for_child(
widget &child, ssize_t index)
const noexcept
172 ttlet[child_x, child_width] = _layout.get_offset_and_size(index++);
174 ttlet child_rectangle = aarectangle{
178 rectangle().height() - child.margin() * 2.0f};
180 child.set_layout_parameters_from_parent(child_rectangle);
Definition alignment.hpp:104
void reserve(ssize_t new_size) noexcept
Grow layout to include upto new_size of items.
Definition flow_layout.hpp:106
void set_size(float total_size) noexcept
Update the layout of all items based on the total size.
Definition flow_layout.hpp:57
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:33
Definition gui_window.hpp:37
Definition hit_box.hpp:15
A ranged integer.
Definition ranged_numeric.hpp:21
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
void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept
Update the internal layout of the widget.
Definition abstract_container_widget.hpp:110
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept
Draw the widget.
Definition abstract_container_widget.hpp:124
std::shared_ptr< widget > add_widget(std::shared_ptr< widget > widget) noexcept
Add a widget directly to this widget.
Definition abstract_container_widget.hpp:39
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 toolbar_widget.hpp:12
bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept
Update the constraints of the widget.
Definition toolbar_widget.hpp:46
hit_box hitbox_test(point2 position) const noexcept
Find the widget that is under the mouse cursor.
Definition toolbar_widget.hpp:119
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept
Draw the widget.
Definition toolbar_widget.hpp:108
std::shared_ptr< T > make_widget(Args &&... args)
Add a widget directly to this widget.
Definition toolbar_widget.hpp:138
void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept
Update the internal layout of the widget.
Definition toolbar_widget.hpp:83
std::shared_ptr< widget > add_widget(horizontal_alignment alignment, std::shared_ptr< widget > widget) noexcept
Add a widget directly to this widget.
Definition toolbar_widget.hpp:33
virtual void init() noexcept
Should be called right after allocating and constructing a widget.
Definition widget.hpp:119
float draw_layer() const noexcept
The first drawing layer of the widget.
Definition widget.hpp:149
widget(gui_window &window, std::shared_ptr< abstract_container_widget > parent) noexcept
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.