summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorTomasz Chabora <kobewi4e@gmail.com>2019-12-17 00:51:07 +0100
committerTomasz Chabora <kobewi4e@gmail.com>2019-12-17 00:51:07 +0100
commit3a3cab64948050ba1fd75540892e5930caeadb3e (patch)
tree4c0609d39f7e8fe1630c920b9db540893b4fae0e /scene
parentc3ea4ea9b76d1bacde83f7b70af4638cf2ff41a2 (diff)
Use global transform when calculating scroll
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/scroll_container.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index a882835aed..cb9ae875b7 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -236,6 +236,8 @@ void ScrollContainer::_update_scrollbar_position() {
void ScrollContainer::_ensure_focused_visible(Control *p_control) {
if (is_a_parent_of(p_control)) {
+ Rect2 global_rect = get_global_rect();
+ Rect2 other_rect = p_control->get_global_rect();
float right_margin = 0;
if (v_scroll->is_visible()) {
right_margin += v_scroll->get_size().x;
@@ -245,8 +247,10 @@ void ScrollContainer::_ensure_focused_visible(Control *p_control) {
bottom_margin += h_scroll->get_size().y;
}
- set_v_scroll(MAX(MIN(p_control->get_begin().y, get_v_scroll()), p_control->get_end().y - get_size().y + bottom_margin));
- set_h_scroll(MAX(MIN(p_control->get_begin().x, get_h_scroll()), p_control->get_end().x - get_size().x + right_margin));
+ float diff = MAX(MIN(other_rect.position.y, global_rect.position.y), other_rect.position.y + other_rect.size.y - global_rect.size.y + bottom_margin);
+ set_v_scroll(get_v_scroll() + (diff - global_rect.position.y));
+ diff = MAX(MIN(other_rect.position.x, global_rect.position.x), other_rect.position.x + other_rect.size.x - global_rect.size.x + right_margin);
+ set_h_scroll(get_h_scroll() + (diff - global_rect.position.x));
}
}