50 tt_axiom(!can_scroll_horizontally || _horizontal_scroll_bar);
51 tt_axiom(!can_scroll_vertically || _vertical_scroll_bar);
56 if (has_updated_contraints) {
57 auto width = _content->preferred_size().width();
58 auto height = _content->preferred_size().height();
62 if constexpr (can_scroll_horizontally) {
64 ttlet minimum_width =
std::min(width.minimum(), _horizontal_scroll_bar->preferred_size().width().minimum());
65 width = {minimum_width, width.minimum()};
67 if constexpr (can_scroll_vertically) {
68 ttlet minimum_height =
std::min(height.minimum(), _vertical_scroll_bar->preferred_size().height().minimum());
69 height = {minimum_height, height.minimum()};
73 if constexpr (can_scroll_horizontally) {
74 height += _horizontal_scroll_bar->preferred_size().height();
76 if constexpr (can_scroll_vertically) {
77 width += _vertical_scroll_bar->preferred_size().width();
83 return has_updated_contraints;
91 need_layout |= std::exchange(_request_relayout,
false);
94 ttlet vertical_scroll_bar_width =
95 can_scroll_vertically ? _vertical_scroll_bar->preferred_size().minimum().width() : 0.0f;
96 ttlet horizontal_scroll_bar_height =
97 can_scroll_horizontally ? _horizontal_scroll_bar->preferred_size().minimum().height() : 0.0f;
98 ttlet vertical_scroll_bar_height = height() - horizontal_scroll_bar_height;
99 ttlet horizontal_scroll_bar_width = width() - vertical_scroll_bar_width;
103 rectangle().right() - vertical_scroll_bar_width,
104 rectangle().bottom() + horizontal_scroll_bar_height,
105 vertical_scroll_bar_width,
106 rectangle().height() - horizontal_scroll_bar_height};
108 ttlet horizontal_scroll_bar_rectangle =
aarectangle{
112 if constexpr (can_scroll_horizontally) {
113 _horizontal_scroll_bar->set_layout_parameters_from_parent(horizontal_scroll_bar_rectangle);
115 if constexpr (can_scroll_vertically) {
116 _vertical_scroll_bar->set_layout_parameters_from_parent(vertical_scroll_bar_rectangle);
120 auto aperture_y = horizontal_scroll_bar_rectangle.top();
121 auto aperture_width = horizontal_scroll_bar_rectangle.width();
122 auto aperture_height = vertical_scroll_bar_rectangle.height();
126 _scroll_content_width = can_scroll_horizontally ? _content->preferred_size().minimum().width() : aperture_width;
127 _scroll_content_height = can_scroll_vertically ? _content->preferred_size().minimum().height() : aperture_height;
129 _scroll_aperture_width = aperture_width;
130 _scroll_aperture_height = aperture_height;
132 ttlet scroll_offset_x_max =
std::max(*_scroll_content_width - aperture_width, 0.0f);
133 ttlet scroll_offset_y_max =
std::max(*_scroll_content_height - aperture_height, 0.0f);
135 _scroll_offset_x = std::clamp(
std::round(*_scroll_offset_x), 0.0f, scroll_offset_x_max);
136 _scroll_offset_y = std::clamp(
std::round(*_scroll_offset_y), 0.0f, scroll_offset_y_max);
138 auto content_x = -*_scroll_offset_x;
139 auto content_y = -*_scroll_offset_y;
140 auto content_width = *_scroll_content_width;
141 auto content_height = *_scroll_content_height;
143 if (can_scroll_horizontally && !_horizontal_scroll_bar->visible()) {
144 ttlet delta_height = horizontal_scroll_bar_rectangle.height();
145 aperture_height += delta_height;
146 aperture_y -= delta_height;
147 content_height += delta_height;
148 content_y -= delta_height;
151 if (can_scroll_vertically && !_vertical_scroll_bar->visible()) {
152 ttlet delta_width = vertical_scroll_bar_rectangle.width();
153 aperture_width += delta_width;
154 content_width += delta_width;
157 if constexpr (controls_window) {
158 ttlet has_horizontal_scroll_bar = can_scroll_horizontally && _horizontal_scroll_bar->visible();
159 ttlet has_vertical_scroll_bar = can_scroll_vertically && _vertical_scroll_bar->visible();
160 window.set_resize_border_priority(
true, !has_vertical_scroll_bar, !has_horizontal_scroll_bar,
true);
164 ttlet aperture_rectangle =
aarectangle{aperture_x, aperture_y, aperture_width, aperture_height};
165 ttlet content_rectangle =
aarectangle{content_x, content_y, content_width, content_height};
167 _content->set_layout_parameters_from_parent(
168 content_rectangle, aperture_rectangle, _content->draw_layer() - _draw_layer);