7#include "abstract_container_widget.hpp"
8#include "../GUI/theme.hpp"
9#include "../flow_layout.hpp"
10#include "../alignment.hpp"
15template<arrangement Arrangement>
19 static constexpr auto arrangement = Arrangement;
32 auto shared_thickness = 0.0f;
35 _layout.
reserve(std::ssize(_children));
38 for (ttlet &child : _children) {
39 update_constraints_for_child(*child, index++, shared_base_line, shared_thickness);
42 tt_axiom(index == std::ssize(_children));
44 if constexpr (arrangement == arrangement::row) {
45 _preferred_size = {_layout.minimum_size(), shared_thickness};
47 _preferred_size = {shared_thickness, _layout.minimum_size()};
59 need_layout |= std::exchange(_request_relayout,
false);
64 for (ttlet &child : _children) {
65 update_layout_for_child(*child, index++);
68 tt_axiom(index == std::ssize(_children));
76 void update_constraints_for_child(
80 float &shared_thickness)
noexcept
84 ttlet length = arrangement == arrangement::row ? child.preferred_size().minimum().width() :
85 child.preferred_size().minimum().height();
86 ttlet thickness = arrangement == arrangement::row ? child.preferred_size().minimum().height() :
87 child.preferred_size().minimum().width();
89 ttlet length_resistance = arrangement == arrangement::row ? child.width_resistance() : child.height_resistance();
91 _layout.update(index, length, length_resistance, child.margin());
93 shared_thickness =
std::max(shared_thickness, thickness + child.margin() * 2.0f);
96 void update_layout_for_child(
widget &child, ssize_t index)
const noexcept
102 ttlet child_rectangle = arrangement == arrangement::row ?
107 rectangle().height() - child.margin() * 2.0f} :
110 rectangle().top() - child_offset - child_length,
111 rectangle().width() - child.margin() * 2.0f,
116 child.set_layout_parameters_from_parent(child_rectangle);
120using row_layout_widget = row_column_layout_widget<arrangement::row>;
121using column_layout_widget = row_column_layout_widget<arrangement::column>;
Definition alignment.hpp:104
Layout algorithm.
Definition flow_layout.hpp:18
void reserve(ssize_t new_size) noexcept
Grow layout to include upto new_size of items.
Definition flow_layout.hpp:106
std::pair< float, float > get_offset_and_size(ssize_t first, ssize_t last) const noexcept
Definition flow_layout.hpp:88
void set_size(float total_size) noexcept
Update the layout of all items based on the total size.
Definition flow_layout.hpp:57
Definition gui_window.hpp:37
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
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 row_column_layout_widget.hpp:16
bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept
Update the constraints of the widget.
Definition row_column_layout_widget.hpp:26
void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept
Update the internal layout of the widget.
Definition row_column_layout_widget.hpp:55
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.