mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-18 11:54:30 +01:00
UI: Add ScrollView::ScrollToCenter and GetEnclosingScrollView
For bringing a given view into the middle of the scroll view it's in, rather than just into sight like focusing does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b6f79261a2
commit
0dc5812f32
2 files changed
+26
No files matched your search
@@ -468,6 +468,25 @@ void ScrollView::ScrollTo(float newScrollPos) {
|
||||
scrollToTarget_ = true;
|
||||
}
|
||||
|
||||
void ScrollView::ScrollToCenter(const View *view) {
|
||||
const Bounds &vBounds = view->GetBounds();
|
||||
if (orientation_ == ORIENT_VERTICAL) {
|
||||
ScrollTo(layoutScrollPos_ + vBounds.centerY() - bounds_.y - bounds_.h * 0.5f);
|
||||
} else {
|
||||
ScrollTo(layoutScrollPos_ + vBounds.centerX() - bounds_.x - bounds_.w * 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollView *GetEnclosingScrollView(View *view) {
|
||||
for (ViewGroup *group = view->Parent(); group; group = group->Parent()) {
|
||||
ScrollView *scrollView = dynamic_cast<ScrollView *>(group);
|
||||
if (scrollView) {
|
||||
return scrollView;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ScrollView::ScrollRelative(float distance) {
|
||||
scrollTarget_ = scrollPos_ + distance;
|
||||
scrollToTarget_ = true;
|
||||
|
||||
Reference in new issue
Block a user