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);
70 for (ttlet &child : std::views::reverse(_right_children)) {
71 update_constraints_for_child(*child, index++, shared_base_line, shared_height);
74 tt_axiom(index == std::ssize(_left_children) + 1 + std::ssize(_right_children));
76 _preferred_base_line = shared_base_line;
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));
113 context.fill_color = theme::global->fillColor(_semantic_layer + 1);
122 ttlet lock = std::scoped_lock(gui_system_mutex);
126 if (_window_clipping_rectangle.contains(window_position)) {
127 r =
hit_box{weak_from_this(), _draw_layer, hit_box::Type::MoveArea};
130 for (ttlet &child : _children) {
131 r =
std::max(r, child->hitbox_test(window_position));
138 template<
typename T, horizontal_alignment Alignment = horizontal_alignment::left,
typename... Args>
141 auto widget = std::make_shared<T>(
window, shared_from_this(), std::forward<Args>(args)...);
146 [[nodiscard]]
bool is_toolbar() const noexcept
override
156 void update_constraints_for_child(
159 relative_base_line &shared_base_line,
160 float &shared_height)
noexcept
164 _layout.update(index, child.preferred_size().minimum().width(), child.width_resistance(), child.margin(), relative_base_line{});
166 shared_base_line =
std::max(shared_base_line, child.preferred_base_line());
167 shared_height =
std::max(shared_height, child.preferred_size().minimum().height() + child.margin() * 2.0f);
170 void update_layout_for_child(
widget &child, ssize_t index)
const noexcept
174 ttlet[child_x, child_width] = _layout.get_offset_and_size(index++);
176 ttlet child_rectangle = aarect{
180 rectangle().height() - child.margin() * 2.0f};
182 ttlet child_window_rectangle = translate2{_window_rectangle} * child_rectangle;
184 child.set_layout_parameters(child_window_rectangle, _window_clipping_rectangle, _window_base_line);
Definition alignment.hpp:104
void reserve(ssize_t new_size) noexcept
Grow layout to include upto new_size of items.
Definition flow_layout.hpp:112
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:39
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:111
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept
Draw the widget.
Definition abstract_container_widget.hpp:125
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:96
Definition toolbar_widget.hpp:12
hit_box hitbox_test(f32x4 window_position) const noexcept
Find the widget that is under the mouse cursor.
Definition toolbar_widget.hpp:120
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
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:139
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
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:100
abstract_container_widget const & parent() const noexcept
Get a reference to the parent.
virtual aarect window_clipping_rectangle() const noexcept
Get the clipping-rectangle in window coordinates.
Definition widget.hpp:320
aarect rectangle() const noexcept
Get the rectangle in local coordinates.
Definition widget.hpp:340