Skip to content

Commit 69c5b03

Browse files
committed
Merge pull request #101625 from Rindbee/fix-follow-focus-in-rotated-ScrollContainer
Fix Follow Focus in a rotated `ScrollContainer`
2 parents 7bf6caa + b75acc3 commit 69c5b03

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

scene/gui/scroll_container.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,20 @@ void ScrollContainer::_gui_focus_changed(Control *p_control) {
292292
void ScrollContainer::ensure_control_visible(Control *p_control) {
293293
ERR_FAIL_COND_MSG(!is_ancestor_of(p_control), "Must be an ancestor of the control.");
294294

295-
Rect2 global_rect = get_global_rect();
296-
Rect2 other_rect = p_control->get_global_rect();
295+
// Just eliminate the rotation of this ScrollContainer.
296+
Transform2D other_in_this = get_global_transform().affine_inverse() * p_control->get_global_transform();
297+
298+
Size2 size = get_size();
299+
Rect2 other_rect = other_in_this.xform(Rect2(Point2(), p_control->get_size()));
300+
297301
float side_margin = v_scroll->is_visible() ? v_scroll->get_size().x : 0.0f;
298302
float bottom_margin = h_scroll->is_visible() ? h_scroll->get_size().y : 0.0f;
299303

300-
Vector2 diff = Vector2(MAX(MIN(other_rect.position.x - (is_layout_rtl() ? side_margin : 0.0f), global_rect.position.x), other_rect.position.x + other_rect.size.x - global_rect.size.x + (!is_layout_rtl() ? side_margin : 0.0f)),
301-
MAX(MIN(other_rect.position.y, global_rect.position.y), other_rect.position.y + other_rect.size.y - global_rect.size.y + bottom_margin));
304+
Vector2 diff = Vector2(MAX(MIN(other_rect.position.x - (is_layout_rtl() ? side_margin : 0.0f), 0.0f), other_rect.position.x + other_rect.size.x - size.x + (!is_layout_rtl() ? side_margin : 0.0f)),
305+
MAX(MIN(other_rect.position.y, 0.0f), other_rect.position.y + other_rect.size.y - size.y + bottom_margin));
302306

303-
set_h_scroll(get_h_scroll() + (diff.x - global_rect.position.x));
304-
set_v_scroll(get_v_scroll() + (diff.y - global_rect.position.y));
307+
set_h_scroll(get_h_scroll() + diff.x);
308+
set_v_scroll(get_v_scroll() + diff.y);
305309
}
306310

307311
void ScrollContainer::_reposition_children() {

0 commit comments

Comments
 (0)