-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-// INTERNAL INCLUDES
-#include <dali/public-api/events/mouse-wheel-event.h>
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
-#include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
-#include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
+// CLASS HEADER
#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h>
-#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-effect-impl.h>
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/actors/actor-devel.h>
+#include <dali/devel-api/common/stage.h>
+#include <dali/devel-api/events/pan-gesture-devel.h>
+#include <dali/devel-api/object/property-helper-devel.h>
+#include <dali/integration-api/debug.h>
+#include <dali/public-api/animation/constraints.h>
+#include <dali/public-api/events/touch-event.h>
+#include <dali/public-api/events/wheel-event.h>
+#include <dali/public-api/object/property-map.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/object/type-registry.h>
+#include <cstring> // for strcmp
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-overshoot-indicator-impl.h>
+#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-effect-impl.h>
+#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl-property-handler.h>
+#include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-mode.h>
+#include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
+#include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
+
+//#define ENABLED_SCROLL_STATE_LOGGING
+
+#ifdef ENABLED_SCROLL_STATE_LOGGING
+#define DALI_LOG_SCROLL_STATE(format, ...) Dali::Integration::Log::LogMessageWithFunctionLine(Dali::Integration::Log::DebugInfo, "%s:%d " format "\n", __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
+#else
+#define DALI_LOG_SCROLL_STATE(format, ...)
+#endif
// TODO: Change to two class system:
-// 1. DraggableActor (is an actor which can be dragged anywhere/scaled/rotated, can be set to range using the ruler)
+// 1. DraggableActor (is an actor which can be dragged anywhere, can be set to range using the ruler)
// 2. ScrollView (contains a draggable actor that can a) be dragged in the negative X, and Y domain, b) has a hitArea for touches)
-// TODO: Rotation
-// TODO: Asymetrical scaling
// TODO: external components (page and status overlays).
// TODO: Orientation.
// TODO: upgrade Vector2/3 to support returning Unit vectors, normals, & cross product (dot product is already provided)
-using namespace Dali;
-
namespace
{
+using namespace Dali;
-const int DEFAULT_REFRESH_INTERVAL_MILLISECONDS = 50; ///< Refresh rate TODO: Animation should have an update signal (and see item-view-impl)
-const float FLICK_SPEED_THRESHOLD = 500.0f; ///< Flick threshold in pixels/ms
-const float FREE_FLICK_SPEED_THRESHOLD = 200.0f; ///< Free-Flick threshold in pixels/ms
-const float AUTOLOCK_AXIS_MINIMUM_DISTANCE2 = 100.0f; ///< Auto-lock axis after minimum distance squared.
-const float FLICK_ORTHO_ANGLE_RANGE = 60.0f; ///< degrees. (if >45, then supports diagonal flicking)
-const unsigned int MAXIMUM_NUMBER_OF_VALUES = 5; ///< Number of values to use for weighted pan calculation.
-const Vector2 DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION = Vector2(0.17f, 0.1f); ///< The step of horizontal scroll distance in the proportion of stage size for each mouse wheel event received.
-const unsigned long MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET( 150u );
+constexpr float DEFAULT_SLOW_SNAP_ANIMATION_DURATION(0.5f); ///< Default Drag-Release animation time.
+constexpr float DEFAULT_FAST_SNAP_ANIMATION_DURATION(0.25f); ///< Default Drag-Flick animation time.
+constexpr float DEFAULT_SNAP_OVERSHOOT_DURATION(0.5f); ///< Default Overshoot snapping animation time.
+constexpr float DEFAULT_MAX_OVERSHOOT(100.0f); ///< Default maximum allowed overshoot in pixels
-// predefined effect values
-const Vector3 ANGLE_CAROUSEL_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f);
-const Vector3 ANGLE_CUBE_PAGE_ROTATE(Math::PI * 0.2f, Math::PI * 0.2f, 0.0f); ///< Cube page rotates as if it has ten sides with the camera positioned inside
-const Vector2 ANGLE_CUSTOM_CUBE_SWING(-Math::PI * 0.45f, -Math::PI * 0.45f); ///< outer cube pages swing 90 degrees as they pan offscreen
-const Vector2 ANGLE_SPIRAL_SWING_IN(Math::PI * 0.5f, Math::PI * 0.5f);
-const Vector2 ANGLE_SPIRAL_SWING_OUT(Math::PI * 0.35f, Math::PI * 0.35f);
-const Vector2 ANGLE_OUTER_CUBE_SWING(Math::PI * 0.5f, Math::PI * 0.5f); ///< outer cube pages swing 90 degrees as they pan offscreen
+constexpr float DEFAULT_AXIS_AUTO_LOCK_GRADIENT(0.36f); ///< Default Axis-AutoLock gradient threshold. default is 0.36:1 (20 degrees)
+constexpr float DEFAULT_FRICTION_COEFFICIENT(1.0f); ///< Default Friction Co-efficient. (in stage diagonals per second)
+constexpr float DEFAULT_FLICK_SPEED_COEFFICIENT(1.0f); ///< Default Flick speed coefficient (multiples input touch velocity)
+constexpr float DEFAULT_MAX_FLICK_SPEED(3.0f); ///< Default Maximum flick speed. (in stage diagonals per second)
-// Helpers ////////////////////////////////////////////////////////////////////////////////////////
+constexpr Dali::Vector2 DEFAULT_MIN_FLICK_DISTANCE(30.0f, 30.0f); ///< minimum distance for pan before flick allowed
+constexpr float DEFAULT_MIN_FLICK_SPEED_THRESHOLD(500.0f); ///< Minimum pan speed required for flick in pixels/s
-// TODO: GetAngle for Vector2 can be moved.
-// GetAngle for Vector3 needs to be measured against a normal/plane.
+constexpr float FREE_FLICK_SPEED_THRESHOLD = 200.0f; ///< Free-Flick threshold in pixels/ms
+constexpr float AUTOLOCK_AXIS_MINIMUM_DISTANCE2 = 100.0f; ///< Auto-lock axis after minimum distance squared.
+constexpr float FLICK_ORTHO_ANGLE_RANGE = 75.0f; ///< degrees. (if >45, then supports diagonal flicking)
-/**
- * @param[in] vector The 3D vector to be measured
- * @return angle in radians from 0 to 2PI
- */
-float GetAngle(const Vector3& vector)
-{
- return atan2(vector.y, vector.x) + Math::PI;
-}
+constexpr Dali::Vector2 DEFAULT_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION(0.17f, 0.1f); ///< The step of horizontal scroll distance in the proportion of stage size for each wheel event received.
-/**
- * @param[in] vector The 2D vector to be measured
- * @return angle in radians from 0 to 2PI
- */
-float GetAngle(const Vector2& vector)
-{
- return atan2(vector.y, vector.x) + Math::PI;
-}
+constexpr unsigned long MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET(150u);
+constexpr float TOUCH_DOWN_TIMER_INTERVAL = 100.0f;
+constexpr float DEFAULT_SCROLL_UPDATE_DISTANCE(30.0f); ///< Default distance to travel in pixels for scroll update signal
+
+const std::string INTERNAL_MAX_POSITION_PROPERTY_NAME("internalMaxPosition");
+
+// Helpers ////////////////////////////////////////////////////////////////////////////////////////
/**
* Find the vector (distance) from (a) to (b)
*/
float VectorInDomain(float a, float b, float start, float end, Dali::Toolkit::DirectionBias bias)
{
- if(bias == Dali::Toolkit::DirectionBiasNone)
+ if(bias == Dali::Toolkit::DIRECTION_BIAS_NONE)
{
- return ShortestDistanceInDomain( a, b, start, end );
+ return Dali::ShortestDistanceInDomain(a, b, start, end);
}
// (a-start + end-b)
- float size = end-start;
- float vect = b-a;
+ float size = end - start;
+ float vect = b - a;
if(vect > 0)
{
// +ve vector
- if(bias == Dali::Toolkit::DirectionBiasRight) // going right, take the vector.
+ if(bias == Dali::Toolkit::DIRECTION_BIAS_RIGHT) // going right, take the vector.
{
return vect;
}
else
{
- float aRight = a+size;
- return b-aRight;
+ float aRight = a + size;
+ return b - aRight;
}
}
else
{
// -ve vector
- if(bias == Dali::Toolkit::DirectionBiasLeft) // going left, take the vector.
+ if(bias == Dali::Toolkit::DIRECTION_BIAS_LEFT) // going left, take the vector.
{
return vect;
}
else
{
- float aLeft = a-size;
- return b-aLeft;
+ float aLeft = a - size;
+ return b - aLeft;
}
}
}
* @param anchor The Anchor point of interest.
* @return The position of the Anchor
*/
-Vector3 GetPositionOfAnchor(Actor &actor, const Vector3 &anchor)
+Dali::Vector3 GetPositionOfAnchor(Dali::Actor& actor, const Dali::Vector3& anchor)
{
- Vector3 childPosition = actor.GetCurrentPosition();
- Vector3 childAnchor = - actor.GetCurrentAnchorPoint() + anchor;
- Vector3 childSize = actor.GetCurrentSize();
+ Dali::Vector3 childPosition = actor.GetCurrentProperty<Dali::Vector3>(Dali::Actor::Property::POSITION);
+ Dali::Vector3 childAnchor = -actor.GetCurrentProperty<Dali::Vector3>(Dali::Actor::Property::ANCHOR_POINT) + anchor;
+ Dali::Vector3 childSize = actor.GetCurrentProperty<Dali::Vector3>(Dali::Actor::Property::SIZE);
return childPosition + childAnchor * childSize;
}
-// AlphaFunctions /////////////////////////////////////////////////////////////////////////////////
+/**
+ * Returns the closest actor to the given position
+ * @param[in] actor The scrollview actor
+ * @param[in] internalActor The internal actor (to ignore)
+ * @param[in] position The given position
+ * @param[in] dirX Direction to search in
+ * @param[in] dirY Direction to search in
+ * @param[in] dirZ Direction to search in
+ * @return the closest child actor
+ */
+using FindDirection = Dali::Toolkit::Internal::ScrollView::FindDirection;
-float FinalDefaultAlphaFunction(float offset)
+Actor FindClosestActorToPosition(
+ CustomActor actor, Actor internalActor, const Vector3& position, FindDirection dirX, FindDirection dirY, FindDirection dirZ)
{
- return offset * 0.5f;
+ Actor closestChild;
+ float closestDistance2 = 0.0f;
+ Vector3 actualPosition = position;
+
+ unsigned int numChildren = actor.GetChildCount();
+
+ for(unsigned int i = 0; i < numChildren; ++i)
+ {
+ Actor child = actor.GetChildAt(i);
+
+ if(internalActor == child) // ignore internal actor.
+ {
+ continue;
+ }
+
+ Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
+
+ Vector3 delta = childPosition - actualPosition;
+
+ // X-axis checking (only find Actors to the [dirX] of actualPosition)
+ if(dirX > FindDirection::All) // != All,None
+ {
+ FindDirection deltaH = delta.x > 0 ? FindDirection::Right : FindDirection::Left;
+ if(dirX != deltaH)
+ {
+ continue;
+ }
+ }
+
+ // Y-axis checking (only find Actors to the [dirY] of actualPosition)
+ if(dirY > FindDirection::All) // != All,None
+ {
+ FindDirection deltaV = delta.y > 0 ? FindDirection::Down : FindDirection::Up;
+ if(dirY != deltaV)
+ {
+ continue;
+ }
+ }
+
+ // Z-axis checking (only find Actors to the [dirZ] of actualPosition)
+ if(dirZ > FindDirection::All) // != All,None
+ {
+ FindDirection deltaV = delta.y > 0 ? FindDirection::In : FindDirection::Out;
+ if(dirZ != deltaV)
+ {
+ continue;
+ }
+ }
+
+ // compare child to closest child in terms of distance.
+ float distance2 = 0.0f;
+
+ // distance2 = the Square of the relevant dimensions of delta
+ if(dirX != FindDirection::None)
+ {
+ distance2 += delta.x * delta.x;
+ }
+
+ if(dirY != FindDirection::None)
+ {
+ distance2 += delta.y * delta.y;
+ }
+
+ if(dirZ != FindDirection::None)
+ {
+ distance2 += delta.z * delta.z;
+ }
+
+ if(closestChild) // Next time.
+ {
+ if(distance2 < closestDistance2)
+ {
+ closestChild = child;
+ closestDistance2 = distance2;
+ }
+ }
+ else // First time.
+ {
+ closestChild = child;
+ closestDistance2 = distance2;
+ }
+ }
+
+ return closestChild;
}
+// AlphaFunctions /////////////////////////////////////////////////////////////////////////////////
+
/**
* ConstantDecelerationAlphaFunction
* Newtoninan distance for constant deceleration
return progress * 2.0f - progress * progress;
}
-// Internal Constraints ///////////////////////////////////////////////////////////////////////////
-
/**
- * Internal Relative position Constraint
- * Generates the relative position value of the scroll view
- * based on the absolute position, and it's relation to the
- * scroll domain. This is a value from 0.0f to 1.0f in each
- * scroll position axis.
+ * Clamp a position
+ * @param[in] size The size to clamp to
+ * @param[in] rulerX The horizontal ruler
+ * @param[in] rulerY The vertical ruler
+ * @param[in,out] position The position to clamp
+ * @param[out] clamped the clamped state
*/
-Vector3 InternalRelativePositionConstraint(const Vector3& current,
- const PropertyInput& scrollPositionProperty,
- const PropertyInput& scrollMinProperty,
- const PropertyInput& scrollMaxProperty,
- const PropertyInput& scrollSizeProperty)
+void ClampPosition(const Vector3& size, Dali::Toolkit::RulerPtr rulerX, Dali::Toolkit::RulerPtr rulerY, Vector2& position, Dali::Toolkit::ClampState2D& clamped)
{
- const Vector3& position = -scrollPositionProperty.GetVector3();
- const Vector3& min = scrollMinProperty.GetVector3();
- const Vector3& max = scrollMaxProperty.GetVector3();
- const Vector3& size = scrollSizeProperty.GetVector3();
-
- Vector3 relativePosition;
- Vector3 domainSize = (max - min) - size;
-
- relativePosition.x = domainSize.x > Math::MACHINE_EPSILON_1 ? fabsf((position.x - min.x) / domainSize.x) : 0.0f;
- relativePosition.y = domainSize.y > Math::MACHINE_EPSILON_1 ? fabsf((position.y - min.y) / domainSize.y) : 0.0f;
-
- return relativePosition;
+ position.x = -rulerX->Clamp(-position.x, size.width, 1.0f, clamped.x); // NOTE: X & Y rulers think in -ve coordinate system.
+ position.y = -rulerY->Clamp(-position.y, size.height, 1.0f, clamped.y); // That is scrolling RIGHT (e.g. 100.0, 0.0) means moving LEFT.
}
-} // unnamed namespace
-
-namespace Dali
+/**
+ * TODO: In situations where axes are different (X snap, Y free)
+ * Each axis should really have their own independent animation (time and equation)
+ * Consider, X axis snapping to nearest grid point (EaseOut over fixed time)
+ * Consider, Y axis simulating physics to arrive at a point (Physics equation over variable time)
+ * Currently, the axes have been split however, they both use the same EaseOut equation.
+ *
+ * @param[in] scrollView The main scrollview
+ * @param[in] rulerX The X ruler
+ * @param[in] rulerY The Y ruler
+ * @param[in] lockAxis Which axis (if any) is locked.
+ * @param[in] velocity Current pan velocity
+ * @param[in] maxOvershoot Maximum overshoot
+ * @param[in] inAcessibilityPan True if we are currently panning with accessibility
+ * @param[out] positionSnap The target position of snap animation
+ * @param[out] positionDuration The duration of the snap animation
+ * @param[out] alphaFunction The snap animation alpha function
+ * @param[out] isFlick if we are flicking or not
+ * @param[out] isFreeFlick if we are free flicking or not
+ */
+void SnapWithVelocity(
+ Dali::Toolkit::Internal::ScrollView& scrollView,
+ Dali::Toolkit::RulerPtr rulerX,
+ Dali::Toolkit::RulerPtr rulerY,
+ Dali::Toolkit::Internal::ScrollView::LockAxis lockAxis,
+ Vector2 velocity,
+ Vector2 maxOvershoot,
+ Vector2& positionSnap,
+ Vector2& positionDuration,
+ AlphaFunction& alphaFunction,
+ bool inAccessibilityPan,
+ bool& isFlick,
+ bool& isFreeFlick)
{
+ // Animator takes over now, touches are assumed not to interfere.
+ // And if touches do interfere, then we'll stop animation, update PrePosition
+ // to current mScroll's properties, and then resume.
+ // Note: For Flicking this may work a bit different...
-namespace Toolkit
-{
+ float angle = atan2(velocity.y, velocity.x);
+ float speed2 = velocity.LengthSquared();
+ float biasX = 0.5f;
+ float biasY = 0.5f;
+ FindDirection horizontal = FindDirection::None;
+ FindDirection vertical = FindDirection::None;
-namespace Internal
-{
+ using LockAxis = Dali::Toolkit::Internal::ScrollView::LockAxis;
-namespace
-{
+ // orthoAngleRange = Angle tolerance within the Exact N,E,S,W direction
+ // that will be accepted as a general N,E,S,W flick direction.
-/**
- * Internal Pre-Position Property Constraint.
- *
- * Generates position property based on current position + gesture displacement.
- * Or generates position property based on positionX/Y.
- * Note: This is the position prior to any clamping at scroll boundaries.
- * TODO: Scale & Rotation Transforms.
- */
-struct InternalPrePositionConstraint
-{
- InternalPrePositionConstraint(const Vector2& initialPanMask,
- bool axisAutoLock,
- float axisAutoLockGradient)
- : mInitialPanMask(initialPanMask),
- mAxisAutoLock(axisAutoLock),
- mLockAxis(ScrollView::LockPossible),
- mAxisAutoLockGradient(axisAutoLockGradient),
- mPrePosition(Vector3::ZERO),
- mWasPanning(false)
- {
- }
+ const float orthoAngleRange = FLICK_ORTHO_ANGLE_RANGE * M_PI / 180.0f;
+ const float flickSpeedThreshold2 = scrollView.GetMinimumSpeedForFlick() * scrollView.GetMinimumSpeedForFlick();
+
+ // Flick logic X Axis
- Vector3 operator()(const Vector3& current,
- const PropertyInput& gesturePositionProperty,
- const PropertyInput& gestureDisplacementProperty,
- const PropertyInput& scrollPositionXProperty,
- const PropertyInput& scrollPositionYProperty,
- const PropertyInput& panningProperty)
+ if(rulerX->IsEnabled() && lockAxis != LockAxis::LockHorizontal)
{
- const bool panning = panningProperty.GetBoolean();
- Vector3 scrollPostPosition;
+ horizontal = FindDirection::All;
- if(panning)
+ if(speed2 > flickSpeedThreshold2 || // exceeds flick threshold
+ inAccessibilityPan) // With AccessibilityPan its easier to move between snap positions
{
- // Check if panning has just started...
- if(!mWasPanning)
+ if((angle >= -orthoAngleRange) && (angle < orthoAngleRange)) // Swiping East
{
- mLocalStart = gesturePositionProperty.GetVector2() - gestureDisplacementProperty.GetVector2();
- mPrePosition = current;
- mLockAxis = ScrollView::LockPossible;
+ biasX = 0.0f, horizontal = FindDirection::Left;
- mCurrentPanMask = mInitialPanMask;
+ // This guards against an error where no movement occurs, due to the flick finishing
+ // before the update-thread has advanced mScrollPostPosition past the the previous snap point.
+ positionSnap.x += 1.0f;
}
+ else if((angle >= M_PI - orthoAngleRange) || (angle < -M_PI + orthoAngleRange)) // Swiping West
+ {
+ biasX = 1.0f, horizontal = FindDirection::Right;
- // Calculate Deltas...
- Vector2 currentPosition = gesturePositionProperty.GetVector2();
- Vector2 panDelta( currentPosition - mLocalStart );
-
- // Axis Auto Lock - locks the panning to the horizontal or vertical axis if the pan
- // appears mostly horizontal or mostly vertical respectively...
- AxisAutoLock(panDelta);
-
- // Restrict deltas based on ruler enable/disable and axis-lock state...
- panDelta *= mCurrentPanMask;
-
- // Perform Position transform based on input deltas...
- scrollPostPosition = mPrePosition;
- scrollPostPosition.GetVectorXY() += panDelta;
- }
- else
- {
- scrollPostPosition.x = scrollPositionXProperty.GetFloat();
- scrollPostPosition.y = scrollPositionYProperty.GetFloat();
+ // This guards against an error where no movement occurs, due to the flick finishing
+ // before the update-thread has advanced mScrollPostPosition past the the previous snap point.
+ positionSnap.x -= 1.0f;
+ }
}
-
- mWasPanning = panning;
- return scrollPostPosition;
}
- void AxisAutoLock(Vector2& panDelta)
+ // Flick logic Y Axis
+
+ if(rulerY->IsEnabled() && lockAxis != LockAxis::LockVertical)
{
- if(mAxisAutoLock)
+ vertical = FindDirection::All;
+
+ if(speed2 > flickSpeedThreshold2 || // exceeds flick threshold
+ inAccessibilityPan) // With AccessibilityPan its easier to move between snap positions
{
- if(panDelta.LengthSquared() > AUTOLOCK_AXIS_MINIMUM_DISTANCE2 &&
- mLockAxis == ScrollView::LockPossible)
+ if((angle >= M_PI_2 - orthoAngleRange) && (angle < M_PI_2 + orthoAngleRange)) // Swiping South
{
- float dx = fabsf(panDelta.x);
- float dy = fabsf(panDelta.y);
- if(dx * mAxisAutoLockGradient >= dy)
- {
- // 0.36:1 gradient to the horizontal (deviate < 20 degrees)
- mLockAxis = ScrollView::LockVertical;
- mCurrentPanMask.y = 0.0f;
- }
- else if(dy * mAxisAutoLockGradient > dx)
- {
- // 0.36:1 gradient to the vertical (deviate < 20 degrees)
- mLockAxis = ScrollView::LockHorizontal;
- mCurrentPanMask.x = 0.0f;
- }
- else
- {
- mLockAxis = ScrollView::LockNone;
- }
+ biasY = 0.0f, vertical = FindDirection::Up;
+ }
+ else if((angle >= -M_PI_2 - orthoAngleRange) && (angle < -M_PI_2 + orthoAngleRange)) // Swiping North
+ {
+ biasY = 1.0f, vertical = FindDirection::Down;
}
- } // end if mAxisAutoLock
+ }
}
- Vector2 mLocalStart;
- Vector2 mInitialPanMask; ///< Initial pan mask (based on ruler settings)
- Vector2 mCurrentPanMask; ///< Current pan mask that can be altered by axis lock mode.
-
- bool mAxisAutoLock; ///< Set by ScrollView
- ScrollView::LockAxis mLockAxis;
- float mAxisAutoLockGradient; ///< Set by ScrollView
- Vector3 mPrePosition;
- bool mWasPanning;
-};
+ // isFlick: Whether this gesture is a flick or not.
+ isFlick = (horizontal != FindDirection::All || vertical != FindDirection::All);
+ // isFreeFlick: Whether this gesture is a flick under free panning criteria.
+ isFreeFlick = velocity.LengthSquared() > (FREE_FLICK_SPEED_THRESHOLD * FREE_FLICK_SPEED_THRESHOLD);
-/**
- * Internal Position Property Constraint.
- *
- * Generates position property based on pre-position
- * Note: This is the position after clamping.
- * (uses result of InternalPrePositionConstraint)
- */
-struct InternalPositionConstraint
-{
- InternalPositionConstraint(const RulerDomain& domainX, const RulerDomain& domainY)
- : mDomainMin( -domainX.min, -domainY.min ),
- mDomainMax( -domainX.max, -domainY.max ),
- mClampX( domainX.enabled ),
- mClampY( domainY.enabled )
+ if(isFlick || isFreeFlick)
{
+ positionDuration = Vector2::ONE * scrollView.GetScrollFlickDuration();
+ alphaFunction = scrollView.GetScrollFlickAlphaFunction();
}
- Vector3 operator()(const Vector3& current,
- const PropertyInput& scrollPositionProperty,
- const PropertyInput& scrollSizeProperty)
- {
- Vector3 position = scrollPositionProperty.GetVector3();
- const Vector2& size = scrollSizeProperty.GetVector3().GetVectorXY();
+ // Calculate next positionSnap ////////////////////////////////////////////////////////////
- position.x = mClampX ? Clamp(position.x, mDomainMax.x + size.x, mDomainMin.x ) : position.x;
- position.y = mClampY ? Clamp(position.y, mDomainMax.y + size.y, mDomainMin.y ) : position.y;
+ if(scrollView.GetActorAutoSnap())
+ {
+ Vector3 size = scrollView.Self().GetCurrentProperty<Vector3>(Actor::Property::SIZE);
- return position;
- }
+ Actor child = scrollView.FindClosestActorToPosition(Vector3(size.width * 0.5f, size.height * 0.5f, 0.0f), horizontal, vertical);
- Vector2 mDomainMin;
- Vector2 mDomainMax;
- bool mClampX;
- bool mClampY;
+ if(!child && isFlick)
+ {
+ // If we conducted a direction limited search and found no actor, then just snap to the closest actor.
+ child = scrollView.FindClosestActorToPosition(Vector3(size.width * 0.5f, size.height * 0.5f, 0.0f));
+ }
-};
+ if(child)
+ {
+ Vector2 position = scrollView.Self().GetCurrentProperty<Vector2>(Toolkit::ScrollView::Property::SCROLL_POSITION);
-/**
- * This constraint updates the X overshoot property using the difference
- * mPropertyPrePosition.x and mPropertyPosition.x, returning a relative value between 0.0f and 1.0f
- */
-struct OvershootXConstraint
-{
- OvershootXConstraint(float maxOvershoot) : mLastOvershoot(0.0f), mMaxOvershoot(maxOvershoot) {}
+ // Get center-point of the Actor.
+ Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
- float operator()(const float& current,
- const PropertyInput& scrollPrePositionProperty,
- const PropertyInput& scrollPostPositionProperty)
- {
- Vector3 scrollPrePosition = scrollPrePositionProperty.GetVector3();
- Vector3 scrollPostPosition = scrollPostPositionProperty.GetVector3();
- float newOvershoot = scrollPrePosition.x - scrollPostPosition.x;
- return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
+ if(rulerX->IsEnabled())
+ {
+ positionSnap.x = position.x - childPosition.x + size.width * 0.5f;
+ }
+ if(rulerY->IsEnabled())
+ {
+ positionSnap.y = position.y - childPosition.y + size.height * 0.5f;
+ }
+ }
}
- float mLastOvershoot;
- float mMaxOvershoot;
-};
+ Vector2 startPosition = positionSnap;
+ positionSnap.x = -rulerX->Snap(-positionSnap.x, biasX); // NOTE: X & Y rulers think in -ve coordinate system.
+ positionSnap.y = -rulerY->Snap(-positionSnap.y, biasY); // That is scrolling RIGHT (e.g. 100.0, 0.0) means moving LEFT.
-/**
- * This constraint updates the Y overshoot property using the difference
- * mPropertyPrePosition.y and mPropertyPosition.y, returning a relative value between 0.0f and 1.0f
- */
-struct OvershootYConstraint
-{
- OvershootYConstraint(float maxOvershoot) : mLastOvershoot(0.0f), mMaxOvershoot(maxOvershoot) {}
+ Dali::Toolkit::ClampState2D clamped;
+ Vector3 size = scrollView.Self().GetCurrentProperty<Vector3>(Actor::Property::SIZE);
+ Vector2 clampDelta(Vector2::ZERO);
+ ClampPosition(size, rulerX, rulerY, positionSnap, clamped);
- float operator()(const float& current,
- const PropertyInput& scrollPrePositionProperty,
- const PropertyInput& scrollPostPositionProperty)
+ if((rulerX->GetType() == Dali::Toolkit::Ruler::FREE || rulerY->GetType() == Dali::Toolkit::Ruler::FREE) &&
+ isFreeFlick && !scrollView.GetActorAutoSnap())
{
- Vector3 scrollPrePosition = scrollPrePositionProperty.GetVector3();
- Vector3 scrollPostPosition = scrollPostPositionProperty.GetVector3();
- float newOvershoot = scrollPrePosition.y - scrollPostPosition.y;
- return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
- }
-
- float mLastOvershoot;
- float mMaxOvershoot;
-};
+ // Calculate target position based on velocity of flick.
-/**
- * When panning, this constraint updates the X property, otherwise
- * it has no effect on the X property.
- */
-float InternalXConstraint(const float& current,
- const PropertyInput& scrollPosition,
- const PropertyInput& panningProperty)
-{
- return scrollPosition.GetVector3().x;
-}
+ // a = Deceleration (Set to diagonal stage length * friction coefficient)
+ // u = Initial Velocity (Flick velocity)
+ // v = 0 (Final Velocity)
+ // t = Time (Velocity / Deceleration)
+ Vector2 stageSize = Stage::GetCurrent().GetSize();
+ float stageLength = Vector3(stageSize.x, stageSize.y, 0.0f).Length();
+ float a = (stageLength * scrollView.GetFrictionCoefficient());
+ Vector3 u = Vector3(velocity.x, velocity.y, 0.0f) * scrollView.GetFlickSpeedCoefficient();
+ float speed = u.Length();
+ u /= speed;
-/**
- * When panning, this constraint updates the Y property, otherwise
- * it has no effect on the Y property.
- */
-float InternalYConstraint(const float& current,
- const PropertyInput& scrollPosition,
- const PropertyInput& panningProperty)
-{
- return scrollPosition.GetVector3().y;
-}
+ // TODO: Change this to a decay function. (faster you flick, the slower it should be)
+ speed = std::min(speed, stageLength * scrollView.GetMaxFlickSpeed());
+ u *= speed;
+ alphaFunction = ConstantDecelerationAlphaFunction;
-/**
- * Internal Position-Delta Property Constraint.
- *
- * Generates position-delta property based on scroll-position + scroll-offset properties.
- */
-Vector3 InternalPositionDeltaConstraint(const Vector3& current,
- const PropertyInput& scrollPositionProperty,
- const PropertyInput& scrollOffsetProperty)
-{
- const Vector3& scrollPosition = scrollPositionProperty.GetVector3();
- const Vector3& scrollOffset = scrollOffsetProperty.GetVector3();
+ float t = speed / a;
- return scrollPosition + scrollOffset;
-}
+ if(rulerX->IsEnabled() && rulerX->GetType() == Dali::Toolkit::Ruler::FREE)
+ {
+ positionSnap.x += t * u.x * 0.5f;
+ }
-/**
- * Internal Final Position Constraint
- * The position of content is:
- * of scroll-position + f(scroll-overshoot)
- * where f(...) function defines how overshoot
- * should affect final-position.
- */
-struct InternalFinalConstraint
-{
- InternalFinalConstraint(AlphaFunction functionX,
- AlphaFunction functionY)
- : mFunctionX(functionX),
- mFunctionY(functionY)
- {
- }
+ if(rulerY->IsEnabled() && rulerY->GetType() == Dali::Toolkit::Ruler::FREE)
+ {
+ positionSnap.y += t * u.y * 0.5f;
+ }
- Vector3 operator()(const Vector3& current,
- const PropertyInput& scrollPositionProperty,
- const PropertyInput& scrollOvershootXProperty,
- const PropertyInput& scrollOvershootYProperty)
- {
- const float& overshootx = scrollOvershootXProperty.GetFloat();
- const float& overshooty = scrollOvershootYProperty.GetFloat();
- Vector3 offset( mFunctionX(overshootx),
- mFunctionY(overshooty),
- 0.0f);
+ clampDelta = positionSnap;
+ ClampPosition(size, rulerX, rulerY, positionSnap, clamped);
- return scrollPositionProperty.GetVector3() - offset;
- }
+ if((positionSnap - startPosition).LengthSquared() > Math::MACHINE_EPSILON_0)
+ {
+ clampDelta -= positionSnap;
+ clampDelta.x = clampDelta.x > 0.0f ? std::min(clampDelta.x, maxOvershoot.x) : std::max(clampDelta.x, -maxOvershoot.x);
+ clampDelta.y = clampDelta.y > 0.0f ? std::min(clampDelta.y, maxOvershoot.y) : std::max(clampDelta.y, -maxOvershoot.y);
+ }
+ else
+ {
+ clampDelta = Vector2::ZERO;
+ }
- AlphaFunction mFunctionX;
- AlphaFunction mFunctionY;
-};
+ // If Axis is Free and has velocity, then calculate time taken
+ // to reach target based on velocity in axis.
+ if(rulerX->IsEnabled() && rulerX->GetType() == Dali::Toolkit::Ruler::FREE)
+ {
+ float deltaX = fabsf(startPosition.x - positionSnap.x);
+ if(fabsf(u.x) > Math::MACHINE_EPSILON_1)
+ {
+ positionDuration.x = fabsf(deltaX / u.x);
+ }
+ else
+ {
+ positionDuration.x = 0;
+ }
+ }
-BaseHandle Create()
-{
- return Toolkit::ScrollView::New();
-}
+ if(rulerY->IsEnabled() && rulerY->GetType() == Dali::Toolkit::Ruler::FREE)
+ {
+ float deltaY = fabsf(startPosition.y - positionSnap.y);
-TypeRegistration typeRegistration( typeid(Toolkit::ScrollView), typeid(Toolkit::Scrollable), Create );
+ if(fabsf(u.y) > Math::MACHINE_EPSILON_1)
+ {
+ positionDuration.y = fabsf(deltaY / u.y);
+ }
+ else
+ {
+ positionDuration.y = 0;
+ }
+ }
+ }
-SignalConnectorType signalConnector1( typeRegistration, Toolkit::ScrollView::SIGNAL_SNAP_STARTED, &ScrollView::DoConnectSignal );
+ if(scrollView.IsOvershootEnabled())
+ {
+ // Scroll to the end of the overshoot only when overshoot is enabled.
+ positionSnap += clampDelta;
+ }
+}
+} // unnamed namespace
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+namespace
+{
+BaseHandle Create()
+{
+ return Toolkit::ScrollView::New();
}
+// Setup properties, signals and actions using the type-registry.
+DALI_TYPE_REGISTRATION_BEGIN(Toolkit::ScrollView, Toolkit::Scrollable, Create)
+
+DALI_PROPERTY_REGISTRATION(Toolkit, ScrollView, "wrapEnabled", BOOLEAN, WRAP_ENABLED)
+DALI_PROPERTY_REGISTRATION(Toolkit, ScrollView, "panningEnabled", BOOLEAN, PANNING_ENABLED)
+DALI_PROPERTY_REGISTRATION(Toolkit, ScrollView, "axisAutoLockEnabled", BOOLEAN, AXIS_AUTO_LOCK_ENABLED)
+DALI_PROPERTY_REGISTRATION(Toolkit, ScrollView, "wheelScrollDistanceStep", VECTOR2, WHEEL_SCROLL_DISTANCE_STEP)
+DALI_PROPERTY_REGISTRATION(Toolkit, ScrollView, "scrollMode", MAP, SCROLL_MODE)
+
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "scrollPosition", VECTOR2, SCROLL_POSITION)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "scrollPrePosition", VECTOR2, SCROLL_PRE_POSITION)
+DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, ScrollView, "scrollPrePositionX", SCROLL_PRE_POSITION_X, SCROLL_PRE_POSITION, 0)
+DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, ScrollView, "scrollPrePositionY", SCROLL_PRE_POSITION_Y, SCROLL_PRE_POSITION, 1)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "scrollPrePositionMax", VECTOR2, SCROLL_PRE_POSITION_MAX)
+DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, ScrollView, "scrollPrePositionMaxX", SCROLL_PRE_POSITION_MAX_X, SCROLL_PRE_POSITION_MAX, 0)
+DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, ScrollView, "scrollPrePositionMaxY", SCROLL_PRE_POSITION_MAX_Y, SCROLL_PRE_POSITION_MAX, 1)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "overshootX", FLOAT, OVERSHOOT_X)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "overshootY", FLOAT, OVERSHOOT_Y)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "scrollFinal", VECTOR2, SCROLL_FINAL)
+DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, ScrollView, "scrollFinalX", SCROLL_FINAL_X, SCROLL_FINAL, 0)
+DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, ScrollView, "scrollFinalY", SCROLL_FINAL_Y, SCROLL_FINAL, 1)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "wrap", BOOLEAN, WRAP)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "panning", BOOLEAN, PANNING)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "scrolling", BOOLEAN, SCROLLING)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "scrollDomainSize", VECTOR2, SCROLL_DOMAIN_SIZE)
+DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, ScrollView, "scrollDomainSizeX", SCROLL_DOMAIN_SIZE_X, SCROLL_DOMAIN_SIZE, 0)
+DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, ScrollView, "scrollDomainSizeY", SCROLL_DOMAIN_SIZE_Y, SCROLL_DOMAIN_SIZE, 1)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "scrollDomainOffset", VECTOR2, SCROLL_DOMAIN_OFFSET)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "scrollPositionDelta", VECTOR2, SCROLL_POSITION_DELTA)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, ScrollView, "startPagePosition", VECTOR3, START_PAGE_POSITION)
+
+DALI_SIGNAL_REGISTRATION(Toolkit, ScrollView, "valueChanged", SIGNAL_SNAP_STARTED)
+
+DALI_TYPE_REGISTRATION_END()
+
+} // namespace
///////////////////////////////////////////////////////////////////////////////////////////////////
// ScrollView
}
ScrollView::ScrollView()
-: ScrollBase(),
- mInitialized(false),
+: ScrollBase(ControlBehaviour(DISABLE_STYLE_CHANGE_SIGNALS)), // Enable size negotiation
+ mTouchDownTime(0u),
+ mGestureStackDepth(0),
+ mScrollStateFlags(0),
+ mLockAxis(LockPossible),
+ mScrollUpdateDistance(DEFAULT_SCROLL_UPDATE_DISTANCE),
+ mMaxOvershoot(DEFAULT_MAX_OVERSHOOT, DEFAULT_MAX_OVERSHOOT),
+ mUserMaxOvershoot(DEFAULT_MAX_OVERSHOOT, DEFAULT_MAX_OVERSHOOT),
+ mSnapOvershootDuration(DEFAULT_SNAP_OVERSHOOT_DURATION),
+ mSnapOvershootAlphaFunction(AlphaFunction::EASE_OUT),
+ mSnapDuration(DEFAULT_SLOW_SNAP_ANIMATION_DURATION),
+ mSnapAlphaFunction(AlphaFunction::EASE_OUT),
+ mMinFlickDistance(DEFAULT_MIN_FLICK_DISTANCE),
+ mFlickSpeedThreshold(DEFAULT_MIN_FLICK_SPEED_THRESHOLD),
+ mFlickDuration(DEFAULT_FAST_SNAP_ANIMATION_DURATION),
+ mFlickAlphaFunction(AlphaFunction::EASE_OUT),
+ mAxisAutoLockGradient(DEFAULT_AXIS_AUTO_LOCK_GRADIENT),
+ mFrictionCoefficient(DEFAULT_FRICTION_COEFFICIENT),
+ mFlickSpeedCoefficient(DEFAULT_FLICK_SPEED_COEFFICIENT),
+ mMaxFlickSpeed(DEFAULT_MAX_FLICK_SPEED),
+ mWheelScrollDistanceStep(Vector2::ZERO),
+ mInAccessibilityPan(false),
mScrolling(false),
mScrollInterrupted(false),
- mTouchDownTime(0u),
+ mPanning(false),
mSensitive(true),
- mGestureStackDepth(0),
- mRotationDelta(0.0f),
- mScrollPreRotation(0.0f),
- mScrollPostRotation(0.0f),
- mTouchDownReceived(false),
+ mTouchDownTimeoutReached(false),
mActorAutoSnapEnabled(false),
mAutoResizeContainerEnabled(false),
mWrapMode(false),
mAxisAutoLock(false),
- mMinTouchesForPanning(1),
- mMaxTouchesForPanning(1),
- mLockAxis(LockPossible),
- mRefreshIntervalMilliseconds(DEFAULT_REFRESH_INTERVAL_MILLISECONDS),
mAlterChild(false),
- mOvershootDelay(1.0f),
- mMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT),
mDefaultMaxOvershoot(true),
- mSnapOvershootDuration(Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION),
- mSnapOvershootAlphaFunction(AlphaFunctions::EaseOut),
- mSnapDuration(Toolkit::ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION),
- mSnapAlphaFunction(AlphaFunctions::EaseOut),
- mFlickDuration(Toolkit::ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION),
- mFlickAlphaFunction(AlphaFunctions::EaseOut),
- mAxisAutoLockGradient(Toolkit::ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT),
- mFrictionCoefficient(Toolkit::ScrollView::DEFAULT_FRICTION_COEFFICIENT),
- mFlickSpeedCoefficient(Toolkit::ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT),
- mMaxFlickSpeed(Toolkit::ScrollView::DEFAULT_MAX_FLICK_SPEED)
+ mCanScrollHorizontal(true),
+ mCanScrollVertical(true),
+ mTransientScrollBar(true)
{
- SetRequiresMouseWheelEvents(true);
}
void ScrollView::OnInitialize()
{
Actor self = Self();
- self.SetLeaveRequired(true);
// Internal Actor, used to hide actors from enumerations.
// Also actors added to Internal actor appear as overlays e.g. ScrollBar components.
mInternalActor = Actor::New();
- mInternalActor.SetDrawMode(DrawMode::OVERLAY);
self.Add(mInternalActor);
- mInternalActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
- mInternalActor.SetParentOrigin(ParentOrigin::CENTER);
- mInternalActor.SetAnchorPoint(AnchorPoint::CENTER);
- mAlterChild = true;
-
- // Register Scroll Properties.
- RegisterProperties();
+ mInternalActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ mInternalActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ mInternalActor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
- mScrollPostPosition = mScrollPrePosition = Vector3::ZERO;
- mScrollPostScale = mScrollPreScale = Vector3::ONE;
- mScrollPostRotation = mScrollPreRotation = 0.0f;
+ mAlterChild = true;
- mMouseWheelScrollDistanceStep = Stage::GetCurrent().GetSize() * DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION;
+ mScrollPostPosition = mScrollPrePosition = Vector2::ZERO;
- mInitialized = true;
+ mWheelScrollDistanceStep = Stage::GetCurrent().GetSize() * DEFAULT_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION;
mGestureStackDepth = 0;
- EnableGestureDetection( Gesture::Type( Gesture::Pan ) );
-
- // For pan, default to only 1 touch required, ignoring touches outside this range.
- SetTouchesRequiredForPanning(1, 1, false);
+ self.TouchedSignal().Connect(this, &ScrollView::OnTouch);
+ EnableGestureDetection(GestureType::Value(GestureType::PAN));
// By default we'll allow the user to freely drag the scroll view,
// while disabling the other rulers.
RulerPtr ruler = new DefaultRuler();
- RulerPtr rulerDisabled = new DefaultRuler();
- rulerDisabled->Disable();
- mRulerX = ruler;
- mRulerY = ruler;
- mRulerScaleX = rulerDisabled;
- mRulerScaleY = rulerDisabled;
- mRulerRotation = rulerDisabled;
+ mRulerX = ruler;
+ mRulerY = ruler;
- EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator);
+ self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL, mCanScrollVertical);
+ self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_HORIZONTAL, mCanScrollHorizontal);
- Vector3 size = GetControlSize();
- UpdatePropertyDomain(size);
- SetInternalConstraints();
+ ScrollViewPropertyHandler::UpdatePropertyDomain(*this);
+ mConstraints.SetInternalConstraints(*this);
+
+ // Connect wheel event
+ self.WheelEventSignal().Connect(this, &ScrollView::OnWheelEvent);
+
+ DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
+ return std::unique_ptr<Dali::Accessibility::Accessible>(
+ new AccessibleImpl(actor, Dali::Accessibility::Role::SCROLL_PANE));
+ });
}
-void ScrollView::OnControlStageConnection()
+void ScrollView::OnSceneConnection(int depth)
{
- if ( mSensitive )
- {
- SetScrollSensitive( false );
- SetScrollSensitive( true );
- }
- if(IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator))
+ DALI_LOG_SCROLL_STATE("[0x%X]", this);
+
+ if(mSensitive)
{
- // try and make sure property notifications are set
- EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator);
+ SetScrollSensitive(false);
+ SetScrollSensitive(true);
}
-}
-void ScrollView::OnControlStageDisconnection()
-{
- if ( mSnapOvershootAnimation )
+ if(IsOvershootEnabled())
{
- SetOvershootToOrigin();
+ // try and make sure property notifications are set
+ EnableScrollOvershoot(true);
}
- StopAnimation();
-}
-
-ScrollView::~ScrollView()
-{
-}
-
-AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
-{
- return mSnapAlphaFunction;
-}
-
-void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
-{
- mSnapAlphaFunction = alpha;
+ ScrollBase::OnSceneConnection(depth);
}
-AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
+void ScrollView::OnSceneDisconnection()
{
- return mFlickAlphaFunction;
-}
+ DALI_LOG_SCROLL_STATE("[0x%X]", this);
-void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
-{
- mFlickAlphaFunction = alpha;
-}
-
-float ScrollView::GetScrollSnapDuration() const
-{
- return mSnapDuration;
-}
-
-void ScrollView::SetScrollSnapDuration(float time)
-{
- mSnapDuration = time;
-}
+ StopAnimation();
-float ScrollView::GetScrollFlickDuration() const
-{
- return mFlickDuration;
+ ScrollBase::OnSceneDisconnection();
}
-void ScrollView::SetScrollFlickDuration(float time)
+ScrollView::~ScrollView()
{
- mFlickDuration = time;
+ DALI_LOG_SCROLL_STATE("[0x%X]", this);
}
void ScrollView::ApplyEffect(Toolkit::ScrollViewEffect effect)
// Assertion check to ensure effect doesn't already exist in this scrollview
bool effectAlreadyExistsInScrollView(false);
- for (ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
+ for(ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
{
- if(*iter==effect)
+ if(*iter == effect)
{
effectAlreadyExistsInScrollView = true;
break;
GetImpl(effect).Attach(self);
}
-Toolkit::ScrollViewEffect ScrollView::ApplyEffect(Toolkit::ScrollView::PageEffect effect)
-{
- Toolkit::ScrollViewEffect scrollEffect;
- switch(effect)
- {
- case Toolkit::ScrollView::PageEffectNone:
- {
- break;
- }
- case Toolkit::ScrollView::PageEffectOuterCube:
- {
- Toolkit::ScrollViewCustomEffect customEffect;
- scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
- Vector2 pageSize = Stage::GetCurrent().GetSize();
- // set the page translation to the slide off distance, also add an extra value to space the pages, having a smaller spacing on translationOut will allow the spacing to reduce over time
- // the page moving onto screen will start 50.0f further out (1.0f * 50.0f) and the spacing will reduce as its position reaches the centre (0.0f * 50.0f)
- // the page moving off screen will slowly build a spacing from 0.0f to 20.0f
- // the spacing from each page is added together for the final spacing between the two pages.
- customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0) + Vector3(50.0f, 50.0f, 0.0f), Vector3(pageSize.x, pageSize.y, 0) + Vector3(20.0f, 20.0f, 0.0f));
- customEffect.SetSwingAngleOut(ANGLE_CUSTOM_CUBE_SWING.x, Vector3(0.0f, -1.0f, 0.0f));
- customEffect.SetSwingAnchor(AnchorPoint::CENTER, AnchorPoint::CENTER_LEFT);
- customEffect.SetOpacityThreshold(0.7f);
- break;
- }
- case Toolkit::ScrollView::PageEffectDepth:
- {
- Toolkit::ScrollViewCustomEffect customEffect;
- scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
- break;
- }
- case Toolkit::ScrollView::PageEffectInnerCube:
- {
- Toolkit::ScrollViewCustomEffect customEffect;
- scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
- customEffect.SetPageSpacing(Vector2(30.0f, 30.0f));
- customEffect.SetAngledOriginPageRotation(ANGLE_CUBE_PAGE_ROTATE);
- customEffect.SetSwingAngle(ANGLE_CUBE_PAGE_ROTATE.x, Vector3(0,-1,0));
- customEffect.SetOpacityThreshold(0.5f);
- break;
- }
- case Toolkit::ScrollView::PageEffectCarousel:
- {
- Toolkit::ScrollViewCustomEffect customEffect;
- scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
- customEffect.SetPageTranslation(Vector3(0,0,0), Vector3(-30, 0, 0));
- customEffect.SetPageSpacing(Vector2(60.0f, 60.0f));
- customEffect.SetAngledOriginPageRotation(-ANGLE_CUBE_PAGE_ROTATE);
- customEffect.SetOpacityThreshold(0.2f, 0.6f);
- break;
- }
- case Toolkit::ScrollView::PageEffectSpiral:
- {
- Toolkit::ScrollViewCustomEffect customEffect;
- scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
-
- Vector2 pageSize = Stage::GetCurrent().GetSize();
- customEffect.SetSwingAngle(-ANGLE_SPIRAL_SWING_IN.x, Vector3(0.0f, -1.0f, 0.0f), ANGLE_SPIRAL_SWING_OUT.x, Vector3(0.0f, -1.0f, 0.0f));
- //customEffect.SetSwingAngleAlphaFunctionOut(AlphaFunctions::EaseOut);
- customEffect.SetSwingAnchor(AnchorPoint::CENTER_RIGHT);
- customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0) + Vector3(100.0f, 100.0f, 0.0f), Vector3(pageSize.x, pageSize.y, -pageSize.y * 2.0f) * 0.33f);
- //customEffect.SetPageTranslateAlphaFunctionOut(AlphaFunctions::EaseOut);
- customEffect.SetOpacityThreshold(0.75f, 0.6f);
- customEffect.SetOpacityAlphaFunctionIn(AlphaFunctions::EaseInOut);
- break;
- }
- default:
- {
- DALI_ASSERT_DEBUG(0 && "unknown scroll view effect");
- }
- }
- RemoveConstraintsFromChildren();
- if(scrollEffect)
- {
- ApplyEffect(scrollEffect);
- }
- return scrollEffect;
-}
-
void ScrollView::RemoveEffect(Toolkit::ScrollViewEffect effect)
{
Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
// remove effect from effects list
bool effectExistedInScrollView(false);
- for (ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
+ for(ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
{
- if(*iter==effect)
+ if(*iter == effect)
{
mEffects.erase(iter);
effectExistedInScrollView = true;
{
Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
- for (ScrollViewEffectIter effectIter = mEffects.begin(); effectIter != mEffects.end(); ++effectIter)
+ for(ScrollViewEffectIter effectIter = mEffects.begin(); effectIter != mEffects.end(); ++effectIter)
{
Toolkit::ScrollViewEffect effect = *effectIter;
RemoveConstraintsFromBoundActors();
}
-const RulerPtr ScrollView::GetRulerX() const
-{
- return mRulerX;
-}
-
-const RulerPtr ScrollView::GetRulerY() const
-{
- return mRulerY;
-}
-
void ScrollView::SetRulerX(RulerPtr ruler)
{
mRulerX = ruler;
- Vector3 size = GetControlSize();
- UpdatePropertyDomain(size);
- UpdateMainInternalConstraint();
+ ScrollViewPropertyHandler::UpdatePropertyDomain(*this);
+ mConstraints.UpdateMainInternalConstraint(*this);
}
void ScrollView::SetRulerY(RulerPtr ruler)
{
mRulerY = ruler;
- Vector3 size = GetControlSize();
- UpdatePropertyDomain(size);
- UpdateMainInternalConstraint();
-}
-
-void ScrollView::UpdatePropertyDomain(const Vector3& size)
-{
- Vector3 min;
- Vector3 max;
-
- bool canScrollVertical = false;
- bool canScrollHorizontal = false;
- Actor self = Self();
- if(mRulerX->IsEnabled())
- {
- const Toolkit::RulerDomain& rulerDomain = mRulerX->GetDomain();
- min.x = rulerDomain.min;
- max.x = rulerDomain.max;
-
- // make sure new scroll value is within new domain
- float newScroll = min.x;
- int scrollXPropertyIndex = self.GetPropertyIndex(Toolkit::ScrollView::SCROLL_X_PROPERTY_NAME);
- if((fabsf(max.x - min.x) - size.x) > Math::MACHINE_EPSILON_1)
- {
- canScrollHorizontal = true;
- float currentScroll = self.GetProperty<float>(scrollXPropertyIndex);
- newScroll = Clamp(currentScroll, -(max.x - size.x), -min.x);
- }
- self.SetProperty(scrollXPropertyIndex, newScroll);
- }
-
- if(mRulerY->IsEnabled())
- {
- const Toolkit::RulerDomain& rulerDomain = mRulerY->GetDomain();
- min.y = rulerDomain.min;
- max.y = rulerDomain.max;
-
- // make sure new scroll value is within new domain
- float newScroll = min.y;
- int scrollYPropertyIndex = self.GetPropertyIndex(Toolkit::ScrollView::SCROLL_Y_PROPERTY_NAME);
- if((fabsf(max.y - min.y) - size.y) > Math::MACHINE_EPSILON_1)
- {
- canScrollVertical = true;
- float currentScroll = self.GetProperty<float>(scrollYPropertyIndex);
- newScroll = Clamp(currentScroll, -(max.y - size.y), -min.y);
- }
- self.SetProperty(scrollYPropertyIndex, newScroll);
- }
- self.SetProperty(mPropertyCanScrollVertical, canScrollVertical);
- self.SetProperty(mPropertyCanScrollHorizontal, canScrollHorizontal);
-
- self.SetProperty(mPropertyPositionMin, min );
- self.SetProperty(mPropertyPositionMax, max );
-}
-
-void ScrollView::SetRulerScaleX(RulerPtr ruler)
-{
- mRulerScaleX = ruler;
- UpdateMainInternalConstraint();
-}
-
-void ScrollView::SetRulerScaleY(RulerPtr ruler)
-{
- mRulerScaleY = ruler;
- UpdateMainInternalConstraint();
-}
-
-void ScrollView::SetRulerRotation(RulerPtr ruler)
-{
- mRulerRotation = ruler;
- UpdateMainInternalConstraint();
+ ScrollViewPropertyHandler::UpdatePropertyDomain(*this);
+ mConstraints.UpdateMainInternalConstraint(*this);
}
void ScrollView::SetScrollSensitive(bool sensitive)
{
- Actor self = Self();
- PanGestureDetector panGesture( GetPanGestureDetector() );
+ Actor self = Self();
+ PanGestureDetector panGesture(GetPanGestureDetector());
+
+ DALI_LOG_SCROLL_STATE("[0x%X] sensitive: before:[%d] setting[%d]", this, int(mSensitive), int(sensitive));
if((!mSensitive) && (sensitive))
{
}
else if((mSensitive) && (!sensitive))
{
- mSensitive = sensitive;
+ DALI_LOG_SCROLL_STATE("[0x%X] BEFORE: panning:[%d]", this, int(mPanning));
+
+ // while the scroll view is panning, the state needs to be reset.
+ if(mPanning)
+ {
+ PanGesture cancelGesture = DevelPanGesture::New(GestureState::CANCELLED);
+ OnPan(cancelGesture);
+ }
+
panGesture.Detach(self);
+ mSensitive = sensitive;
mGestureStackDepth = 0;
- self.SetProperty(mPropertyPanning, false);
-
- // Remove X & Y position constraints as they are not required when we are not panning.
- self.RemoveConstraint(mScrollMainInternalXConstraint);
- self.RemoveConstraint(mScrollMainInternalYConstraint);
+ DALI_LOG_SCROLL_STATE("[0x%X] AFTER: panning:[%d]", this, int(mPanning));
}
}
void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
{
- mMaxOvershoot.x = overshootX;
- mMaxOvershoot.y = overshootY;
+ mMaxOvershoot.x = overshootX;
+ mMaxOvershoot.y = overshootY;
+ mUserMaxOvershoot = mMaxOvershoot;
mDefaultMaxOvershoot = false;
- UpdateMainInternalConstraint();
-}
-
-void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
-{
- mSnapOvershootAlphaFunction = alpha;
-}
-
-void ScrollView::SetSnapOvershootDuration(float duration)
-{
- mSnapOvershootDuration = duration;
+ mConstraints.UpdateMainInternalConstraint(*this);
}
-void ScrollView::SetTouchesRequiredForPanning(unsigned int minTouches, unsigned int maxTouches, bool endOutside)
+bool ScrollView::GetActorAutoSnap()
{
- PanGestureDetector panGesture( GetPanGestureDetector() );
-
- mMinTouchesForPanning = minTouches;
- mMaxTouchesForPanning = maxTouches;
-
- if(endOutside)
- {
- panGesture.SetMinimumTouchesRequired(minTouches);
- panGesture.SetMaximumTouchesRequired(maxTouches);
- }
- else
- {
- panGesture.SetMinimumTouchesRequired(1);
- panGesture.SetMaximumTouchesRequired(UINT_MAX);
- }
-}
-
-void ScrollView::SetActorAutoSnap(bool enable)
-{
- mActorAutoSnapEnabled = enable;
+ return mActorAutoSnapEnabled;
}
void ScrollView::SetAutoResize(bool enable)
// TODO: This needs a lot of issues to be addressed before working.
}
-bool ScrollView::GetWrapMode() const
-{
- return mWrapMode;
-}
-
void ScrollView::SetWrapMode(bool enable)
{
mWrapMode = enable;
- Self().SetProperty(mPropertyWrap, enable);
-}
-
-int ScrollView::GetRefreshInterval() const
-{
- return mRefreshIntervalMilliseconds;
-}
-
-void ScrollView::SetRefreshInterval(int milliseconds)
-{
- mRefreshIntervalMilliseconds = milliseconds;
-}
-
-bool ScrollView::GetAxisAutoLock() const
-{
- return mAxisAutoLock;
+ Self().SetProperty(Toolkit::ScrollView::Property::WRAP, enable);
}
void ScrollView::SetAxisAutoLock(bool enable)
{
mAxisAutoLock = enable;
- UpdateMainInternalConstraint();
-}
-
-float ScrollView::GetAxisAutoLockGradient() const
-{
- return mAxisAutoLockGradient;
+ mConstraints.UpdateMainInternalConstraint(*this);
}
void ScrollView::SetAxisAutoLockGradient(float gradient)
{
- DALI_ASSERT_DEBUG( gradient >= 0.0f && gradient <= 1.0f );
+ DALI_ASSERT_DEBUG(gradient >= 0.0f && gradient <= 1.0f);
mAxisAutoLockGradient = gradient;
- UpdateMainInternalConstraint();
-}
-
-float ScrollView::GetFrictionCoefficient() const
-{
- return mFrictionCoefficient;
+ mConstraints.UpdateMainInternalConstraint(*this);
}
void ScrollView::SetFrictionCoefficient(float friction)
{
- DALI_ASSERT_DEBUG( friction > 0.0f );
+ DALI_ASSERT_DEBUG(friction > 0.0f);
mFrictionCoefficient = friction;
}
-float ScrollView::GetFlickSpeedCoefficient() const
-{
- return mFlickSpeedCoefficient;
-}
-
-void ScrollView::SetFlickSpeedCoefficient(float speed)
-{
- mFlickSpeedCoefficient = speed;
-}
-
-float ScrollView::GetMaxFlickSpeed() const
-{
- return mMaxFlickSpeed;
-}
-
-void ScrollView::SetMaxFlickSpeed(float speed)
-{
- mMaxFlickSpeed = speed;
-}
-
-void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
-{
- mMouseWheelScrollDistanceStep = step;
-}
-
-Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
-{
- return mMouseWheelScrollDistanceStep;
-}
-
unsigned int ScrollView::GetCurrentPage() const
{
// in case animation is currently taking place.
- Vector3 position = GetPropertyPrePosition();
+ Vector2 position = GetPropertyPosition();
- Actor self = Self();
- unsigned int page = 0;
+ Actor self = Self();
+ unsigned int page = 0;
unsigned int pagesPerVolume = 1;
- unsigned int volume = 0;
+ unsigned int volume = 0;
// if rulerX is enabled, then get page count (columns)
- page = mRulerX->GetPageFromPosition(-position.x, mWrapMode);
- volume = mRulerY->GetPageFromPosition(-position.y, mWrapMode);
+ page = mRulerX->GetPageFromPosition(-position.x, mWrapMode);
+ volume = mRulerY->GetPageFromPosition(-position.y, mWrapMode);
pagesPerVolume = mRulerX->GetTotalPages();
return volume * pagesPerVolume + page;
}
-Vector3 ScrollView::GetCurrentScrollPosition() const
+Vector2 ScrollView::GetCurrentScrollPosition() const
{
- // in case animation is currently taking place.
- return -GetPropertyPrePosition();
+ return -GetPropertyPosition();
}
-Vector3 ScrollView::GetCurrentScrollScale() const
+void ScrollView::TransformTo(const Vector2& position,
+ DirectionBias horizontalBias,
+ DirectionBias verticalBias)
{
- // in case animation is currently taking place.
- return GetPropertyScale();
+ TransformTo(position, mSnapDuration, mSnapAlphaFunction, horizontalBias, verticalBias);
}
-Vector3 ScrollView::GetDomainSize() const
+void ScrollView::TransformTo(const Vector2& position, float duration, AlphaFunction alpha, DirectionBias horizontalBias, DirectionBias verticalBias)
{
- Vector3 size = Self().GetCurrentSize();
-
- const RulerDomain& xDomain = GetRulerX()->GetDomain();
- const RulerDomain& yDomain = GetRulerY()->GetDomain();
-
- Vector3 domainSize = Vector3( xDomain.max - xDomain.min, yDomain.max - yDomain.min, 0.0f ) - size;
- return domainSize;
-}
+ // If this is called while the timer is running, then cancel it
+ StopTouchDownTimer();
-void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation,
- DirectionBias horizontalBias, DirectionBias verticalBias)
-{
- TransformTo(position, scale, rotation, mSnapDuration, horizontalBias, verticalBias);
-}
+ Actor self(Self());
-void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration,
- DirectionBias horizontalBias, DirectionBias verticalBias)
-{
// Guard against destruction during signal emission
// Note that Emit() methods are called indirectly e.g. from within ScrollView::AnimateTo()
- Toolkit::ScrollView handle( GetOwner() );
+ Toolkit::ScrollView handle(GetOwner());
+
+ DALI_LOG_SCROLL_STATE("[0x%X] pos[%.2f,%.2f], duration[%.2f] bias[%d, %d]",
+ this,
+ position.x,
+ position.y,
+ duration,
+ int(horizontalBias),
+ int(verticalBias));
- Vector3 currentScrollPosition = GetCurrentScrollPosition();
- Self().SetProperty( mPropertyScrollStartPagePosition, currentScrollPosition );
+ Vector2 currentScrollPosition = GetCurrentScrollPosition();
+ self.SetProperty(Toolkit::ScrollView::Property::START_PAGE_POSITION, Vector3(currentScrollPosition));
if(mScrolling) // are we interrupting a current scroll?
{
// set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete.
mScrolling = false;
- mScrollCompletedSignalV2.Emit( currentScrollPosition );
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
+ mScrollCompletedSignal.Emit(currentScrollPosition);
}
- Self().SetProperty(mPropertyScrolling, true);
- mScrolling = true;
- mScrollStartedSignalV2.Emit( currentScrollPosition );
- bool animating = AnimateTo(-position,
- Vector3::ONE * duration,
- scale,
- Vector3::ONE * duration,
- rotation,
- duration,
- mSnapAlphaFunction,
- true,
- horizontalBias,
- verticalBias,
- Snap);
-
- if(!animating)
+ if(mPanning) // are we interrupting a current pan?
{
- // if not animating, then this pan has completed right now.
- Self().SetProperty(mPropertyScrolling, false);
- mScrolling = false;
- mScrollCompletedSignalV2.Emit( currentScrollPosition );
- }
-}
-
-void ScrollView::ScrollTo(const Vector3& position)
-{
- ScrollTo(position, mSnapDuration );
-}
-
-void ScrollView::ScrollTo(const Vector3& position, float duration)
-{
- ScrollTo(position, duration, DirectionBiasNone, DirectionBiasNone);
-}
-
-void ScrollView::ScrollTo(const Vector3& position, float duration,
- DirectionBias horizontalBias, DirectionBias verticalBias)
-{
- TransformTo(position, mScrollPostScale, mScrollPostRotation, duration, horizontalBias, verticalBias);
-}
-
-void ScrollView::ScrollTo(unsigned int page)
-{
- ScrollTo(page, mSnapDuration);
-}
-
-void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
-{
- Vector3 position;
- unsigned int volume;
- unsigned int libraries;
-
- // The position to scroll to is continuous and linear
- // unless a domain has been enabled on the X axis.
- // or if WrapMode has been enabled.
- bool carryX = mRulerX->GetDomain().enabled | mWrapMode;
- bool carryY = mRulerY->GetDomain().enabled | mWrapMode;
-
- position.x = mRulerX->GetPositionFromPage(page, volume, carryX);
- position.y = mRulerY->GetPositionFromPage(volume, libraries, carryY);
-
- ScrollTo(position, duration, bias, bias);
-}
-
-void ScrollView::ScrollTo(Actor &actor)
-{
- ScrollTo(actor, mSnapDuration);
-}
-
-void ScrollView::ScrollTo(Actor &actor, float duration)
-{
- DALI_ASSERT_ALWAYS(actor.GetParent() == Self());
-
- Actor self = Self();
- Vector3 size = self.GetCurrentSize();
- Vector3 position = actor.GetCurrentPosition();
- position -= GetPropertyPrePosition();
-
- ScrollTo(Vector3(position.x - size.width * 0.5f, position.y - size.height * 0.5f, 0.0f), duration);
-}
-
-Actor ScrollView::FindClosestActor()
-{
- Actor self = Self();
- Vector3 size = self.GetCurrentSize();
-
- return FindClosestActorToPosition(Vector3(size.width * 0.5f,size.height * 0.5f,0.0f));
-}
-
-Actor ScrollView::FindClosestActorToPosition(const Vector3& position, FindDirection dirX, FindDirection dirY, FindDirection dirZ)
-{
- Actor closestChild;
- float closestDistance2 = 0.0f;
- Vector3 actualPosition = position;
-
- unsigned int numChildren = Self().GetChildCount();
-
- for(unsigned int i = 0; i < numChildren; ++i)
- {
- Actor child = Self().GetChildAt(i);
-
- if(mInternalActor == child) // ignore internal actor.
- {
- continue;
- }
-
- Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
-
- Vector3 delta = childPosition - actualPosition;
-
- // X-axis checking (only find Actors to the [dirX] of actualPosition)
- if(dirX > All) // != All,None
- {
- FindDirection deltaH = delta.x > 0 ? Right : Left;
- if(dirX != deltaH)
- {
- continue;
- }
- }
-
- // Y-axis checking (only find Actors to the [dirY] of actualPosition)
- if(dirY > All) // != All,None
- {
- FindDirection deltaV = delta.y > 0 ? Down : Up;
- if(dirY != deltaV)
- {
- continue;
- }
- }
-
- // Z-axis checking (only find Actors to the [dirZ] of actualPosition)
- if(dirZ > All) // != All,None
- {
- FindDirection deltaV = delta.y > 0 ? In : Out;
- if(dirZ != deltaV)
- {
- continue;
- }
- }
-
- // compare child to closest child in terms of distance.
- float distance2 = 0.0f;
-
- // distance2 = the Square of the relevant dimensions of delta
- if(dirX != None)
- {
- distance2 += delta.x * delta.x;
- }
-
- if(dirY != None)
- {
- distance2 += delta.y * delta.y;
- }
-
- if(dirZ != None)
- {
- distance2 += delta.z * delta.z;
- }
-
- if(closestChild) // Next time.
- {
- if(distance2 < closestDistance2)
- {
- closestChild = child;
- closestDistance2 = distance2;
- }
- }
- else // First time.
- {
- closestChild = child;
- closestDistance2 = distance2;
- }
- }
-
- return closestChild;
-}
-
-bool ScrollView::ScrollToSnapPoint()
-{
- Vector2 stationaryVelocity = Vector2(0.0f, 0.0f);
- return SnapWithVelocity( stationaryVelocity );
-}
-
-void ScrollView::ScaleTo(const Vector3& scale)
-{
- ScaleTo(scale, mSnapDuration);
-}
-
-void ScrollView::ScaleTo(const Vector3& scale, float duration)
-{
- TransformTo(mScrollPostPosition, scale, mScrollPostRotation, duration);
-}
-
-
-// TODO: In situations where axes are different (X snap, Y free)
-// Each axis should really have their own independent animation (time and equation)
-// Consider, X axis snapping to nearest grid point (EaseOut over fixed time)
-// Consider, Y axis simulating physics to arrive at a point (Physics equation over variable time)
-// Currently, the axes have been split however, they both use the same EaseOut equation.
-bool ScrollView::SnapWithVelocity(Vector2 velocity)
-{
- // Animator takes over now, touches are assumed not to interfere.
- // And if touches do interfere, then we'll stop animation, update PrePosition
- // to current mScroll's properties, and then resume.
- // Note: For Flicking this may work a bit different...
-
- float angle = atan2(velocity.y, velocity.x);
- float speed2 = velocity.LengthSquared();
- AlphaFunction alphaFunction = mSnapAlphaFunction;
- Vector3 positionDuration = Vector3::ONE * mSnapDuration;
- Vector3 scaleDuration = Vector3::ONE * mSnapDuration;
- float rotationDuration = mSnapDuration;
- float biasX = 0.5f;
- float biasY = 0.5f;
- FindDirection horizontal = None;
- FindDirection vertical = None;
-
- // orthoAngleRange = Angle tolerance within the Exact N,E,S,W direction
- // that will be accepted as a general N,E,S,W flick direction.
-
- const float orthoAngleRange = FLICK_ORTHO_ANGLE_RANGE * M_PI / 180.0f;
- const float flickSpeedThreshold2 = FLICK_SPEED_THRESHOLD*FLICK_SPEED_THRESHOLD;
-
- // Flick logic X Axis
-
- if(mRulerX->IsEnabled())
- {
- horizontal = All;
-
- if(speed2 > flickSpeedThreshold2) // exceeds flick threshold
- {
- if((angle >= -orthoAngleRange) && (angle < orthoAngleRange)) // Swiping East
- {
- biasX = 0.0f, horizontal = Left;
- }
- else if((angle >= M_PI-orthoAngleRange) || (angle < -M_PI+orthoAngleRange)) // Swiping West
- {
- biasX = 1.0f, horizontal = Right;
- }
- }
- }
-
- // Flick logic Y Axis
-
- if(mRulerY->IsEnabled())
- {
- vertical = All;
+ DALI_LOG_SCROLL_STATE("[0x%X] Interrupting Pan, set to false", this);
+ mPanning = false;
+ mGestureStackDepth = 0;
+ self.SetProperty(Toolkit::ScrollView::Property::PANNING, false);
- if(speed2 > flickSpeedThreshold2) // exceeds flick threshold
+ if(mConstraints.mScrollMainInternalPrePositionConstraint)
{
- if((angle >= M_PI_2-orthoAngleRange) && (angle < M_PI_2+orthoAngleRange)) // Swiping South
- {
- biasY = 0.0f, vertical = Up;
- }
- else if((angle >= -M_PI_2-orthoAngleRange) && (angle < -M_PI_2+orthoAngleRange)) // Swiping North
- {
- biasY = 1.0f, vertical = Down;
- }
+ mConstraints.mScrollMainInternalPrePositionConstraint.Remove();
}
}
- // isFlick: Whether this gesture is a flick or not.
- bool isFlick = (horizontal != All || vertical != All);
- // isFreeFlick: Whether this gesture is a flick under free panning criteria.
- bool isFreeFlick = velocity.LengthSquared() > (FREE_FLICK_SPEED_THRESHOLD*FREE_FLICK_SPEED_THRESHOLD);
-
- if(isFlick || isFreeFlick)
- {
- positionDuration = Vector3::ONE * mFlickDuration;
- alphaFunction = mFlickAlphaFunction;
- }
+ self.SetProperty(Toolkit::ScrollView::Property::SCROLLING, true);
+ mScrolling = true;
- // Position Snap ////////////////////////////////////////////////////////////
- Vector3 positionSnap = mScrollPostPosition;
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignal 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
+ mScrollStartedSignal.Emit(currentScrollPosition);
+ bool animating = AnimateTo(-position,
+ Vector2::ONE * duration,
+ alpha,
+ true,
+ horizontalBias,
+ verticalBias,
+ SNAP);
- if(mActorAutoSnapEnabled)
+ if(!animating)
{
- Vector3 size = Self().GetCurrentSize();
-
- Actor child = FindClosestActorToPosition( Vector3(size.width * 0.5f,size.height * 0.5f,0.0f), horizontal, vertical );
-
- if(!child && isFlick )
- {
- // If we conducted a direction limited search and found no actor, then just snap to the closest actor.
- child = FindClosestActorToPosition( Vector3(size.width * 0.5f,size.height * 0.5f,0.0f) );
- }
-
- if(child)
- {
- Vector3 position = Self().GetProperty<Vector3>(mPropertyPosition);
-
- // Get center-point of the Actor.
- Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
+ // if not animating, then this pan has completed right now.
+ self.SetProperty(Toolkit::ScrollView::Property::SCROLLING, false);
+ mScrolling = false;
- if(mRulerX->IsEnabled())
- {
- positionSnap.x = position.x - childPosition.x + size.width * 0.5f;
- }
- if(mRulerY->IsEnabled())
- {
- positionSnap.y = position.y - childPosition.y + size.height * 0.5f;
- }
+ // If we have no duration, then in the next update frame, we will be at the position specified as we just set.
+ // In this scenario, we cannot return the currentScrollPosition as this is out-of-date and should instead return the requested final position
+ Vector2 completedPosition(currentScrollPosition);
+ if(duration <= Math::MACHINE_EPSILON_10)
+ {
+ completedPosition = position;
}
+
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 2 [%.2f, %.2f]", this, completedPosition.x, completedPosition.y);
+ SetScrollUpdateNotification(false);
+ mScrollCompletedSignal.Emit(completedPosition);
}
+}
- Vector3 startPosition = positionSnap;
- positionSnap.x = -mRulerX->Snap(-positionSnap.x, biasX); // NOTE: X & Y rulers think in -ve coordinate system.
- positionSnap.y = -mRulerY->Snap(-positionSnap.y, biasY); // That is scrolling RIGHT (e.g. 100.0, 0.0) means moving LEFT.
+void ScrollView::ScrollTo(const Vector2& position)
+{
+ ScrollTo(position, mSnapDuration);
+}
- Vector3 clampDelta(Vector3::ZERO);
- ClampPosition(positionSnap);
+void ScrollView::ScrollTo(const Vector2& position, float duration)
+{
+ ScrollTo(position, duration, DIRECTION_BIAS_NONE, DIRECTION_BIAS_NONE);
+}
- if( (mRulerX->GetType() == Ruler::Free || mRulerY->GetType() == Ruler::Free)
- && isFreeFlick && !mActorAutoSnapEnabled)
- {
- // Calculate target position based on velocity of flick.
+void ScrollView::ScrollTo(const Vector2& position, float duration, AlphaFunction alpha)
+{
+ ScrollTo(position, duration, alpha, DIRECTION_BIAS_NONE, DIRECTION_BIAS_NONE);
+}
- // a = Deceleration (Set to diagonal stage length * friction coefficient)
- // u = Initial Velocity (Flick velocity)
- // v = 0 (Final Velocity)
- // t = Time (Velocity / Deceleration)
- Vector2 stageSize = Stage::GetCurrent().GetSize();
- float stageLength = Vector3(stageSize.x, stageSize.y, 0.0f).Length();
- float a = (stageLength * mFrictionCoefficient);
- Vector3 u = Vector3(velocity.x, velocity.y, 0.0f) * mFlickSpeedCoefficient;
- float speed = u.Length();
- u/= speed;
+void ScrollView::ScrollTo(const Vector2& position, float duration, DirectionBias horizontalBias, DirectionBias verticalBias)
+{
+ ScrollTo(position, duration, mSnapAlphaFunction, horizontalBias, verticalBias);
+}
- // TODO: Change this to a decay function. (faster you flick, the slower it should be)
- speed = std::min(speed, stageLength * mMaxFlickSpeed );
- u*= speed;
- alphaFunction = ConstantDecelerationAlphaFunction;
+void ScrollView::ScrollTo(const Vector2& position, float duration, AlphaFunction alpha, DirectionBias horizontalBias, DirectionBias verticalBias)
+{
+ DALI_LOG_SCROLL_STATE("[0x%X] position[%.2f, %.2f] duration[%.2f], bias[%d, %d]", this, position.x, position.y, duration, int(horizontalBias), int(verticalBias));
+ TransformTo(position, duration, alpha, horizontalBias, verticalBias);
+}
- float t = speed / a;
+void ScrollView::ScrollTo(unsigned int page)
+{
+ ScrollTo(page, mSnapDuration);
+}
- if(mRulerX->IsEnabled() && mRulerX->GetType() == Ruler::Free)
- {
- positionSnap.x += t*u.x*0.5f;
- }
+void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
+{
+ Vector2 position;
+ unsigned int volume;
+ unsigned int libraries;
- if(mRulerY->IsEnabled() && mRulerY->GetType() == Ruler::Free)
- {
- positionSnap.y += t*u.y*0.5f;
- }
+ // The position to scroll to is continuous and linear
+ // unless a domain has been enabled on the X axis.
+ // or if WrapMode has been enabled.
+ bool carryX = mRulerX->GetDomain().enabled | mWrapMode;
+ bool carryY = mRulerY->GetDomain().enabled | mWrapMode;
- clampDelta = positionSnap;
- ClampPosition(positionSnap);
- if((positionSnap - startPosition).LengthSquared() > Math::MACHINE_EPSILON_0)
- {
- clampDelta -= positionSnap;
- clampDelta.x = clampDelta.x > 0.0f ? std::min(clampDelta.x, mMaxOvershoot.x) : std::max(clampDelta.x, -mMaxOvershoot.x);
- clampDelta.y = clampDelta.y > 0.0f ? std::min(clampDelta.y, mMaxOvershoot.y) : std::max(clampDelta.y, -mMaxOvershoot.y);
- }
- else
- {
- clampDelta = Vector3::ZERO;
- }
+ position.x = mRulerX->GetPositionFromPage(page, volume, carryX);
+ position.y = mRulerY->GetPositionFromPage(volume, libraries, carryY);
- // If Axis is Free and has velocity, then calculate time taken
- // to reach target based on velocity in axis.
- if(mRulerX->IsEnabled() && mRulerX->GetType() == Ruler::Free)
- {
- float deltaX = fabsf(startPosition.x - positionSnap.x);
+ ScrollTo(position, duration, bias, bias);
+}
- if(fabsf(u.x) > Math::MACHINE_EPSILON_1)
- {
- positionDuration.x = fabsf(deltaX / u.x);
- }
- else
- {
- positionDuration.x = 0;
- }
- }
+void ScrollView::ScrollTo(Actor& actor)
+{
+ ScrollTo(actor, mSnapDuration);
+}
- if(mRulerY->IsEnabled() && mRulerY->GetType() == Ruler::Free)
- {
- float deltaY = fabsf(startPosition.y - positionSnap.y);
+void ScrollView::ScrollTo(Actor& actor, float duration)
+{
+ DALI_ASSERT_ALWAYS(actor.GetParent() == Self());
- if(fabsf(u.y) > Math::MACHINE_EPSILON_1)
- {
- positionDuration.y = fabsf(deltaY / u.y);
- }
- else
- {
- positionDuration.y = 0;
- }
- }
- }
- positionSnap += clampDelta;
+ Actor self = Self();
+ Vector3 size = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE);
+ Vector3 position = actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION);
+ Vector2 prePosition = GetPropertyPrePosition();
+ position.GetVectorXY() -= prePosition;
+
+ ScrollTo(Vector2(position.x - size.width * 0.5f, position.y - size.height * 0.5f), duration);
+}
+
+Actor ScrollView::FindClosestActor()
+{
+ Actor self = Self();
+ Vector3 size = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE);
- // Scale Snap ///////////////////////////////////////////////////////////////
- Vector3 scaleSnap = mScrollPostScale;
+ return FindClosestActorToPosition(Vector3(size.width * 0.5f, size.height * 0.5f, 0.0f));
+}
- scaleSnap.x = mRulerScaleX->Snap(scaleSnap.x);
- scaleSnap.y = mRulerScaleY->Snap(scaleSnap.y);
+Actor ScrollView::FindClosestActorToPosition(const Vector3& position, FindDirection dirX, FindDirection dirY, FindDirection dirZ)
+{
+ return ::FindClosestActorToPosition(Self(), mInternalActor, position, dirX, dirY, dirZ);
+}
- ClampScale(scaleSnap);
+bool ScrollView::ScrollToSnapPoint()
+{
+ DALI_LOG_SCROLL_STATE("[0x%X]", this);
+ Vector2 stationaryVelocity = Vector2(0.0f, 0.0f);
+ return SnapWithVelocity(stationaryVelocity);
+}
- // Rotation Snap ////////////////////////////////////////////////////////////
- float rotationSnap = mScrollPostRotation;
- // TODO: implement rotation snap
+bool ScrollView::SnapWithVelocity(Vector2 velocity)
+{
+ Vector2 positionSnap = mScrollPrePosition;
+ Vector2 positionDuration = Vector2::ONE * mSnapDuration;
+ AlphaFunction alphaFunction = mSnapAlphaFunction;
+ bool isFlick;
+ bool isFreeFlick;
- bool animating = AnimateTo(positionSnap, positionDuration,
- scaleSnap, scaleDuration,
- rotationSnap, rotationDuration,
- alphaFunction, false,
- DirectionBiasNone, DirectionBiasNone,
- isFlick || isFreeFlick ? Flick : Snap);
+ ::SnapWithVelocity(*this, mRulerX, mRulerY, mLockAxis, velocity, mMaxOvershoot, positionSnap, positionDuration, alphaFunction, mInAccessibilityPan, isFlick, isFreeFlick);
- if(animating)
- {
- AnimateOvershootToOrigin(positionDuration.x, positionDuration.y);
- }
+ bool animating = AnimateTo(positionSnap, positionDuration, alphaFunction, false, DIRECTION_BIAS_NONE, DIRECTION_BIAS_NONE, isFlick || isFreeFlick ? FLICK : SNAP);
return animating;
}
void ScrollView::StopAnimation(void)
{
// Clear Snap animation if exists.
- if(mSnapAnimation)
- {
- mSnapAnimation.Stop();
- mSnapAnimation.FinishedSignal().Disconnect(this, &ScrollView::OnSnapAnimationFinished);
- mSnapAnimation.Clear();
- mSnapAnimation = NULL;
- }
- if(mSnapXAnimation)
- {
- mSnapXAnimation.Stop();
- mSnapXAnimation.FinishedSignal().Disconnect(this, &ScrollView::OnSnapXAnimationFinished);
- mSnapXAnimation.Clear();
- mSnapXAnimation = NULL;
- }
- if(mSnapYAnimation)
- {
- mSnapYAnimation.Stop();
- mSnapYAnimation.FinishedSignal().Disconnect(this, &ScrollView::OnSnapYAnimationFinished);
- mSnapYAnimation.Clear();
- mSnapYAnimation = NULL;
- }
- if(mSnapOvershootAnimation)
+ StopAnimation(mInternalXAnimation);
+ StopAnimation(mInternalYAnimation);
+ mScrollStateFlags = 0;
+ // remove scroll animation flags
+ HandleStoppedAnimation();
+}
+
+void ScrollView::StopAnimation(Animation& animation)
+{
+ if(animation)
{
- mSnapOvershootAnimation.FinishedSignal().Disconnect(this, &ScrollView::OnSnapOvershootAnimationFinished);
- mSnapOvershootAnimation.Stop();
- mSnapOvershootAnimation.Clear();
- mSnapOvershootAnimation = NULL;
+ animation.Stop();
+ animation.Reset();
}
- HandleStoppedAnimation();
}
-bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDuration,
- const Vector3& scale, const Vector3& scaleDuration,
- float rotation, float rotationDuration,
- AlphaFunction alpha, bool findShortcuts,
- DirectionBias horizontalBias, DirectionBias verticalBias,
- SnapType snapType)
+bool ScrollView::AnimateTo(const Vector2& position, const Vector2& positionDuration, AlphaFunction alpha, bool findShortcuts, DirectionBias horizontalBias, DirectionBias verticalBias, SnapType snapType)
{
// Here we perform an animation on a number of properties (depending on which have changed)
// The animation is applied to all ScrollBases
- Actor self = Self();
- bool startAnimation = false;
- Vector3 positionTransformed = position;
- float totalDuration = 0.0f;
+ Actor self = Self();
+ mScrollTargetPosition = position;
+ float totalDuration = 0.0f;
- bool positionChanged = (positionTransformed != mScrollPostPosition);
- bool scaleChanged = (scale != mScrollPostScale);
- bool rotationChanged = fabsf(rotation - mScrollPostRotation) > Math::MACHINE_EPSILON_0;
+ bool positionChanged = (mScrollTargetPosition != mScrollPostPosition);
if(positionChanged)
{
totalDuration = std::max(totalDuration, positionDuration.x);
totalDuration = std::max(totalDuration, positionDuration.y);
}
-
- if(scaleChanged)
+ else
{
- totalDuration = std::max(totalDuration, scaleDuration.x);
- totalDuration = std::max(totalDuration, scaleDuration.y);
+ // try to animate for a frame, on some occasions update will be changing scroll value while event side thinks it hasnt changed
+ totalDuration = 0.01f;
+ positionChanged = true;
}
- if(rotationChanged)
- {
- totalDuration = std::max(totalDuration, rotationDuration);
- }
+ StopAnimation();
- if(totalDuration > Math::MACHINE_EPSILON_1)
+ // Position Delta ///////////////////////////////////////////////////////
+ if(positionChanged)
{
- StopAnimation();
- mSnapAnimation = Animation::New(totalDuration);
- mSnapAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapAnimationFinished);
- mSnapXAnimation = Animation::New(positionDuration.x);
- mSnapXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapXAnimationFinished);
- mSnapYAnimation = Animation::New(positionDuration.y);
- mSnapYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapYAnimationFinished);
- startAnimation = true;
-
- // Position Delta ///////////////////////////////////////////////////////
- if(positionChanged)
- {
- if(mWrapMode && findShortcuts)
- {
- // In Wrap Mode, the shortest distance is a little less intuitive...
- const RulerDomain rulerDomainX = mRulerX->GetDomain();
- const RulerDomain rulerDomainY = mRulerY->GetDomain();
-
- if(mRulerX->IsEnabled())
- {
- float dir = VectorInDomain(-mScrollPostPosition.x, -positionTransformed.x, rulerDomainX.min, rulerDomainX.max, horizontalBias);
- positionTransformed.x = mScrollPostPosition.x + -dir;
- }
+ mConstraints.UpdateMainInternalConstraint(*this);
+ if(mWrapMode && findShortcuts)
+ {
+ // In Wrap Mode, the shortest distance is a little less intuitive...
+ const RulerDomain rulerDomainX = mRulerX->GetDomain();
+ const RulerDomain rulerDomainY = mRulerY->GetDomain();
- if(mRulerY->IsEnabled())
- {
- float dir = VectorInDomain(-mScrollPostPosition.y, -positionTransformed.y, rulerDomainY.min, rulerDomainY.max, verticalBias);
- positionTransformed.y = mScrollPostPosition.y + -dir;
- }
+ if(mRulerX->IsEnabled())
+ {
+ float dir = VectorInDomain(-mScrollPrePosition.x, -mScrollTargetPosition.x, rulerDomainX.min, rulerDomainX.max, horizontalBias);
+ mScrollTargetPosition.x = mScrollPrePosition.x + -dir;
}
- // note we have two separate animations for X & Y, this deals with sliding diagonally and hitting
- // a horizonal/vertical wall.delay
- mSnapXAnimation.AnimateTo( Property(self, mPropertyX), positionTransformed.x, alpha, TimePeriod(0.0f, positionDuration.x));
- mSnapYAnimation.AnimateTo( Property(self, mPropertyY), positionTransformed.y, alpha, TimePeriod(0.0f, positionDuration.y));
- }
-
- // Scale Delta ///////////////////////////////////////////////////////
- if(scaleChanged)
- {
- // TODO: for non-uniform scaling to different bounds e.g. scaling a square to a 4:3 aspect ratio screen with a velocity
- // the height will hit first, and then the width, so that would require two different animation times just like position.
- mSnapAnimation.AnimateTo( Property(self, mPropertyScale), scale, alpha, TimePeriod(0.0f, scaleDuration.x));
+ if(mRulerY->IsEnabled())
+ {
+ float dir = VectorInDomain(-mScrollPrePosition.y, -mScrollTargetPosition.y, rulerDomainY.min, rulerDomainY.max, verticalBias);
+ mScrollTargetPosition.y = mScrollPrePosition.y + -dir;
+ }
}
- mSnapAnimation.AnimateTo( Property(self, mPropertyTime), totalDuration, AlphaFunctions::Linear );
+ // note we have two separate animations for X & Y, this deals with sliding diagonally and hitting
+ // a horizonal/vertical wall.delay
+ AnimateInternalXTo(mScrollTargetPosition.x, positionDuration.x, alpha);
+ AnimateInternalYTo(mScrollTargetPosition.y, positionDuration.y, alpha);
- mSnapAnimation.Play();
- mSnapXAnimation.Play();
- mSnapYAnimation.Play();
- StartRefreshTimer();
- } // end if(totalDuration > Math::MACHINE_EPSILON_1)
- else // totalDuration == 0
- {
- // instantly set transform.
- if(positionChanged)
+ if(!(mScrollStateFlags & SCROLL_ANIMATION_FLAGS))
{
- self.SetProperty(mPropertyX, positionTransformed.x);
- self.SetProperty(mPropertyY, positionTransformed.y);
-
- mScrollPrePosition = mScrollPostPosition = positionTransformed;
+ DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollTargetPosition.x, mScrollTargetPosition.y);
+ self.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollTargetPosition);
+ mScrollPrePosition = mScrollTargetPosition;
+ mScrollPostPosition = mScrollTargetPosition;
+ WrapPosition(mScrollPostPosition);
}
- if(scaleChanged)
- {
- self.SetProperty(mPropertyScale, scale);
-
- mScrollPreScale = mScrollPostScale = scale;
- }
+ DALI_LOG_SCROLL_STATE("[0x%X] position-changed, mScrollTargetPosition[%.2f, %.2f], mScrollPrePosition[%.2f, %.2f], mScrollPostPosition[%.2f, %.2f]", this, mScrollTargetPosition.x, mScrollTargetPosition.y, mScrollPrePosition.x, mScrollPrePosition.y, mScrollPostPosition.x, mScrollPostPosition.y);
+ DALI_LOG_SCROLL_STATE("[0x%X] SCROLL_PRE_POSITION[%.2f, %.2f], SCROLL_POSITION[%.2f, %.2f]", this, self.GetCurrentProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get<Vector2>().x, self.GetCurrentProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get<Vector2>().y, self.GetCurrentProperty(Toolkit::ScrollView::Property::SCROLL_POSITION).Get<Vector2>().x, self.GetCurrentProperty(Toolkit::ScrollView::Property::SCROLL_POSITION).Get<Vector2>().y);
}
+ SetScrollUpdateNotification(true);
+
// Always send a snap event when AnimateTo is called.
Toolkit::ScrollView::SnapEvent snapEvent;
- snapEvent.type = snapType;
- snapEvent.position = positionTransformed;
- snapEvent.scale = scale;
- snapEvent.rotation = rotation;
+ snapEvent.type = snapType;
+ snapEvent.position = -mScrollTargetPosition;
snapEvent.duration = totalDuration;
- mSnapStartedSignalV2.Emit( snapEvent );
+ DALI_LOG_SCROLL_STATE("[0x%X] mSnapStartedSignal [%.2f, %.2f]", this, snapEvent.position.x, snapEvent.position.y);
+ mSnapStartedSignal.Emit(snapEvent);
- return startAnimation;
+ return (mScrollStateFlags & SCROLL_ANIMATION_FLAGS) != 0;
}
-void ScrollView::SetOvershootEnabled(bool enabled)
+void ScrollView::EnableScrollOvershoot(bool enable)
{
- if(enabled && !mOvershootIndicator)
+ if(enable)
+ {
+ if(!mOvershootIndicator)
+ {
+ mOvershootIndicator = ScrollOvershootIndicator::New();
+ }
+
+ mOvershootIndicator->AttachToScrollable(*this);
+ }
+ else
{
- mOvershootIndicator = ScrollOvershootIndicator::New(*this);
+ mMaxOvershoot = mUserMaxOvershoot;
+
+ if(mOvershootIndicator)
+ {
+ mOvershootIndicator->DetachFromScrollable(*this);
+ }
}
- mOvershootIndicator->Enable(enabled);
+
+ mConstraints.UpdateMainInternalConstraint(*this);
}
void ScrollView::AddOverlay(Actor actor)
{
- mInternalActor.Add( actor );
+ actor.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
+ mInternalActor.Add(actor);
}
void ScrollView::RemoveOverlay(Actor actor)
{
- mInternalActor.Remove( actor );
+ mInternalActor.Remove(actor);
+}
+
+void ScrollView::SetOvershootSize(const Vector2& size)
+{
+ mOvershootSize = size;
+ if(IsOvershootEnabled() && mOvershootIndicator)
+ {
+ mOvershootIndicator->AttachToScrollable(*this);
+ }
+}
+
+void ScrollView::SetOvershootEffectColor(const Vector4& color)
+{
+ mOvershootEffectColor = color;
+ if(mOvershootIndicator)
+ {
+ mOvershootIndicator->SetOvershootEffectColor(color);
+ }
}
-void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
+void ScrollView::SetScrollingDirection(Radian direction, Radian threshold)
{
- PanGestureDetector panGesture( GetPanGestureDetector() );
+ PanGestureDetector panGesture(GetPanGestureDetector());
// First remove just in case we have some set, then add.
- panGesture.RemoveDirection( direction );
- panGesture.AddDirection( direction, threshold );
+ panGesture.RemoveDirection(direction);
+ panGesture.AddDirection(direction, threshold);
}
-void ScrollView::RemoveScrollingDirection( Radian direction )
+void ScrollView::RemoveScrollingDirection(Radian direction)
{
- PanGestureDetector panGesture( GetPanGestureDetector() );
- panGesture.RemoveDirection( direction );
+ PanGestureDetector panGesture(GetPanGestureDetector());
+ panGesture.RemoveDirection(direction);
}
-Toolkit::ScrollView::SnapStartedSignalV2& ScrollView::SnapStartedSignal()
+Toolkit::ScrollView::SnapStartedSignalType& ScrollView::SnapStartedSignal()
{
- return mSnapStartedSignalV2;
+ return mSnapStartedSignal;
+}
+
+bool ScrollView::AccessibleImpl::ScrollToChild(Actor child)
+{
+ auto scrollView = Dali::Toolkit::ScrollView::DownCast(Self());
+ if(Toolkit::GetImpl(scrollView).FindClosestActor() == child)
+ {
+ return false;
+ }
+
+ // FIXME: ScrollTo does not work (snaps back to original position)
+ scrollView.ScrollTo(child, scrollView.GetScrollFlickDuration());
+ return true;
}
void ScrollView::FindAndUnbindActor(Actor child)
UnbindActor(child);
}
-Vector3 ScrollView::GetPropertyPrePosition() const
+Vector2 ScrollView::GetPropertyPrePosition() const
{
- Vector3 position(Self().GetProperty<float>(mPropertyX), Self().GetProperty<float>(mPropertyY), 0.0f);
+ Vector2 position = Self().GetCurrentProperty<Vector2>(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION);
WrapPosition(position);
-
return position;
}
-Vector3 ScrollView::GetPropertyPosition() const
+Vector2 ScrollView::GetPropertyPosition() const
{
- Vector3 position = Self().GetProperty<Vector3>(mPropertyPosition);
+ Vector2 position = Self().GetCurrentProperty<Vector2>(Toolkit::ScrollView::Property::SCROLL_POSITION);
WrapPosition(position);
return position;
}
-Vector3 ScrollView::GetPropertyScale() const
-{
- return Self().GetProperty<Vector3>(mPropertyScale);
-}
-
void ScrollView::HandleStoppedAnimation()
{
- // Animation has stopped, so stop sending the scroll-update signal.
- CancelRefreshTimer();
-
- // cement transform now, and allow interactivity to resume.
- mScrollPostPosition = GetPropertyPosition();
-
- mScrollPostScale = GetPropertyScale();
-
- // Update Actor position with this wrapped value.
-
- Self().SetProperty(mPropertyX, mScrollPostPosition.x);
- Self().SetProperty(mPropertyY, mScrollPostPosition.y);
- // TODO Rotation
-
- mScrollPrePosition = mScrollPostPosition;
- mScrollPreScale = mScrollPostScale;
- mScrollPreRotation = mScrollPostRotation;
+ SetScrollUpdateNotification(false);
}
void ScrollView::HandleSnapAnimationFinished()
{
// Emit Signal that scrolling has completed.
mScrolling = false;
- Self().SetProperty(mPropertyScrolling, false);
+ Actor self = Self();
+ self.SetProperty(Toolkit::ScrollView::Property::SCROLLING, false);
- Vector3 deltaPosition(Self().GetProperty<float>(mPropertyX),
- Self().GetProperty<float>(mPropertyY),
- 0.0f);
+ Vector2 deltaPosition(mScrollPrePosition);
- Vector3 currentScrollPosition = GetCurrentScrollPosition();
- mScrollCompletedSignalV2.Emit( currentScrollPosition );
+ UpdateLocalScrollProperties();
+ WrapPosition(mScrollPrePosition);
+ DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y);
+ self.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPrePosition);
+
+ Vector2 currentScrollPosition = GetCurrentScrollPosition();
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 3 current[%.2f, %.2f], mScrollTargetPosition[%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y, -mScrollTargetPosition.x, -mScrollTargetPosition.y);
+ mScrollCompletedSignal.Emit(currentScrollPosition);
mDomainOffset += deltaPosition - mScrollPostPosition;
- Self().SetProperty(mPropertyDomainOffset, mDomainOffset);
+ self.SetProperty(Toolkit::ScrollView::Property::SCROLL_DOMAIN_OFFSET, mDomainOffset);
HandleStoppedAnimation();
}
-bool ScrollView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
+void ScrollView::SetScrollUpdateNotification(bool enabled)
+{
+ Actor self = Self();
+ if(mScrollXUpdateNotification)
+ {
+ // disconnect now to avoid a notification before removed from update thread
+ mScrollXUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
+ self.RemovePropertyNotification(mScrollXUpdateNotification);
+ mScrollXUpdateNotification.Reset();
+ }
+ if(enabled && !mScrollUpdatedSignal.Empty())
+ {
+ // Only set up the notification when the application has connected to the updated signal
+ mScrollXUpdateNotification = self.AddPropertyNotification(Toolkit::ScrollView::Property::SCROLL_POSITION, 0, StepCondition(mScrollUpdateDistance, 0.0f));
+ mScrollXUpdateNotification.NotifySignal().Connect(this, &ScrollView::OnScrollUpdateNotification);
+ }
+ if(mScrollYUpdateNotification)
+ {
+ // disconnect now to avoid a notification before removed from update thread
+ mScrollYUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
+ self.RemovePropertyNotification(mScrollYUpdateNotification);
+ mScrollYUpdateNotification.Reset();
+ }
+ if(enabled && !mScrollUpdatedSignal.Empty())
+ {
+ // Only set up the notification when the application has connected to the updated signal
+ mScrollYUpdateNotification = self.AddPropertyNotification(Toolkit::ScrollView::Property::SCROLL_POSITION, 1, StepCondition(mScrollUpdateDistance, 0.0f));
+ mScrollYUpdateNotification.NotifySignal().Connect(this, &ScrollView::OnScrollUpdateNotification);
+ }
+}
+
+void ScrollView::OnScrollUpdateNotification(Dali::PropertyNotification& source)
+{
+ // Guard against destruction during signal emission
+ Toolkit::ScrollView handle(GetOwner());
+
+ Vector2 currentScrollPosition = GetCurrentScrollPosition();
+ mScrollUpdatedSignal.Emit(currentScrollPosition);
+}
+
+bool ScrollView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
{
- Dali::BaseHandle handle( object );
+ Dali::BaseHandle handle(object);
- bool connected( true );
- Toolkit::ScrollView view = Toolkit::ScrollView::DownCast( handle );
+ bool connected(true);
+ Toolkit::ScrollView view = Toolkit::ScrollView::DownCast(handle);
- if( Toolkit::ScrollView::SIGNAL_SNAP_STARTED == signalName )
+ if(0 == strcmp(signalName.c_str(), SIGNAL_SNAP_STARTED))
{
- view.SnapStartedSignal().Connect( tracker, functor );
+ view.SnapStartedSignal().Connect(tracker, functor);
}
else
{
void ScrollView::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
{
// need to update domain properties for new size
- UpdatePropertyDomain(targetSize);
+ ScrollViewPropertyHandler::UpdatePropertyDomain(*this);
}
-void ScrollView::OnControlSizeSet( const Vector3& size )
+void ScrollView::OnSizeSet(const Vector3& size)
{
// need to update domain properties for new size
- if( mDefaultMaxOvershoot )
+ if(mDefaultMaxOvershoot)
{
- mMaxOvershoot.x = size.x * 0.5f;
- mMaxOvershoot.y = size.y * 0.5f;
+ mUserMaxOvershoot.x = size.x * 0.5f;
+ mUserMaxOvershoot.y = size.y * 0.5f;
+ if(!IsOvershootEnabled())
+ {
+ mMaxOvershoot = mUserMaxOvershoot;
+ }
}
- UpdatePropertyDomain(size);
- UpdateMainInternalConstraint();
- if( IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
+ ScrollViewPropertyHandler::UpdatePropertyDomain(*this);
+ mConstraints.UpdateMainInternalConstraint(*this);
+ if(IsOvershootEnabled())
{
mOvershootIndicator->Reset();
}
+
+ ScrollBase::OnSizeSet(size);
}
void ScrollView::OnChildAdd(Actor& child)
{
- if(mAlterChild)
+ ScrollBase::OnChildAdd(child);
+
+ Dali::Toolkit::ScrollBar scrollBar = Dali::Toolkit::ScrollBar::DownCast(child);
+ if(scrollBar)
+ {
+ mScrollBar = scrollBar;
+ scrollBar.SetProperty(Dali::Actor::Property::NAME, "ScrollBar");
+
+ mInternalActor.Add(scrollBar);
+ if(scrollBar.GetScrollDirection() == Toolkit::ScrollBar::HORIZONTAL)
+ {
+ scrollBar.SetScrollPropertySource(Self(),
+ Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_X,
+ Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_X,
+ Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_X,
+ Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_X);
+ }
+ else
+ {
+ scrollBar.SetScrollPropertySource(Self(),
+ Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_Y,
+ Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_Y,
+ Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_Y,
+ Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_Y);
+ }
+
+ if(mTransientScrollBar)
+ {
+ // Show the scroll-indicator for a brief period
+ Property::Map emptyMap;
+ scrollBar.DoAction("ShowTransientIndicator", emptyMap);
+ }
+ }
+ else if(mAlterChild)
{
BindActor(child);
}
{
// TODO: Actor needs a RemoveConstraint method to take out an individual constraint.
UnbindActor(child);
+
+ ScrollBase::OnChildRemove(child);
+}
+
+void ScrollView::StartTouchDownTimer()
+{
+ if(!mTouchDownTimer)
+ {
+ mTouchDownTimer = Timer::New(TOUCH_DOWN_TIMER_INTERVAL);
+ mTouchDownTimer.TickSignal().Connect(this, &ScrollView::OnTouchDownTimeout);
+ }
+
+ mTouchDownTimer.Start();
+}
+
+void ScrollView::StopTouchDownTimer()
+{
+ if(mTouchDownTimer)
+ {
+ mTouchDownTimer.Stop();
+ }
+}
+
+bool ScrollView::OnTouchDownTimeout()
+{
+ DALI_LOG_SCROLL_STATE("[0x%X]", this);
+
+ mTouchDownTimeoutReached = true;
+
+ unsigned int currentScrollStateFlags(mScrollStateFlags); // Cleared in StopAnimation so keep local copy for comparison
+ if(currentScrollStateFlags & (SCROLL_ANIMATION_FLAGS | SNAP_ANIMATION_FLAGS))
+ {
+ DALI_LOG_SCROLL_STATE("[0x%X] Scrolling Or snapping flags set, stopping animation", this);
+
+ StopAnimation();
+ if(currentScrollStateFlags & SCROLL_ANIMATION_FLAGS)
+ {
+ DALI_LOG_SCROLL_STATE("[0x%X] Scrolling flags set, emitting signal", this);
+
+ mScrollInterrupted = true;
+ // reset domain offset as scrolling from original plane.
+ mDomainOffset = Vector2::ZERO;
+ Self().SetProperty(Toolkit::ScrollView::Property::SCROLL_DOMAIN_OFFSET, Vector2::ZERO);
+
+ UpdateLocalScrollProperties();
+ Vector2 currentScrollPosition = GetCurrentScrollPosition();
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 4 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
+ mScrollCompletedSignal.Emit(currentScrollPosition);
+ }
+ }
+
+ return false;
}
-bool ScrollView::OnTouchEvent(const TouchEvent& event)
+bool ScrollView::OnTouch(Actor actor, const TouchEvent& touch)
{
if(!mSensitive)
{
+ DALI_LOG_SCROLL_STATE("[0x%X], Not Sensitive, ignoring", this);
+
// Ignore this touch event, if scrollview is insensitive.
return false;
}
// Ignore events with multiple-touch points
- if (event.GetPointCount() != 1)
+ if(touch.GetPointCount() != 1)
{
+ DALI_LOG_SCROLL_STATE("[0x%X], multiple touch, ignoring", this);
+
return false;
}
- if (event.GetPoint(0).state == TouchPoint::Down)
+ const PointState::Type pointState = touch.GetState(0);
+ if(pointState == PointState::DOWN)
{
- mTouchDownTime = event.time;
- mTouchDownReceived = true;
- mTouchDownPosition = event.GetPoint(0).local;
-
- if( mSnapAnimation || mSnapXAnimation || mSnapYAnimation || mSnapOvershootAnimation )
- {
- mScrollInterrupted = true;
- StopAnimation();
- }
+ DALI_LOG_SCROLL_STATE("[0x%X] Down", this);
- if(mScrolling) // are we interrupting a current scroll?
+ if(mGestureStackDepth == 0)
{
- // reset domain offset as scrolling from original plane.
- mDomainOffset = Vector3::ZERO;
- Self().SetProperty(mPropertyDomainOffset, Vector3::ZERO);
+ mTouchDownTime = touch.GetTime();
- mScrolling = false;
- Vector3 currentScrollPosition = GetCurrentScrollPosition();
- mScrollCompletedSignalV2.Emit( currentScrollPosition );
+ // This allows time for a pan-gesture to start, to avoid breaking snap-animation behavior with fast flicks.
+ // If touch-down does not become a pan (after timeout interval), then snap-animation can be interrupted.
+ mTouchDownTimeoutReached = false;
+ mScrollInterrupted = false;
+ StartTouchDownTimer();
}
}
- else if(event.GetPoint(0).state == TouchPoint::Up)
+ else if((pointState == PointState::UP) ||
+ ((pointState == PointState::INTERRUPTED) && (touch.GetHitActor(0) == Self())))
{
+ DALI_LOG_SCROLL_STATE("[0x%X] %s", this, ((pointState == PointState::UP) ? "Up" : "Interrupted"));
+
+ StopTouchDownTimer();
+
// if the user touches and releases without enough movement to go
// into a gesture state, then we should snap to nearest point.
// otherwise our scroll could be stopped (interrupted) half way through an animation.
- if(mGestureStackDepth==0 && mTouchDownReceived)
+ if(mGestureStackDepth == 0 && mTouchDownTimeoutReached)
{
- unsigned timeDelta( event.time - mTouchDownTime );
- if ( timeDelta >= MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET )
+ if((pointState == PointState::INTERRUPTED) ||
+ ((touch.GetTime() - mTouchDownTime) >= MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET))
{
// Reset the velocity only if down was received a while ago
- mLastVelocity = Vector2( 0.0f, 0.0f );
- }
- else
- {
- Vector2 positionDelta( mTouchDownPosition - event.GetPoint(0).local );
- mLastVelocity = positionDelta / timeDelta;
+ mLastVelocity = Vector2(0.0f, 0.0f);
}
+ UpdateLocalScrollProperties();
// Only finish the transform if scrolling was interrupted on down or if we are scrolling
- if ( mSnapAnimation || mSnapXAnimation || mSnapYAnimation || mSnapOvershootAnimation || mScrollInterrupted || mScrolling )
+ if(mScrollInterrupted || mScrolling)
{
+ DALI_LOG_SCROLL_STATE("[0x%X] Calling FinishTransform", this);
+
FinishTransform();
}
}
- mTouchDownReceived = false;
- mScrollInterrupted = false;
+ mTouchDownTimeoutReached = false;
+ mScrollInterrupted = false;
}
- return true; // consume since we're potentially scrolling
+ return false;
}
-bool ScrollView::OnMouseWheelEvent(const MouseWheelEvent& event)
+bool ScrollView::OnWheelEvent(Actor actor, const WheelEvent& event)
{
if(!mSensitive)
{
- // Ignore this mouse wheel event, if scrollview is insensitive.
+ // Ignore this wheel event, if scrollview is insensitive.
return false;
}
- Vector3 targetScrollPosition = GetPropertyPosition();
+ Vector2 targetScrollPosition = GetPropertyPosition();
if(mRulerX->IsEnabled() && !mRulerY->IsEnabled())
{
// If only the ruler in the X axis is enabled, scroll in the X axis.
- if(mRulerX->GetType() == Ruler::Free)
+ if(mRulerX->GetType() == Ruler::FREE)
{
// Free panning mode
- targetScrollPosition.x -= event.z * mMouseWheelScrollDistanceStep.x;
+ targetScrollPosition.x += event.GetDelta() * mWheelScrollDistanceStep.x;
ClampPosition(targetScrollPosition);
ScrollTo(-targetScrollPosition);
}
else if(!mScrolling)
{
// Snap mode, only respond to the event when the previous snap animation is finished.
- ScrollTo(GetCurrentPage() + event.z);
+ ScrollTo(GetCurrentPage() - event.GetDelta());
}
}
else
{
// If the ruler in the Y axis is enabled, scroll in the Y axis.
- if(mRulerY->GetType() == Ruler::Free)
+ if(mRulerY->GetType() == Ruler::FREE)
{
// Free panning mode
- targetScrollPosition.y -= event.z * mMouseWheelScrollDistanceStep.y;
+ targetScrollPosition.y += event.GetDelta() * mWheelScrollDistanceStep.y;
ClampPosition(targetScrollPosition);
ScrollTo(-targetScrollPosition);
}
else if(!mScrolling)
{
// Snap mode, only respond to the event when the previous snap animation is finished.
- ScrollTo(GetCurrentPage() + event.z * mRulerX->GetTotalPages());
+ ScrollTo(GetCurrentPage() - event.GetDelta() * mRulerX->GetTotalPages());
}
}
return true;
}
-void ScrollView::OnSnapAnimationFinished( Animation& source )
+void ScrollView::ResetScrolling()
{
- mSnapAnimation.FinishedSignal().Disconnect( this, &ScrollView::OnSnapAnimationFinished );
- mSnapAnimation = NULL;
+ Actor self = Self();
+ self.GetCurrentProperty(Toolkit::ScrollView::Property::SCROLL_POSITION).Get(mScrollPostPosition);
+ mScrollPrePosition = mScrollPostPosition;
+ DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPostPosition.x, mScrollPostPosition.y);
+ self.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPostPosition);
}
-void ScrollView::OnSnapXAnimationFinished( Animation& source )
+void ScrollView::UpdateLocalScrollProperties()
{
- // Guard against destruction during signal emission
- // Note that ScrollCompletedSignal is emitted from HandleSnapAnimationFinished()
- Toolkit::ScrollView handle( GetOwner() );
+ Actor self = Self();
+ self.GetCurrentProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get(mScrollPrePosition);
+ self.GetCurrentProperty(Toolkit::ScrollView::Property::SCROLL_POSITION).Get(mScrollPostPosition);
+}
+
+// private functions
+
+void ScrollView::PreAnimatedScrollSetup()
+{
+ // SCROLL_PRE_POSITION is our unclamped property with wrapping
+ // SCROLL_POSITION is our final scroll position after clamping
+
+ Actor self = Self();
+
+ Vector2 deltaPosition(mScrollPostPosition);
+ WrapPosition(mScrollPostPosition);
+ mDomainOffset += deltaPosition - mScrollPostPosition;
+ Self().SetProperty(Toolkit::ScrollView::Property::SCROLL_DOMAIN_OFFSET, mDomainOffset);
- if(!mSnapYAnimation)
+ if(mScrollStateFlags & SCROLL_X_STATE_MASK)
{
- HandleSnapAnimationFinished();
+ // already performing animation on internal x position
+ StopAnimation(mInternalXAnimation);
+ }
+
+ if(mScrollStateFlags & SCROLL_Y_STATE_MASK)
+ {
+ // already performing animation on internal y position
+ StopAnimation(mInternalYAnimation);
}
- if(mScrollMainInternalOvershootXConstraint)
+
+ mScrollStateFlags = 0;
+
+ // Update Actor position with this wrapped value.
+}
+
+void ScrollView::FinaliseAnimatedScroll()
+{
+ // TODO - common animation finishing code in here
+}
+
+void ScrollView::AnimateInternalXTo(float position, float duration, AlphaFunction alpha)
+{
+ StopAnimation(mInternalXAnimation);
+
+ if(duration > Math::MACHINE_EPSILON_10)
{
- Self().RemoveConstraint(mScrollMainInternalOvershootXConstraint);
- mScrollMainInternalOvershootXConstraint.Reset();
- mScrollMainInternalOvershootXConstraint = 0;
+ Actor self = Self();
+ DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetCurrentProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get<Vector2>().x, position);
+ mInternalXAnimation = Animation::New(duration);
+ DALI_LOG_SCROLL_STATE("[0x%X], mInternalXAnimation[0x%X]", this, mInternalXAnimation.GetObjectPtr());
+ mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
+ mInternalXAnimation.AnimateTo(Property(self, Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, 0), position, alpha, TimePeriod(duration));
+ mInternalXAnimation.Play();
+
+ // erase current state flags
+ mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
+ // add internal animation state flag
+ mScrollStateFlags |= AnimatingInternalX;
}
- mSnapXAnimation.FinishedSignal().Disconnect(this, &ScrollView::OnSnapXAnimationFinished);
- mSnapXAnimation.Reset();
- mSnapXAnimation = NULL;
- if( IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
+}
+
+void ScrollView::AnimateInternalYTo(float position, float duration, AlphaFunction alpha)
+{
+ StopAnimation(mInternalYAnimation);
+
+ if(duration > Math::MACHINE_EPSILON_10)
{
- // kick start animation to 0
- Self().SetProperty(mPropertyOvershootX, 0.0f);
+ Actor self = Self();
+ DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetCurrentProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get<Vector2>().y, position);
+ mInternalYAnimation = Animation::New(duration);
+ DALI_LOG_SCROLL_STATE("[0x%X], mInternalYAnimation[0x%X]", this, mInternalYAnimation.GetObjectPtr());
+ mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
+ mInternalYAnimation.AnimateTo(Property(self, Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, 1), position, alpha, TimePeriod(duration));
+ mInternalYAnimation.Play();
+
+ // erase current state flags
+ mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
+ // add internal animation state flag
+ mScrollStateFlags |= AnimatingInternalY;
}
}
-void ScrollView::OnSnapYAnimationFinished( Animation& source )
+void ScrollView::OnScrollAnimationFinished(Animation& source)
{
// Guard against destruction during signal emission
// Note that ScrollCompletedSignal is emitted from HandleSnapAnimationFinished()
- Toolkit::ScrollView handle( GetOwner() );
+ Toolkit::ScrollView handle(GetOwner());
+
+ bool scrollingFinished = false;
+
+ // update our local scroll positions
+ UpdateLocalScrollProperties();
+
+ if(source == mInternalXAnimation)
+ {
+ DALI_LOG_SCROLL_STATE("[0x%X] mInternalXAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalXAnimation.GetObjectPtr(), mScrollTargetPosition.x, Self().GetCurrentProperty(SCROLL_PRE_POSITION).Get<Vector2>().x, mScrollPostPosition.x);
- if(!mSnapXAnimation)
+ if(!(mScrollStateFlags & AnimatingInternalY))
+ {
+ scrollingFinished = true;
+ }
+ mInternalXAnimation.Reset();
+ // wrap pre scroll x position and set it
+ if(mWrapMode)
+ {
+ const RulerDomain rulerDomain = mRulerX->GetDomain();
+ mScrollPrePosition.x = -WrapInDomain(-mScrollPrePosition.x, rulerDomain.min, rulerDomain.max);
+ DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y);
+ handle.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPrePosition);
+ }
+ SnapInternalXTo(mScrollPostPosition.x);
+ }
+
+ if(source == mInternalYAnimation)
+ {
+ DALI_LOG_SCROLL_STATE("[0x%X] mInternalYAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalYAnimation.GetObjectPtr(), mScrollTargetPosition.y, DevelHandle::GetProperty(Self(), SCROLL_PRE_POSITION).Get<Vector2>().y, mScrollPostPosition.y);
+
+ if(!(mScrollStateFlags & AnimatingInternalX))
+ {
+ scrollingFinished = true;
+ }
+ mInternalYAnimation.Reset();
+ if(mWrapMode)
+ {
+ // wrap pre scroll y position and set it
+ const RulerDomain rulerDomain = mRulerY->GetDomain();
+ mScrollPrePosition.y = -WrapInDomain(-mScrollPrePosition.y, rulerDomain.min, rulerDomain.max);
+ DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y);
+ handle.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPrePosition);
+ }
+ SnapInternalYTo(mScrollPostPosition.y);
+ }
+
+ DALI_LOG_SCROLL_STATE("[0x%X] scrollingFinished[%d] Animation[0x%X]", this, scrollingFinished, source.GetObjectPtr());
+
+ if(scrollingFinished)
{
HandleSnapAnimationFinished();
}
- if(mScrollMainInternalOvershootYConstraint)
+}
+
+void ScrollView::OnSnapInternalPositionFinished(Animation& source)
+{
+ Actor self = Self();
+ UpdateLocalScrollProperties();
+ if(source == mInternalXAnimation)
+ {
+ DALI_LOG_SCROLL_STATE("[0x%X] Finished X PostPosition Animation", this);
+
+ // clear internal x animation flags
+ mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
+ mInternalXAnimation.Reset();
+ WrapPosition(mScrollPrePosition);
+ }
+ if(source == mInternalYAnimation)
+ {
+ DALI_LOG_SCROLL_STATE("[0x%X] Finished Y PostPosition Animation", this);
+
+ mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
+ mInternalYAnimation.Reset();
+ WrapPosition(mScrollPrePosition);
+ }
+}
+
+void ScrollView::SnapInternalXTo(float position)
+{
+ Actor self = Self();
+
+ StopAnimation(mInternalXAnimation);
+
+ // erase current state flags
+ mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
+
+ // if internal x not equal to inputed parameter, animate it
+ float duration = std::min(fabsf((position - mScrollPrePosition.x) / mMaxOvershoot.x) * mSnapOvershootDuration, mSnapOvershootDuration);
+ DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration);
+ if(duration > Math::MACHINE_EPSILON_1)
{
- Self().RemoveConstraint(mScrollMainInternalOvershootYConstraint);
- mScrollMainInternalOvershootYConstraint.Reset();
- mScrollMainInternalOvershootYConstraint = 0;
+ DALI_LOG_SCROLL_STATE("[0x%X] Starting X Snap Animation to[%.2f]", this, position);
+
+ mInternalXAnimation = Animation::New(duration);
+ mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
+ mInternalXAnimation.AnimateTo(Property(self, Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, 0), position);
+ mInternalXAnimation.Play();
+
+ // add internal animation state flag
+ mScrollStateFlags |= SnappingInternalX;
}
- mSnapYAnimation.FinishedSignal().Disconnect(this, &ScrollView::OnSnapYAnimationFinished);
- mSnapYAnimation.Reset();
- mSnapYAnimation = NULL;
- if( IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
+}
+
+void ScrollView::SnapInternalYTo(float position)
+{
+ Actor self = Self();
+
+ StopAnimation(mInternalYAnimation);
+
+ // erase current state flags
+ mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
+
+ // if internal y not equal to inputed parameter, animate it
+ float duration = std::min(fabsf((position - mScrollPrePosition.y) / mMaxOvershoot.y) * mSnapOvershootDuration, mSnapOvershootDuration);
+ DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration);
+ if(duration > Math::MACHINE_EPSILON_1)
{
- // kick start animation to 0
- Self().SetProperty(mPropertyOvershootY, 0.0f);
+ DALI_LOG_SCROLL_STATE("[0x%X] Starting Y Snap Animation to[%.2f]", this, position);
+
+ mInternalYAnimation = Animation::New(duration);
+ mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
+ mInternalYAnimation.AnimateTo(Property(self, Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, 1), position);
+ mInternalYAnimation.Play();
+
+ // add internal animation state flag
+ mScrollStateFlags |= SnappingInternalY;
}
}
// we handle the first gesture.
// if we're currently doing a gesture and receive another
// we continue and combine the effects of the gesture instead of reseting.
- if(mGestureStackDepth++==0)
+ if(mGestureStackDepth++ == 0)
{
+ Actor self = Self();
+ StopTouchDownTimer();
StopAnimation();
- mPanDelta = Vector3::ZERO;
- mScaleDelta = Vector3::ONE;
- mRotationDelta = 0.0f;
- mLastVelocity = Vector2(0.0f, 0.0f);
- mLockAxis = LockPossible;
+ mPanDelta = Vector2::ZERO;
+ mLastVelocity = Vector2::ZERO;
+ if(!mScrolling)
+ {
+ mLockAxis = LockPossible;
+ }
+
+ if(mScrollStateFlags & SCROLL_X_STATE_MASK)
+ {
+ StopAnimation(mInternalXAnimation);
+ }
+ if(mScrollStateFlags & SCROLL_Y_STATE_MASK)
+ {
+ StopAnimation(mInternalYAnimation);
+ }
+ mScrollStateFlags = 0;
if(mScrolling) // are we interrupting a current scroll?
{
// set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete.
mScrolling = false;
- Vector3 currentScrollPosition = GetCurrentScrollPosition();
- mScrollCompletedSignalV2.Emit( currentScrollPosition );
+ // send negative scroll position since scroll internal scroll position works as an offset for actors,
+ // give applications the position within the domain from the scroll view's anchor position
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 5 [%.2f, %.2f]", this, -mScrollPostPosition.x, -mScrollPostPosition.y);
+ mScrollCompletedSignal.Emit(-mScrollPostPosition);
}
}
}
-void ScrollView::GestureContinuing(Vector2 panDelta, Vector2 scaleDelta, float rotationDelta)
+void ScrollView::GestureContinuing(const Vector2& panDelta)
{
- mPanDelta.x+= panDelta.x;
- mPanDelta.y+= panDelta.y;
- mScaleDelta.x*= scaleDelta.x;
- mScaleDelta.y*= scaleDelta.y;
- mRotationDelta+= rotationDelta;
+ mPanDelta.x += panDelta.x;
+ mPanDelta.y += panDelta.y;
// Save the velocity, there is a bug in PanGesture
- // Whereby the Gesture::Finished's velocity is either:
+ // Whereby the GestureState::FINISHED's velocity is either:
// NaN (due to time delta of zero between the last two events)
// or 0 (due to position being the same between the last two events)
// appears mostly horizontal or mostly vertical respectively.
if(mAxisAutoLock)
{
- if(mPanDelta.LengthSquared() > AUTOLOCK_AXIS_MINIMUM_DISTANCE2 &&
- mLockAxis == LockPossible)
- {
- float dx = fabsf(mPanDelta.x);
- float dy = fabsf(mPanDelta.y);
- if(dx * mAxisAutoLockGradient >= dy)
- {
- // 0.36:1 gradient to the horizontal (deviate < 20 degrees)
- mLockAxis = LockVertical;
- }
- else if(dy * mAxisAutoLockGradient > dx)
- {
- // 0.36:1 gradient to the vertical (deviate < 20 degrees)
- mLockAxis = LockHorizontal;
- }
- else
- {
- mLockAxis = LockNone;
- }
- }
+ mLockAxis = GetLockAxis(mPanDelta, mLockAxis, mAxisAutoLockGradient);
} // end if mAxisAutoLock
}
// TODO: Upgrade to use a more powerful gesture detector (one that supports multiple touches on pan - so works as pan and flick gesture)
-// TODO: Reimplement Scaling (pinching 2+ points)
-// TODO: Reimplment Rotation (pinching 2+ points)
-// BUG: Gesture::Finished doesn't always return velocity on release (due to
+// BUG: GestureState::FINISHED doesn't always return velocity on release (due to
// timeDelta between last two events being 0 sometimes, or posiiton being the same)
-void ScrollView::OnPan(PanGesture gesture)
+void ScrollView::OnPan(const PanGesture& gesture)
{
// Guard against destruction during signal emission
// Note that Emit() methods are called indirectly e.g. from within ScrollView::OnGestureEx()
- Actor self( Self() );
+ Actor self(Self());
if(!mSensitive)
{
+ DALI_LOG_SCROLL_STATE("[0x%X] Pan Ignored, Insensitive", this);
+
// If another callback on the same original signal disables sensitivity,
// this callback will still be called, so we must suppress it.
return;
}
// translate Gesture input to get useful data...
- switch(gesture.state)
+ switch(gesture.GetState())
{
- case Gesture::Started:
+ case GestureState::STARTED:
{
+ DALI_LOG_SCROLL_STATE("[0x%X] Pan Started", this);
+ const Vector2& position = gesture.GetPosition();
+ mPanStartPosition = position - gesture.GetDisplacement();
+ UpdateLocalScrollProperties();
GestureStarted();
- self.SetProperty( mPropertyPanning, true );
- self.SetProperty( mPropertyScrollStartPagePosition, GetCurrentScrollPosition() );
-
- // Update property: X & Y = Position (only when in panning mode - in snapping mode, X & Y are animated).
- Constraint constraint = Constraint::New<float>( mPropertyX,
- LocalSource( mPropertyPosition ),
- Source( self, mPropertyPanning ),
- InternalXConstraint );
- mScrollMainInternalXConstraint = self.ApplyConstraint(constraint);
-
- constraint = Constraint::New<float>( mPropertyY,
- LocalSource( mPropertyPosition ),
- Source( self, mPropertyPanning ),
- InternalYConstraint );
- mScrollMainInternalYConstraint = self.ApplyConstraint(constraint);
- // When panning we want to make sure overshoot values are affected by pre position and post position
- SetOvershootConstraintsEnabled(true);
+ mPanning = true;
+ self.SetProperty(Toolkit::ScrollView::Property::PANNING, true);
+ self.SetProperty(Toolkit::ScrollView::Property::START_PAGE_POSITION, Vector3(position.x, position.y, 0.0f));
+
+ mConstraints.UpdateMainInternalConstraint(*this);
+ Toolkit::ScrollBar scrollBar = mScrollBar.GetHandle();
+ if(scrollBar && mTransientScrollBar)
+ {
+ Vector3 size = Self().GetCurrentProperty<Vector3>(Actor::Property::SIZE);
+ const Toolkit::RulerDomain& rulerDomainX = mRulerX->GetDomain();
+ const Toolkit::RulerDomain& rulerDomainY = mRulerY->GetDomain();
+
+ if((rulerDomainX.max > size.width) || (rulerDomainY.max > size.height))
+ {
+ scrollBar.ShowIndicator();
+ }
+ }
break;
}
- case Gesture::Continuing:
+ case GestureState::CONTINUING:
{
- // Nothing to do, handled in constraint.
+ if(mPanning)
+ {
+ DALI_LOG_SCROLL_STATE("[0x%X] Pan Continuing", this);
+ GestureContinuing(gesture.GetScreenDisplacement());
+ }
+ else
+ {
+ // If we do not think we are panning, then we should not do anything here
+ return;
+ }
break;
}
- case Gesture::Finished:
- case Gesture::Cancelled:
+ case GestureState::FINISHED:
+ case GestureState::CANCELLED:
{
- mLastVelocity = gesture.velocity;
- self.SetProperty( mPropertyPanning, false );
+ if(mPanning)
+ {
+ DALI_LOG_SCROLL_STATE("[0x%X] Pan %s", this, ((gesture.GetState() == GestureState::FINISHED) ? "Finished" : "Cancelled"));
+
+ UpdateLocalScrollProperties();
+ mLastVelocity = gesture.GetVelocity();
+ mPanning = false;
+ self.SetProperty(Toolkit::ScrollView::Property::PANNING, false);
+
+ if(mConstraints.mScrollMainInternalPrePositionConstraint)
+ {
+ mConstraints.mScrollMainInternalPrePositionConstraint.Remove();
+ }
- // Remove X & Y position constraints as they are not required when we are not panning.
- self.RemoveConstraint(mScrollMainInternalXConstraint);
- self.RemoveConstraint(mScrollMainInternalYConstraint);
+ Toolkit::ScrollBar scrollBar = mScrollBar.GetHandle();
+ if(scrollBar && mTransientScrollBar)
+ {
+ scrollBar.HideIndicator();
+ }
+ }
+ else
+ {
+ // If we do not think we are panning, then we should not do anything here
+ return;
+ }
break;
}
- case Gesture::Possible:
- case Gesture::Clear:
+ case GestureState::POSSIBLE:
+ case GestureState::CLEAR:
{
// Nothing to do, not needed.
break;
} // end switch(gesture.state)
- OnGestureEx(gesture.state);
+ OnGestureEx(gesture.GetState());
}
-void ScrollView::OnGestureEx(Gesture::State state)
+void ScrollView::OnGestureEx(GestureState state)
{
// call necessary signals for application developer
- if(state == Gesture::Started)
+ if(state == GestureState::STARTED)
{
- Vector3 currentScrollPosition = GetCurrentScrollPosition();
- Self().SetProperty(mPropertyScrolling, true);
+ Vector2 currentScrollPosition = GetCurrentScrollPosition();
+ Self().SetProperty(Toolkit::ScrollView::Property::SCROLLING, true);
mScrolling = true;
- mScrollStartedSignalV2.Emit( currentScrollPosition );
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignal 2 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
+ mScrollStartedSignal.Emit(currentScrollPosition);
}
- else if( (state == Gesture::Finished) ||
- (state == Gesture::Cancelled) ) // Finished/default
+ else if((state == GestureState::FINISHED) ||
+ (state == GestureState::CANCELLED)) // Finished/default
{
// when all the gestures have finished, we finish the transform.
// so if a user decides to pan (1 gesture), and then pan+zoom (2 gestures)
// then stop panning (back to 1 gesture), and then stop zooming (0 gestures).
// this is the point we end, and perform necessary snapping.
mGestureStackDepth--;
- if(mGestureStackDepth==0)
+ if(mGestureStackDepth == 0)
{
+ // no flick if we have not exceeded min flick distance
+ if((fabsf(mPanDelta.x) < mMinFlickDistance.x) && (fabsf(mPanDelta.y) < mMinFlickDistance.y))
+ {
+ // reset flick velocity
+ mLastVelocity = Vector2::ZERO;
+ }
FinishTransform();
}
+ else
+ {
+ DALI_LOG_SCROLL_STATE("[0x%X] mGestureStackDepth[%d]", this, mGestureStackDepth);
+ }
}
}
-void ScrollView::UpdateTransform()
-{
-// TODO: notify clamps using property notifications (or see if we need this, can deprecate it)
-}
-
void ScrollView::FinishTransform()
{
- const Vector3& scrollPosition = Self().GetProperty<Vector3>(mPropertyPosition);
-
- mScrollPostPosition.x = scrollPosition.x;
- mScrollPostPosition.y = scrollPosition.y;
-
- Vector3 deltaPosition(mScrollPostPosition);
- // Cement PRE transform (PRE = POST), and Begin Snap Animation if necessary.
- WrapPosition(mScrollPostPosition);
+ // at this stage internal x and x scroll position should have followed prescroll position exactly
+ Actor self = Self();
- mDomainOffset += deltaPosition - mScrollPostPosition;
- Self().SetProperty(mPropertyDomainOffset, mDomainOffset);
+ PreAnimatedScrollSetup();
+ // convert pixels/millisecond to pixels per second
bool animating = SnapWithVelocity(mLastVelocity * 1000.0f);
if(!animating)
{
- AnimateOvershootToOrigin(0.0f, 0.0f);
// if not animating, then this pan has completed right now.
+ SetScrollUpdateNotification(false);
mScrolling = false;
- Self().SetProperty(mPropertyScrolling, false);
- Vector3 currentScrollPosition = GetCurrentScrollPosition();
- mScrollCompletedSignalV2.Emit( currentScrollPosition );
- }
-}
-
-Vector3 ScrollView::GetOvershoot(Vector3& position) const
-{
- Vector3 size = Self().GetCurrentSize();
- Vector3 overshoot;
-
- const RulerDomain rulerDomainX = mRulerX->GetDomain();
- const RulerDomain rulerDomainY = mRulerY->GetDomain();
-
- if(mRulerX->IsEnabled() && rulerDomainX.enabled)
- {
- const float left = rulerDomainX.min - position.x;
- const float right = size.width - rulerDomainX.max - position.x;
- if(left<0)
- {
- overshoot.x = left;
- }
- else if(right>0)
- {
- overshoot.x = right;
- }
- }
+ Self().SetProperty(Toolkit::ScrollView::Property::SCROLLING, false);
- if(mRulerY->IsEnabled() && rulerDomainY.enabled)
- {
- const float top = rulerDomainY.min - position.y;
- const float bottom = size.height - rulerDomainY.max - position.y;
- if(top<0)
+ if(fabs(mScrollPrePosition.x - mScrollTargetPosition.x) > Math::MACHINE_EPSILON_10)
{
- overshoot.y = top;
+ SnapInternalXTo(mScrollTargetPosition.x);
}
- else if(bottom>0)
+ if(fabs(mScrollPrePosition.y - mScrollTargetPosition.y) > Math::MACHINE_EPSILON_10)
{
- overshoot.y = bottom;
+ SnapInternalYTo(mScrollTargetPosition.y);
}
+ Vector2 currentScrollPosition = GetCurrentScrollPosition();
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 6 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
+ mScrollCompletedSignal.Emit(currentScrollPosition);
}
-
- return overshoot;
}
bool ScrollView::OnAccessibilityPan(PanGesture gesture)
{
+ // Keep track of whether this is an AccessibilityPan
+ mInAccessibilityPan = true;
OnPan(gesture);
+ mInAccessibilityPan = false;
+
return true;
}
-void ScrollView::ClampPosition(Vector3& position) const
+void ScrollView::ClampPosition(Vector2& position) const
{
- ClampState3 clamped;
+ ClampState2D clamped;
ClampPosition(position, clamped);
}
-void ScrollView::ClampPosition(Vector3& position, ClampState3 &clamped) const
+void ScrollView::ClampPosition(Vector2& position, ClampState2D& clamped) const
{
- Vector3 size = Self().GetCurrentSize();
-
- // determine size of viewport relative to current scaled size.
- // e.g. if you're zoomed in 200%, then each pixel on screen is only 0.5 pixels on subject.
- if(fabsf(mScrollPostScale.x) > Math::MACHINE_EPSILON_0)
- {
- size.x /= mScrollPostScale.x;
- }
-
- if(fabsf(mScrollPostScale.y) > Math::MACHINE_EPSILON_0)
- {
- size.y /= mScrollPostScale.y;
- }
-
- position.x = -mRulerX->Clamp(-position.x, size.width, 1.0f, clamped.x); // NOTE: X & Y rulers think in -ve coordinate system.
- position.y = -mRulerY->Clamp(-position.y, size.height, 1.0f, clamped.y); // That is scrolling RIGHT (e.g. 100.0, 0.0) means moving LEFT.
+ Vector3 size = Self().GetCurrentProperty<Vector3>(Actor::Property::SIZE);
- clamped.z = NotClamped;
+ ::ClampPosition(size, mRulerX, mRulerY, position, clamped);
}
-void ScrollView::WrapPosition(Vector3& position) const
+void ScrollView::WrapPosition(Vector2& position) const
{
if(mWrapMode)
{
}
}
-void ScrollView::ClampScale(Vector3& scale) const
-{
- ClampState3 clamped;
- ClampScale(scale, clamped);
-}
-
-void ScrollView::ClampScale(Vector3& scale, ClampState3 &clamped) const
-{
- scale.x = mRulerScaleX->Clamp(scale.x, 0.0f, 1.0f, clamped.x);
- scale.y = mRulerScaleY->Clamp(scale.y, 0.0f, 1.0f, clamped.y);
- clamped.z = NotClamped;
-}
-
-void ScrollView::UpdateMainInternalConstraint()
-{
- // TODO: Only update the constraints which have changed, rather than remove all and add all again.
- // Requires a dali-core ApplyConstraintAt, or a ReplaceConstraint. The former is probably more flexible.
- Actor self = Self();
- PanGestureDetector detector( GetPanGestureDetector() );
-
- if(mScrollMainInternalPrePositionConstraint)
- {
- self.RemoveConstraint(mScrollMainInternalPrePositionConstraint);
- self.RemoveConstraint(mScrollMainInternalPositionConstraint);
- self.RemoveConstraint(mScrollMainInternalDeltaConstraint);
- self.RemoveConstraint(mScrollMainInternalFinalConstraint);
- self.RemoveConstraint(mScrollMainInternalRelativeConstraint);
- }
-
- // TODO: It's probably better to use a local displacement value as this will give a displacement when scrolling just commences
- // but we need to make sure than the gesture system gives displacement since last frame (60Hz), not displacement since last touch event (90Hz).
-
- // 1. First calculate the pre-position (this is the scroll position if no clamping has taken place)
- Vector2 initialPanMask = Vector2(mRulerX->IsEnabled() ? 1.0f : 0.0f, mRulerY->IsEnabled() ? 1.0f : 0.0f);
-
- Constraint constraint = Constraint::New<Vector3>( mPropertyPrePosition,
- Source( detector, PanGestureDetector::LOCAL_POSITION ),
- Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
- LocalSource( mPropertyX ),
- LocalSource( mPropertyY ),
- Source( self, mPropertyPanning ),
- InternalPrePositionConstraint( initialPanMask, mAxisAutoLock, mAxisAutoLockGradient ) );
- mScrollMainInternalPrePositionConstraint = self.ApplyConstraint(constraint);
-
- // 2. Second calculate the clamped position (actual position)
- constraint = Constraint::New<Vector3>( mPropertyPosition,
- LocalSource( mPropertyPrePosition ),
- Source( self, Actor::SIZE ),
- InternalPositionConstraint( mRulerX->GetDomain(),
- mRulerY->GetDomain()) );
- mScrollMainInternalPositionConstraint = self.ApplyConstraint(constraint);
-
- constraint = Constraint::New<Vector3>( mPropertyPositionDelta,
- LocalSource( mPropertyPosition ),
- LocalSource( mPropertyDomainOffset ),
- InternalPositionDeltaConstraint );
- mScrollMainInternalDeltaConstraint = self.ApplyConstraint(constraint);
-
- constraint = Constraint::New<Vector3>( mPropertyFinal,
- LocalSource( mPropertyPosition ),
- LocalSource( mPropertyOvershootX ),
- LocalSource( mPropertyOvershootY ),
- InternalFinalConstraint( FinalDefaultAlphaFunction,
- FinalDefaultAlphaFunction ) );
- mScrollMainInternalFinalConstraint = self.ApplyConstraint(constraint);
-
- constraint = Constraint::New<Vector3>( mPropertyRelativePosition,
- LocalSource( mPropertyPosition ),
- LocalSource( mPropertyPositionMin ),
- LocalSource( mPropertyPositionMax ),
- LocalSource( Actor::SIZE ),
- InternalRelativePositionConstraint );
- mScrollMainInternalRelativeConstraint = self.ApplyConstraint(constraint);
-
- if(mScrollMainInternalOvershootXConstraint)
- {
- // reset these constraints in correct order
- self.RemoveConstraint(mScrollMainInternalOvershootXConstraint);
- mScrollMainInternalOvershootXConstraint.Reset();
-
- Constraint constraint = Constraint::New<float>( mPropertyOvershootX,
- LocalSource( mPropertyPrePosition ),
- LocalSource( mPropertyPosition ),
- OvershootXConstraint(mMaxOvershoot.x) );
- mScrollMainInternalOvershootXConstraint = self.ApplyConstraint(constraint);
- }
-
- if(mScrollMainInternalOvershootYConstraint)
- {
- // reset these constraints in correct order
- self.RemoveConstraint(mScrollMainInternalOvershootYConstraint);
- mScrollMainInternalOvershootYConstraint.Reset();
-
- Constraint constraint = Constraint::New<float>( mPropertyOvershootY,
- LocalSource( mPropertyPrePosition ),
- LocalSource( mPropertyPosition ),
- OvershootXConstraint(mMaxOvershoot.y) );
- mScrollMainInternalOvershootYConstraint = self.ApplyConstraint(constraint);
- }
-}
-
-void ScrollView::SetOvershootConstraintsEnabled(bool enabled)
-{
- Actor self( Self() );
- // remove and reset, it may now be in wrong order with the main internal constraints
- if(mScrollMainInternalOvershootXConstraint)
- {
- self.RemoveConstraint(mScrollMainInternalOvershootXConstraint);
- mScrollMainInternalOvershootXConstraint.Reset();
- }
- if(mScrollMainInternalOvershootYConstraint)
- {
- self.RemoveConstraint(mScrollMainInternalOvershootYConstraint);
- mScrollMainInternalOvershootYConstraint.Reset();
- }
- if(enabled)
- {
- Constraint constraint = Constraint::New<float>( mPropertyOvershootX,
- LocalSource( mPropertyPrePosition ),
- LocalSource( mPropertyPosition ),
- OvershootXConstraint(mMaxOvershoot.x) );
- mScrollMainInternalOvershootXConstraint = self.ApplyConstraint(constraint);
- constraint = Constraint::New<float>( mPropertyOvershootY,
- LocalSource( mPropertyPrePosition ),
- LocalSource( mPropertyPosition ),
- OvershootYConstraint(mMaxOvershoot.y) );
- mScrollMainInternalOvershootYConstraint = self.ApplyConstraint(constraint);
- }
-}
-
-void ScrollView::SetInternalConstraints()
+void ScrollView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
{
- // Internal constraints (applied to target ScrollBase Actor itself) /////////
- UpdateMainInternalConstraint();
-
- // User definable constraints to apply to all child actors //////////////////
- Actor self = Self();
-
- // LocalSource - The Actors to be moved.
- // self - The ScrollView
-
- // Apply some default constraints to ScrollView.
- // Movement + Scaling + Wrap function
-
- Constraint constraint;
-
- // MoveScaledActor (scrolling/zooming)
- constraint = Constraint::New<Vector3>( Actor::POSITION,
- Source( self, mPropertyPosition ),
- Source( self, mPropertyScale ),
- MoveScaledActorConstraint );
- constraint.SetRemoveAction(Constraint::Discard);
- ApplyConstraintToBoundActors(constraint);
-
- // ScaleActor (scrolling/zooming)
- constraint = Constraint::New<Vector3>( Actor::SCALE,
- Source( self, mPropertyScale ),
- ScaleActorConstraint );
- constraint.SetRemoveAction(Constraint::Discard);
- ApplyConstraintToBoundActors(constraint);
-
- // WrapActor (wrap functionality)
- constraint = Constraint::New<Vector3>( Actor::POSITION,
- LocalSource( Actor::SCALE ),
- LocalSource( Actor::ANCHOR_POINT ),
- LocalSource( Actor::SIZE ),
- Source( self, mPropertyPositionMin ),
- Source( self, mPropertyPositionMax ),
- Source( self, mPropertyWrap ),
- WrapActorConstraint );
- constraint.SetRemoveAction(Constraint::Discard);
- ApplyConstraintToBoundActors(constraint);
+ ScrollViewPropertyHandler::Set(object, index, value);
}
-void ScrollView::SetOvershootToOrigin()
+Property::Value ScrollView::GetProperty(BaseObject* object, Property::Index index)
{
- // Clear Snap animation if exists.
- if(mSnapOvershootAnimation)
- {
- mSnapOvershootAnimation.FinishedSignal().Disconnect(this, &ScrollView::OnSnapOvershootAnimationFinished);
- mSnapOvershootAnimation.Stop();
- mSnapOvershootAnimation.Clear();
- mSnapOvershootAnimation = NULL;
- }
- SetOvershootConstraintsEnabled(false);
- Self().SetProperty(mPropertyOvershootX, 0.0f);
- Self().SetProperty(mPropertyOvershootY, 0.0f);
+ return ScrollViewPropertyHandler::Get(object, index);
}
-void ScrollView::AnimateOvershootToOrigin(float xDelay, float yDelay)
+ScrollView::LockAxis GetLockAxis(const Vector2& panDelta, ScrollView::LockAxis currentLockAxis, float lockGradient)
{
- if( IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
- {
- if(xDelay < Math::MACHINE_EPSILON_1)
- {
- // kick start animation to 0
- Self().SetProperty(mPropertyOvershootX, 0.0f);
- }
- if(yDelay < Math::MACHINE_EPSILON_1)
- {
- // kick start animation to 0
- Self().SetProperty(mPropertyOvershootY, 0.0f);
- }
- return;
- }
- // When we need to animate overshoot to 0
- if(mSnapOvershootDuration > Math::MACHINE_EPSILON_1)
+ if(panDelta.LengthSquared() > AUTOLOCK_AXIS_MINIMUM_DISTANCE2 &&
+ currentLockAxis == ScrollView::LockPossible)
{
- Actor self = Self();
- // Clear Snap animation if exists.
- if(mSnapOvershootAnimation)
- {
- mSnapOvershootAnimation.FinishedSignal().Disconnect( this, &ScrollView::OnSnapOvershootAnimationFinished );
- mSnapOvershootAnimation.Stop();
- mSnapOvershootAnimation.Clear();
- mSnapOvershootAnimation = NULL;
- }
- if(!mSnapXAnimation && mScrollMainInternalOvershootXConstraint)
- {
- // need to remove the x overshoot constraint now or it will override animation to 0
- Self().RemoveConstraint(mScrollMainInternalOvershootXConstraint);
- mScrollMainInternalOvershootXConstraint.Reset();
- mScrollMainInternalOvershootXConstraint = 0;
- }
- if(!mSnapYAnimation && mScrollMainInternalOvershootYConstraint)
+ float dx = fabsf(panDelta.x);
+ float dy = fabsf(panDelta.y);
+ if(dx * lockGradient >= dy)
{
- // need to remove the y overshoot constraint now or it will override animation to 0
- Self().RemoveConstraint(mScrollMainInternalOvershootYConstraint);
- mScrollMainInternalOvershootYConstraint.Reset();
- mScrollMainInternalOvershootYConstraint = 0;
+ // 0.36:1 gradient to the horizontal (deviate < 20 degrees)
+ currentLockAxis = ScrollView::LockVertical;
}
- // setup the new overshoot to 0 animation
- float totalDuration = (xDelay > yDelay ? xDelay : yDelay) + mSnapOvershootDuration;
- mSnapOvershootAnimation = Animation::New(totalDuration);
- mSnapOvershootAnimation.FinishedSignal().Connect( this, &ScrollView::OnSnapOvershootAnimationFinished );
-
- mSnapOvershootAnimation.AnimateTo( Property(self, mPropertyOvershootX), 0.0f, mSnapOvershootAlphaFunction, TimePeriod(xDelay, mSnapOvershootDuration) );
- mSnapOvershootAnimation.AnimateTo( Property(self, mPropertyOvershootY), 0.0f, mSnapOvershootAlphaFunction, TimePeriod(yDelay, mSnapOvershootDuration) );
-
- mSnapOvershootAnimation.SetDuration(totalDuration);
- mSnapOvershootAnimation.Play();
- }
- else
- {
- SetOvershootToOrigin();
- }
-}
-
-void ScrollView::OnSnapOvershootAnimationFinished( Animation& source )
-{
- mSnapOvershootAnimation = NULL;
-}
-
-void ScrollView::StartRefreshTimer()
-{
- if(mRefreshIntervalMilliseconds > 0)
- {
- if (!mRefreshTimer)
+ else if(dy * lockGradient > dx)
{
- mRefreshTimer = Timer::New( mRefreshIntervalMilliseconds );
- mRefreshTimer.TickSignal().Connect( this, &ScrollView::OnRefreshTick );
+ // 0.36:1 gradient to the vertical (deviate < 20 degrees)
+ currentLockAxis = ScrollView::LockHorizontal;
}
-
- if (!mRefreshTimer.IsRunning())
+ else
{
- mRefreshTimer.Start();
+ currentLockAxis = ScrollView::LockNone;
}
}
-}
-
-void ScrollView::CancelRefreshTimer()
-{
- if (mRefreshTimer)
- {
- mRefreshTimer.Stop();
- }
-}
-
-bool ScrollView::OnRefreshTick()
-{
- // Guard against destruction during signal emission
- Toolkit::ScrollView handle( GetOwner() );
-
- Vector3 currentScrollPosition = GetCurrentScrollPosition();
- mScrollUpdatedSignalV2.Emit( currentScrollPosition );
-
- return true;
+ return currentLockAxis;
}
} // namespace Internal