diff --git a/Common/UI/Screen.cpp b/Common/UI/Screen.cpp index 7df38f3fb0..416c69dc6e 100644 --- a/Common/UI/Screen.cpp +++ b/Common/UI/Screen.cpp @@ -4,6 +4,7 @@ #include "Common/UI/Screen.h" #include "Common/UI/UI.h" #include "Common/UI/View.h" +#include "Common/UI/ViewGroup.h" #include "Common/Log.h" #include "Common/TimeUtil.h" @@ -192,9 +193,11 @@ void ScreenManager::render() { } void ScreenManager::getFocusPosition(float &x, float &y, float &z) { + UI::ScrollView::GetLastScrollPosition(x, y); + UI::View *v = UI::GetFocusedView(); - x = v ? v->GetBounds().x : 0; - y = v ? v->GetBounds().y : 0; + x += v ? v->GetBounds().x : 0; + y += v ? v->GetBounds().y : 0; z = stack_.size(); } diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index ba8a9ef1bf..f73816c229 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -1091,11 +1091,25 @@ bool ScrollView::CanScroll() const { } } +float ScrollView::lastScrollPosX = 0; +float ScrollView::lastScrollPosY = 0; + +ScrollView::~ScrollView() { + lastScrollPosX = 0; + lastScrollPosY = 0; +} + +void ScrollView::GetLastScrollPosition(float &x, float &y) { + x = lastScrollPosX; + y = lastScrollPosY; +} + void ScrollView::Update() { if (visibility_ != V_VISIBLE) { inertia_ = 0.0f; } ViewGroup::Update(); + float oldPos = scrollPos_; Gesture gesture = orientation_ == ORIENT_VERTICAL ? GESTURE_DRAG_VERTICAL : GESTURE_DRAG_HORIZONTAL; gesture_.UpdateFrame(); @@ -1124,6 +1138,9 @@ void ScrollView::Update() { pull_ = 0.0f; } } + + if (oldPos != scrollPos_) + orientation_ == ORIENT_HORIZONTAL ? lastScrollPosX = scrollPos_ : lastScrollPosY = scrollPos_; } void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) { diff --git a/Common/UI/ViewGroup.h b/Common/UI/ViewGroup.h index ad21b08a0f..10ca2fbc09 100644 --- a/Common/UI/ViewGroup.h +++ b/Common/UI/ViewGroup.h @@ -264,6 +264,7 @@ class ScrollView : public ViewGroup { public: ScrollView(Orientation orientation, LayoutParams *layoutParams = 0, bool rememberPosition = false) : ViewGroup(layoutParams), orientation_(orientation), rememberPosition_(rememberPosition) {} + ~ScrollView(); void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override; void Layout() override; @@ -280,6 +281,9 @@ public: bool CanScroll() const; void Update() override; + // Get the last moved scroll view position + static void GetLastScrollPosition(float &x, float &y); + // Override so that we can scroll to the active one after moving the focus. bool SubviewFocused(View *view) override; void PersistData(PersistStatus status, std::string anonId, PersistMap &storage) override; @@ -306,6 +310,9 @@ private: float lastViewSize_ = 0.0f; bool scrollToTopOnSizeChange_ = false; bool rememberPosition_; + + static float lastScrollPosX; + static float lastScrollPosY; }; class ViewPager : public ScrollView {