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();
81 _preferred_base_line = {};
84 return has_updated_contraints;
92 need_layout |= std::exchange(_request_relayout,
false);
95 ttlet vertical_scroll_bar_width =
96 can_scroll_vertically ? _vertical_scroll_bar->preferred_size().minimum().width() : 0.0f;
97 ttlet horizontal_scroll_bar_height =
98 can_scroll_horizontally ? _horizontal_scroll_bar->preferred_size().minimum().height() : 0.0f;
99 ttlet vertical_scroll_bar_height =
rectangle().height() - horizontal_scroll_bar_height;
100 ttlet horizontal_scroll_bar_widht =
rectangle().width() - vertical_scroll_bar_width;
103 ttlet vertical_scroll_bar_rectangle =
aarect{
104 rectangle().right() - vertical_scroll_bar_width,
105 rectangle().y() + horizontal_scroll_bar_height,
106 vertical_scroll_bar_width,
107 rectangle().height() - horizontal_scroll_bar_height};
109 ttlet horizontal_scroll_bar_rectangle =
aarect{
113 if constexpr (can_scroll_horizontally) {
114 _horizontal_scroll_bar->set_layout_parameters(
115 translate2{_window_rectangle} * horizontal_scroll_bar_rectangle, _window_clipping_rectangle);
117 if constexpr (can_scroll_vertically) {
118 _vertical_scroll_bar->set_layout_parameters(
119 translate2{_window_rectangle} * vertical_scroll_bar_rectangle, _window_clipping_rectangle);
123 auto aperture_y = horizontal_scroll_bar_rectangle.top();
124 auto aperture_width = horizontal_scroll_bar_rectangle.width();
125 auto aperture_height = vertical_scroll_bar_rectangle.height();
129 _scroll_content_width = can_scroll_horizontally ? _content->preferred_size().minimum().width() : aperture_width;
130 _scroll_content_height = can_scroll_vertically ? _content->preferred_size().minimum().height() : aperture_height;
132 _scroll_aperture_width = aperture_width;
133 _scroll_aperture_height = aperture_height;
135 ttlet scroll_offset_x_max =
std::max(*_scroll_content_width - aperture_width, 0.0f);
136 ttlet scroll_offset_y_max =
std::max(*_scroll_content_height - aperture_height, 0.0f);
138 _scroll_offset_x = std::clamp(
std::round(*_scroll_offset_x), 0.0f, scroll_offset_x_max);
139 _scroll_offset_y = std::clamp(
std::round(*_scroll_offset_y), 0.0f, scroll_offset_y_max);
141 auto content_x = -*_scroll_offset_x;
142 auto content_y = -*_scroll_offset_y;
143 auto content_width = *_scroll_content_width;
144 auto content_height = *_scroll_content_height;
146 if (can_scroll_horizontally && !_horizontal_scroll_bar->visible()) {
147 ttlet delta_height = horizontal_scroll_bar_rectangle.height();
148 aperture_height += delta_height;
149 aperture_y -= delta_height;
150 content_height += delta_height;
151 content_y -= delta_height;
154 if (can_scroll_vertically && !_vertical_scroll_bar->visible()) {
155 ttlet delta_width = vertical_scroll_bar_rectangle.width();
156 aperture_width += delta_width;
157 content_width += delta_width;
160 if constexpr (controls_window) {
161 ttlet has_horizontal_scroll_bar = can_scroll_horizontally && _horizontal_scroll_bar->visible();
162 ttlet has_vertical_scroll_bar = can_scroll_vertically && _vertical_scroll_bar->visible();
163 window.set_resize_border_priority(
true, !has_vertical_scroll_bar, !has_horizontal_scroll_bar,
true);
167 ttlet aperture_rectangle =
aarect{aperture_x, aperture_y, aperture_width, aperture_height};
168 ttlet window_aperture_clipping_rectangle =
169 intersect(_window_clipping_rectangle,
translate2{_window_rectangle} * aperture_rectangle);
171 ttlet content_rectangle =
aarect{content_x, content_y, content_width, content_height};
173 _content->set_layout_parameters(
174 translate2{_window_rectangle} * content_rectangle, window_aperture_clipping_rectangle);