From b422e5389b5b78d6037865c77453ab2fb5e47a0d Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Fri, 20 Jun 2014 19:31:35 +0100 Subject: [PATCH] Allow configurable speed factor when ItemView is being swiped. [problem] No way to configure scroll speed factor separately while panning or flicking. Therefore for some layouts you can't get a value to make both panning and flicking work. [cause] Only one scroll speed factor for both panning and flicking. [solution] New API for configurable speed factor while flicking. Change-Id: Ia58a4346db0923410fd61005efb38f4d1ca4a843 Signed-off-by: Adeel Kazmi --- .../controls/scrollable/item-view/item-view-impl.cpp | 2 +- .../controls/scrollable/item-view/item-layout.cpp | 6 ++++++ .../controls/scrollable/item-view/item-layout.h | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp index b8899de..55f87ad 100644 --- a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp @@ -1349,7 +1349,7 @@ void ItemView::OnPan(PanGesture gesture) case Gesture::Continuing: { mScrollDistance = CalculateScrollDistance(gesture.displacement, *mActiveLayout); - mScrollSpeed = Clamp((gesture.GetSpeed() * mActiveLayout->GetScrollSpeedFactor() * MILLISECONDS_PER_SECONDS), 0.0f, mActiveLayout->GetMaximumSwipeSpeed()); + mScrollSpeed = Clamp((gesture.GetSpeed() * mActiveLayout->GetFlickSpeedFactor() * MILLISECONDS_PER_SECONDS), 0.0f, mActiveLayout->GetMaximumSwipeSpeed()); // Refresh order depends on the direction of the scroll; negative is towards the last item. mRefreshOrderHint = mScrollDistance < 0.0f; diff --git a/base/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.cpp b/base/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.cpp index b79c6e7..c4f94f0 100644 --- a/base/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.cpp +++ b/base/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.cpp @@ -237,6 +237,12 @@ int ItemLayout::GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Cont return itemID; } +float ItemLayout::GetFlickSpeedFactor() const +{ + // By default, the speed factor while dragging and swiping is the same. + return GetScrollSpeedFactor(); +} + } // namespace Toolkit } // namespace Dali diff --git a/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h b/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h index 98deaec..5a32df0 100644 --- a/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h +++ b/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h @@ -345,9 +345,9 @@ public: virtual void GetYAxisScrollHint(Vector2& scrollHint) const; /** - * @brief Query the scroll speed factor of the layout. + * @brief Query the scroll speed factor of the layout while dragging. * - * This factor is used by the layout to customise its scroll speed while dragging and swiping. + * This factor is used by the layout to customise its scroll speed while dragging. * The factor will be multiplied with the scroll distance of how many pixels in actor coordinate, * and the layout position of the actors in ItemView will be moved by this result. * For example, when the speed factor is 0.01, if the scroll distance is 100 pixels, the layout @@ -387,6 +387,20 @@ public: */ virtual int GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled); + /** + * @brief Query the flick speed factor of the layout while swipping. + * + * This factor is used by the layout to customise its scroll speed while swiping. + * The factor will be multiplied with the scroll distance of how many pixels in actor coordinate, + * and the layout position of the actors in ItemView will be moved by this result. + * For example, when the speed factor is 0.01, if the scroll distance is 100 pixels, the layout + * position of actors will be moved by 1. + * Therefore, the bigger the factor is, the faster the flick speed will be. + * + * @return The scroll speed factor of the layout. + */ + virtual float GetFlickSpeedFactor() const; + protected: /** -- 2.7.4