diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index fbff1e3f6c..ba8a9ef1bf 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -795,7 +795,7 @@ void ScrollView::Layout() { scrolled.w = views_[0]->GetMeasuredWidth() - margins.horiz(); scrolled.h = views_[0]->GetMeasuredHeight() - margins.vert(); - float layoutScrollPos = ClampedScrollPos(scrollPos_); + layoutScrollPos_ = ClampedScrollPos(scrollPos_); switch (orientation_) { case ORIENT_HORIZONTAL: @@ -803,7 +803,7 @@ void ScrollView::Layout() { ScrollTo(0.0f); lastViewSize_ = scrolled.w; } - scrolled.x = bounds_.x - layoutScrollPos; + scrolled.x = bounds_.x - layoutScrollPos_; scrolled.y = bounds_.y + margins.top; break; case ORIENT_VERTICAL: @@ -812,7 +812,7 @@ void ScrollView::Layout() { lastViewSize_ = scrolled.h; } scrolled.x = bounds_.x + margins.left; - scrolled.y = bounds_.y - layoutScrollPos; + scrolled.y = bounds_.y - layoutScrollPos_; break; } @@ -915,25 +915,27 @@ bool ScrollView::SubviewFocused(View *view) { const float overscroll = std::min(view->GetBounds().h / 1.5f, GetBounds().h / 4.0f); float pos = ClampedScrollPos(scrollPos_); + float visibleSize = orientation_ == ORIENT_VERTICAL ? bounds_.h : bounds_.w; + float visibleEnd = scrollPos_ + visibleSize; + + float viewStart, viewEnd; switch (orientation_) { case ORIENT_HORIZONTAL: - if (vBounds.x2() > bounds_.x2()) { - ScrollTo(pos + vBounds.x2() - bounds_.x2() + overscroll); - } - if (vBounds.x < bounds_.x) { - ScrollTo(pos + (vBounds.x - bounds_.x) - overscroll); - } + viewStart = layoutScrollPos_ + vBounds.x - bounds_.x; + viewEnd = layoutScrollPos_ + vBounds.x2() - bounds_.x; break; case ORIENT_VERTICAL: - if (vBounds.y2() > bounds_.y2()) { - ScrollTo(pos + vBounds.y2() - bounds_.y2() + overscroll); - } - if (vBounds.y < bounds_.y) { - ScrollTo(pos + (vBounds.y - bounds_.y) - overscroll); - } + viewStart = layoutScrollPos_ + vBounds.y - bounds_.y; + viewEnd = layoutScrollPos_ + vBounds.y2() - bounds_.y; break; } + if (viewEnd > visibleEnd) { + ScrollTo(viewEnd - visibleSize + overscroll); + } else if (viewStart < pos) { + ScrollTo(viewStart - overscroll); + } + return true; } diff --git a/Common/UI/ViewGroup.h b/Common/UI/ViewGroup.h index 3460cd7886..ad21b08a0f 100644 --- a/Common/UI/ViewGroup.h +++ b/Common/UI/ViewGroup.h @@ -300,6 +300,7 @@ private: float scrollTarget_ = 0.0f; int scrollTouchId_ = -1; bool scrollToTarget_ = false; + float layoutScrollPos_ = 0.0f; float inertia_ = 0.0f; float pull_ = 0.0f; float lastViewSize_ = 0.0f;