UI: Fix scrollview focus scroll before relayout.

Need to use the position of the bounds as of last layout, not the new
desired position.
This commit is contained in:
Unknown W. Brackets 2021-08-29 17:35:58 -07:00
parent 01edd695c8
commit e9ebd86439
2 changed files with 18 additions and 15 deletions

View file

@ -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;
}

View file

@ -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;