mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-18 03:44:32 +01:00
UI: Have scroll views directly remember their pos.
Kinda like checkboxes, cleaner this way.
This commit is contained in:
1 parent
4d5a63a74e
commit
fc78b408b2
4 files changed
+14
-16
No files matched your search
@@ -1017,17 +1017,13 @@ void ScrollView::PersistData(PersistStatus status, std::string anonId, PersistMa
|
||||
void ScrollView::SetVisibility(Visibility visibility) {
|
||||
ViewGroup::SetVisibility(visibility);
|
||||
|
||||
if (visibility == V_GONE && !rememberPosition_) {
|
||||
if (visibility == V_GONE && !rememberPos_) {
|
||||
// Since this is no longer shown, forget the scroll position.
|
||||
// For example, this happens when switching tabs.
|
||||
ScrollTo(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
float ScrollView::GetScrollPosition() {
|
||||
return scrollPos_;
|
||||
}
|
||||
|
||||
void ScrollView::ScrollTo(float newScrollPos) {
|
||||
scrollTarget_ = newScrollPos;
|
||||
scrollToTarget_ = true;
|
||||
@@ -1141,6 +1137,8 @@ void ScrollView::Update() {
|
||||
|
||||
if (oldPos != scrollPos_)
|
||||
orientation_ == ORIENT_HORIZONTAL ? lastScrollPosX = scrollPos_ : lastScrollPosY = scrollPos_;
|
||||
if (rememberPos_)
|
||||
*rememberPos_ = scrollPos_;
|
||||
}
|
||||
|
||||
void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) {
|
||||
|
||||
@@ -262,8 +262,8 @@ public:
|
||||
// A scrollview usually contains just a single child - a linear layout or similar.
|
||||
class ScrollView : public ViewGroup {
|
||||
public:
|
||||
ScrollView(Orientation orientation, LayoutParams *layoutParams = 0, bool rememberPosition = false)
|
||||
: ViewGroup(layoutParams), orientation_(orientation), rememberPosition_(rememberPosition) {}
|
||||
ScrollView(Orientation orientation, LayoutParams *layoutParams = 0)
|
||||
: ViewGroup(layoutParams), orientation_(orientation) {}
|
||||
~ScrollView();
|
||||
|
||||
void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override;
|
||||
@@ -277,10 +277,14 @@ public:
|
||||
void ScrollTo(float newScrollPos);
|
||||
void ScrollToBottom();
|
||||
void ScrollRelative(float distance);
|
||||
float GetScrollPosition();
|
||||
bool CanScroll() const;
|
||||
void Update() override;
|
||||
|
||||
void RememberPosition(float *pos) {
|
||||
rememberPos_ = pos;
|
||||
ScrollTo(*pos);
|
||||
}
|
||||
|
||||
// Get the last moved scroll view position
|
||||
static void GetLastScrollPosition(float &x, float &y);
|
||||
|
||||
@@ -309,7 +313,7 @@ private:
|
||||
float pull_ = 0.0f;
|
||||
float lastViewSize_ = 0.0f;
|
||||
bool scrollToTopOnSizeChange_ = false;
|
||||
bool rememberPosition_;
|
||||
float *rememberPos_ = nullptr;
|
||||
|
||||
static float lastScrollPosX;
|
||||
static float lastScrollPosY;
|
||||
|
||||
Reference in new issue
Block a user