2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h>
22 #include <dali/public-api/events/mouse-wheel-event.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
27 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
28 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-effect-impl.h>
29 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-overshoot-indicator-impl.h>
31 //#define ENABLED_SCROLL_STATE_LOGGING
33 #ifdef ENABLED_SCROLL_STATE_LOGGING
34 #define DALI_LOG_SCROLL_STATE(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d " format "\n", __PRETTY_FUNCTION__, __LINE__, ## args)
36 #define DALI_LOG_SCROLL_STATE(format, args...)
39 // TODO: Change to two class system:
40 // 1. DraggableActor (is an actor which can be dragged anywhere, can be set to range using the ruler)
41 // 2. ScrollView (contains a draggable actor that can a) be dragged in the negative X, and Y domain, b) has a hitArea for touches)
42 // TODO: external components (page and status overlays).
44 // TODO: upgrade Vector2/3 to support returning Unit vectors, normals, & cross product (dot product is already provided)
51 const int DEFAULT_REFRESH_INTERVAL_MILLISECONDS = 50; ///< Refresh rate TODO: Animation should have an update signal (and see item-view-impl)
52 const Vector2 DEFAULT_MIN_FLICK_DISTANCE(30.0f, 30.0f); ///< minimum distance for pan before flick allowed
53 const float DEFAULT_MIN_FLICK_SPEED_THRESHOLD(500.0f); ///< Minimum pan speed required for flick in pixels/s
54 const float FREE_FLICK_SPEED_THRESHOLD = 200.0f; ///< Free-Flick threshold in pixels/ms
55 const float AUTOLOCK_AXIS_MINIMUM_DISTANCE2 = 100.0f; ///< Auto-lock axis after minimum distance squared.
56 const float FLICK_ORTHO_ANGLE_RANGE = 75.0f; ///< degrees. (if >45, then supports diagonal flicking)
57 const unsigned int MAXIMUM_NUMBER_OF_VALUES = 5; ///< Number of values to use for weighted pan calculation.
58 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.
59 const unsigned long MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET( 150u );
60 const float DEFAULT_OVERSHOOT_ANIMATION_DURATION = 0.35f; // time in seconds
61 const Vector2 OVERSCROLL_CLAMP(1.0f, 1.0f); // maximum overscroll allowed in pixels when overshoot indicator is being used
62 const float TOUCH_DOWN_TIMER_INTERVAL = 100.0f;
63 const float DEFAULT_SCROLL_UPDATE_DISTANCE( 30.0f ); ///< Default distance to travel in pixels for scroll update signal
65 // predefined effect values
66 const Vector3 ANGLE_CAROUSEL_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f);
67 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
68 const Vector2 ANGLE_CUSTOM_CUBE_SWING(-Math::PI * 0.45f, -Math::PI * 0.45f); ///< outer cube pages swing 90 degrees as they pan offscreen
69 const Vector2 ANGLE_SPIRAL_SWING_IN(Math::PI * 0.5f, Math::PI * 0.5f);
70 const Vector2 ANGLE_SPIRAL_SWING_OUT(Math::PI * 0.35f, Math::PI * 0.35f);
71 const Vector2 ANGLE_OUTER_CUBE_SWING(Math::PI * 0.5f, Math::PI * 0.5f); ///< outer cube pages swing 90 degrees as they pan offscreen
73 // Helpers ////////////////////////////////////////////////////////////////////////////////////////
75 // TODO: GetAngle for Vector2 can be moved.
76 // GetAngle for Vector3 needs to be measured against a normal/plane.
79 * @param[in] vector The 3D vector to be measured
80 * @return angle in radians from 0 to 2PI
82 float GetAngle(const Vector3& vector)
84 return atan2(vector.y, vector.x) + Math::PI;
88 * @param[in] vector The 2D vector to be measured
89 * @return angle in radians from 0 to 2PI
91 float GetAngle(const Vector2& vector)
93 return atan2(vector.y, vector.x) + Math::PI;
97 * Find the vector (distance) from (a) to (b)
98 * in domain (start) to (end)
99 * (\ / start) (\ / end)
102 * @note assumes both (a) and (b) are already with the domain
105 * @param[in] a the current point
106 * @param[in] b the target point
107 * @param[in] start the start of the domain
108 * @param[in] end the end of the domain
109 * @param[in] bias whether to only take the right direction or the left direction,
110 * or the shortest direction.
111 * @return the shortest direction and distance
113 float VectorInDomain(float a, float b, float start, float end, Dali::Toolkit::DirectionBias bias)
115 if(bias == Dali::Toolkit::DirectionBiasNone)
117 return ShortestDistanceInDomain( a, b, start, end );
120 float size = end-start;
126 if(bias == Dali::Toolkit::DirectionBiasRight) // going right, take the vector.
132 float aRight = a+size;
139 if(bias == Dali::Toolkit::DirectionBiasLeft) // going left, take the vector.
145 float aLeft = a-size;
152 * Returns the position of the anchor within actor
154 * @param actor The Actor
155 * @param anchor The Anchor point of interest.
156 * @return The position of the Anchor
158 Vector3 GetPositionOfAnchor(Actor &actor, const Vector3 &anchor)
160 Vector3 childPosition = actor.GetCurrentPosition();
161 Vector3 childAnchor = - actor.GetCurrentAnchorPoint() + anchor;
162 Vector3 childSize = actor.GetCurrentSize();
164 return childPosition + childAnchor * childSize;
167 // AlphaFunctions /////////////////////////////////////////////////////////////////////////////////
169 float FinalDefaultAlphaFunction(float offset)
171 return offset * 0.5f;
175 * ConstantDecelerationAlphaFunction
176 * Newtoninan distance for constant deceleration
177 * v = 1 - t, s = t - 1/2 t^2
178 * when t = 0, s = 0.0 (min distance)
179 * when t = 1, s = 0.5 (max distance)
180 * progress = s / (max-min) = 2t - t^2
182 * @param[in] offset The input progress
183 * @return The output progress
185 float ConstantDecelerationAlphaFunction(float progress)
187 return progress * 2.0f - progress * progress;
190 // Internal Constraints ///////////////////////////////////////////////////////////////////////////
193 * Internal Relative position Constraint
194 * Generates the relative position value of the scroll view
195 * based on the absolute position, and it's relation to the
196 * scroll domain. This is a value from 0.0f to 1.0f in each
197 * scroll position axis.
199 Vector3 InternalRelativePositionConstraint(const Vector3& current,
200 const PropertyInput& scrollPositionProperty,
201 const PropertyInput& scrollMinProperty,
202 const PropertyInput& scrollMaxProperty,
203 const PropertyInput& scrollSizeProperty)
205 Vector3 position = -scrollPositionProperty.GetVector3();
206 const Vector3& min = scrollMinProperty.GetVector3();
207 const Vector3& max = scrollMaxProperty.GetVector3();
208 const Vector3& size = scrollSizeProperty.GetVector3();
210 position.x = WrapInDomain(position.x, min.x, max.x);
211 position.y = WrapInDomain(position.y, min.y, max.y);
213 Vector3 relativePosition;
214 Vector3 domainSize = (max - min) - size;
216 relativePosition.x = domainSize.x > Math::MACHINE_EPSILON_1 ? fabsf((position.x - min.x) / domainSize.x) : 0.0f;
217 relativePosition.y = domainSize.y > Math::MACHINE_EPSILON_1 ? fabsf((position.y - min.y) / domainSize.y) : 0.0f;
219 return relativePosition;
222 } // unnamed namespace
237 * Returns whether to lock scrolling to a particular axis
239 * @param[in] panDelta Distance panned since gesture started
240 * @param[in] currentLockAxis The current lock axis value
241 * @param[in] lockGradient How quickly to lock to a particular axis
243 * @return The new axis lock state
245 ScrollView::LockAxis GetLockAxis(const Vector2& panDelta, ScrollView::LockAxis currentLockAxis, float lockGradient)
247 if(panDelta.LengthSquared() > AUTOLOCK_AXIS_MINIMUM_DISTANCE2 &&
248 currentLockAxis == ScrollView::LockPossible)
250 float dx = fabsf(panDelta.x);
251 float dy = fabsf(panDelta.y);
252 if(dx * lockGradient >= dy)
254 // 0.36:1 gradient to the horizontal (deviate < 20 degrees)
255 currentLockAxis = ScrollView::LockVertical;
257 else if(dy * lockGradient > dx)
259 // 0.36:1 gradient to the vertical (deviate < 20 degrees)
260 currentLockAxis = ScrollView::LockHorizontal;
264 currentLockAxis = ScrollView::LockNone;
267 return currentLockAxis;
271 * Internal Pre-Position Property Constraint.
273 * Generates position property based on current position + gesture displacement.
274 * Or generates position property based on positionX/Y.
275 * Note: This is the position prior to any clamping at scroll boundaries.
277 struct InternalPrePositionConstraint
279 InternalPrePositionConstraint(const Vector2& initialPanPosition,
280 const Vector2& initialPanMask,
282 float axisAutoLockGradient,
283 ScrollView::LockAxis initialLockAxis,
284 const Vector2& maxOvershoot,
285 const RulerDomain& domainX, const RulerDomain& domainY)
286 : mLocalStart(initialPanPosition),
287 mInitialPanMask(initialPanMask),
288 mDomainMin( -domainX.min, -domainY.min ),
289 mDomainMax( -domainX.max, -domainY.max ),
290 mMaxOvershoot(maxOvershoot),
291 mAxisAutoLockGradient(axisAutoLockGradient),
292 mLockAxis(initialLockAxis),
293 mAxisAutoLock(axisAutoLock),
295 mClampX( domainX.enabled ),
296 mClampY( domainY.enabled )
300 Vector3 operator()(const Vector3& current,
301 const PropertyInput& gesturePositionProperty,
302 const PropertyInput& sizeProperty)
304 Vector3 scrollPostPosition = current;
305 Vector2 panPosition = gesturePositionProperty.GetVector2();
309 mPrePosition = current;
310 mCurrentPanMask = mInitialPanMask;
314 // Calculate Deltas...
315 Vector2 currentPosition = gesturePositionProperty.GetVector2();
316 Vector2 panDelta( currentPosition - mLocalStart );
318 // Axis Auto Lock - locks the panning to the horizontal or vertical axis if the pan
319 // appears mostly horizontal or mostly vertical respectively...
322 mLockAxis = GetLockAxis(panDelta, mLockAxis, mAxisAutoLockGradient);
323 if( mLockAxis == ScrollView::LockVertical )
325 mCurrentPanMask.y = 0.0f;
327 else if( mLockAxis == ScrollView::LockHorizontal )
329 mCurrentPanMask.x = 0.0f;
333 // Restrict deltas based on ruler enable/disable and axis-lock state...
334 panDelta *= mCurrentPanMask;
336 // Perform Position transform based on input deltas...
337 scrollPostPosition = mPrePosition;
338 scrollPostPosition.GetVectorXY() += panDelta;
340 // if no wrapping then clamp preposition to maximum overshoot amount
341 const Vector3& size = sizeProperty.GetVector3();
344 float newXPosition = Clamp(scrollPostPosition.x, (mDomainMax.x + size.x) - mMaxOvershoot.x, mDomainMin.x + mMaxOvershoot.x );
345 if( (newXPosition < scrollPostPosition.x - Math::MACHINE_EPSILON_1)
346 || (newXPosition > scrollPostPosition.x + Math::MACHINE_EPSILON_1) )
348 mPrePosition.x = newXPosition;
349 mLocalStart.x = panPosition.x;
351 scrollPostPosition.x = newXPosition;
355 float newYPosition = Clamp(scrollPostPosition.y, (mDomainMax.y + size.y) - mMaxOvershoot.y, mDomainMin.y + mMaxOvershoot.y );
356 if( (newYPosition < scrollPostPosition.y - Math::MACHINE_EPSILON_1)
357 || (newYPosition > scrollPostPosition.y + Math::MACHINE_EPSILON_1) )
359 mPrePosition.y = newYPosition;
360 mLocalStart.y = panPosition.y;
362 scrollPostPosition.y = newYPosition;
365 return scrollPostPosition;
368 Vector3 mPrePosition;
370 Vector2 mInitialPanMask; ///< Initial pan mask (based on ruler settings)
371 Vector2 mCurrentPanMask; ///< Current pan mask that can be altered by axis lock mode.
374 Vector2 mMaxOvershoot;
376 float mAxisAutoLockGradient; ///< Set by ScrollView
377 ScrollView::LockAxis mLockAxis;
379 bool mAxisAutoLock:1; ///< Set by ScrollView
386 * Internal Position Property Constraint.
388 * Generates position property based on pre-position
389 * Note: This is the position after clamping.
390 * (uses result of InternalPrePositionConstraint)
392 struct InternalPositionConstraint
394 InternalPositionConstraint(const RulerDomain& domainX, const RulerDomain& domainY, bool wrap)
395 : mDomainMin( -domainX.min, -domainY.min ),
396 mDomainMax( -domainX.max, -domainY.max ),
397 mClampX( domainX.enabled ),
398 mClampY( domainY.enabled ),
403 Vector3 operator()(const Vector3& current,
404 const PropertyInput& scrollPositionProperty,
405 const PropertyInput& scrollMinProperty,
406 const PropertyInput& scrollMaxProperty,
407 const PropertyInput& scrollSizeProperty)
409 Vector3 position = scrollPositionProperty.GetVector3();
410 const Vector2& size = scrollSizeProperty.GetVector3().GetVectorXY();
411 const Vector3& min = scrollMinProperty.GetVector3();
412 const Vector3& max = scrollMaxProperty.GetVector3();
416 position.x = -WrapInDomain(-position.x, min.x, max.x);
417 position.y = -WrapInDomain(-position.y, min.y, max.y);
421 // clamp post position to domain
422 position.x = mClampX ? Clamp(position.x, mDomainMax.x + size.x, mDomainMin.x ) : position.x;
423 position.y = mClampY ? Clamp(position.y, mDomainMax.y + size.y, mDomainMin.y ) : position.y;
438 * This constraint updates the X overshoot property using the difference
439 * mPropertyPrePosition.x and mPropertyPosition.x, returning a relative value between 0.0f and 1.0f
441 struct OvershootXConstraint
443 OvershootXConstraint(float maxOvershoot) : mMaxOvershoot(maxOvershoot) {}
445 float operator()(const float& current,
446 const PropertyInput& scrollPrePositionProperty,
447 const PropertyInput& scrollPostPositionProperty,
448 const PropertyInput& canScrollProperty)
450 if( canScrollProperty.GetBoolean() )
452 const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
453 const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
454 float newOvershoot = scrollPrePosition.x - scrollPostPosition.x;
455 return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
464 * This constraint updates the Y overshoot property using the difference
465 * mPropertyPrePosition.y and mPropertyPosition.y, returning a relative value between 0.0f and 1.0f
467 struct OvershootYConstraint
469 OvershootYConstraint(float maxOvershoot) : mMaxOvershoot(maxOvershoot) {}
471 float operator()(const float& current,
472 const PropertyInput& scrollPrePositionProperty,
473 const PropertyInput& scrollPostPositionProperty,
474 const PropertyInput& canScrollProperty)
476 if( canScrollProperty.GetBoolean() )
478 const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
479 const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
480 float newOvershoot = scrollPrePosition.y - scrollPostPosition.y;
481 return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
490 * Internal Position-Delta Property Constraint.
492 * Generates position-delta property based on scroll-position + scroll-offset properties.
494 Vector3 InternalPositionDeltaConstraint(const Vector3& current,
495 const PropertyInput& scrollPositionProperty,
496 const PropertyInput& scrollOffsetProperty)
498 const Vector3& scrollPosition = scrollPositionProperty.GetVector3();
499 const Vector3& scrollOffset = scrollOffsetProperty.GetVector3();
501 return scrollPosition + scrollOffset;
505 * Internal Final Position Constraint
506 * The position of content is:
507 * of scroll-position + f(scroll-overshoot)
508 * where f(...) function defines how overshoot
509 * should affect final-position.
511 struct InternalFinalConstraint
513 InternalFinalConstraint(AlphaFunction functionX,
514 AlphaFunction functionY)
515 : mFunctionX(functionX),
516 mFunctionY(functionY)
520 Vector3 operator()(const Vector3& current,
521 const PropertyInput& scrollPositionProperty,
522 const PropertyInput& scrollOvershootXProperty,
523 const PropertyInput& scrollOvershootYProperty)
525 const float& overshootx = scrollOvershootXProperty.GetFloat();
526 const float& overshooty = scrollOvershootYProperty.GetFloat();
527 Vector3 offset( mFunctionX(overshootx),
528 mFunctionY(overshooty),
531 return scrollPositionProperty.GetVector3() - offset;
534 AlphaFunction mFunctionX;
535 AlphaFunction mFunctionY;
541 return Toolkit::ScrollView::New();
544 TypeRegistration typeRegistration( typeid(Toolkit::ScrollView), typeid(Toolkit::Scrollable), Create );
546 SignalConnectorType signalConnector1( typeRegistration, Toolkit::ScrollView::SIGNAL_SNAP_STARTED, &ScrollView::DoConnectSignal );
551 ///////////////////////////////////////////////////////////////////////////////////////////////////
553 ///////////////////////////////////////////////////////////////////////////////////////////////////
555 Dali::Toolkit::ScrollView ScrollView::New()
557 // Create the implementation
558 ScrollViewPtr scrollView(new ScrollView());
560 // Pass ownership to CustomActor via derived handle
561 Dali::Toolkit::ScrollView handle(*scrollView);
563 // Second-phase init of the implementation
564 // This can only be done after the CustomActor connection has been made...
565 scrollView->Initialize();
570 ScrollView::ScrollView()
573 mGestureStackDepth(0),
574 mScrollStateFlags(0),
575 mMinTouchesForPanning(1),
576 mMaxTouchesForPanning(1),
577 mLockAxis(LockPossible),
578 mScrollUpdateDistance(DEFAULT_SCROLL_UPDATE_DISTANCE),
579 mOvershootDelay(1.0f),
580 mMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT),
581 mUserMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT),
582 mSnapOvershootDuration(Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION),
583 mSnapOvershootAlphaFunction(AlphaFunctions::EaseOut),
584 mSnapDuration(Toolkit::ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION),
585 mSnapAlphaFunction(AlphaFunctions::EaseOut),
586 mMinFlickDistance(DEFAULT_MIN_FLICK_DISTANCE),
587 mFlickSpeedThreshold(DEFAULT_MIN_FLICK_SPEED_THRESHOLD),
588 mFlickDuration(Toolkit::ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION),
589 mFlickAlphaFunction(AlphaFunctions::EaseOut),
590 mAxisAutoLockGradient(Toolkit::ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT),
591 mFrictionCoefficient(Toolkit::ScrollView::DEFAULT_FRICTION_COEFFICIENT),
592 mFlickSpeedCoefficient(Toolkit::ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT),
593 mMaxFlickSpeed(Toolkit::ScrollView::DEFAULT_MAX_FLICK_SPEED),
594 mInAccessibilityPan(false),
597 mScrollInterrupted(false),
600 mTouchDownTimeoutReached(false),
601 mActorAutoSnapEnabled(false),
602 mAutoResizeContainerEnabled(false),
604 mAxisAutoLock(false),
606 mDefaultMaxOvershoot(true),
607 mCanScrollHorizontal(true),
608 mCanScrollVertical(true)
610 SetRequiresMouseWheelEvents(true);
613 void ScrollView::OnInitialize()
617 // Internal Actor, used to hide actors from enumerations.
618 // Also actors added to Internal actor appear as overlays e.g. ScrollBar components.
619 mInternalActor = Actor::New();
620 mInternalActor.SetDrawMode(DrawMode::OVERLAY);
621 self.Add(mInternalActor);
622 mInternalActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
623 mInternalActor.SetParentOrigin(ParentOrigin::CENTER);
624 mInternalActor.SetAnchorPoint(AnchorPoint::CENTER);
628 // Register Scroll Properties.
629 RegisterProperties();
631 mScrollPostPosition = mScrollPrePosition = Vector3::ZERO;
633 mMouseWheelScrollDistanceStep = Stage::GetCurrent().GetSize() * DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION;
637 mGestureStackDepth = 0;
639 EnableGestureDetection( Gesture::Type( Gesture::Pan ) );
641 // For pan, default to only 1 touch required, ignoring touches outside this range.
642 SetTouchesRequiredForPanning(1, 1, false);
644 // By default we'll allow the user to freely drag the scroll view,
645 // while disabling the other rulers.
646 RulerPtr ruler = new DefaultRuler();
650 EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator);
652 Vector3 size = GetControlSize();
653 UpdatePropertyDomain(size);
654 SetInternalConstraints();
657 void ScrollView::OnControlStageConnection()
659 DALI_LOG_SCROLL_STATE("[0x%X]", this);
663 SetScrollSensitive( false );
664 SetScrollSensitive( true );
666 if(IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator))
668 // try and make sure property notifications are set
669 EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator);
673 void ScrollView::OnControlStageDisconnection()
675 DALI_LOG_SCROLL_STATE("[0x%X]", this);
680 ScrollView::~ScrollView()
682 DALI_LOG_SCROLL_STATE("[0x%X]", this);
685 AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
687 return mSnapAlphaFunction;
690 void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
692 mSnapAlphaFunction = alpha;
695 AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
697 return mFlickAlphaFunction;
700 void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
702 mFlickAlphaFunction = alpha;
705 float ScrollView::GetScrollSnapDuration() const
707 return mSnapDuration;
710 void ScrollView::SetScrollSnapDuration(float time)
712 mSnapDuration = time;
715 float ScrollView::GetScrollFlickDuration() const
717 return mFlickDuration;
720 void ScrollView::SetScrollFlickDuration(float time)
722 mFlickDuration = time;
725 void ScrollView::ApplyEffect(Toolkit::ScrollViewEffect effect)
727 Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
729 // Assertion check to ensure effect doesn't already exist in this scrollview
730 bool effectAlreadyExistsInScrollView(false);
731 for (ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
735 effectAlreadyExistsInScrollView = true;
740 DALI_ASSERT_ALWAYS(!effectAlreadyExistsInScrollView);
742 // add effect to effects list
743 mEffects.push_back(effect);
745 // invoke Attachment request to ScrollView first
746 GetImpl(effect).Attach(self);
749 Toolkit::ScrollViewEffect ScrollView::ApplyEffect(Toolkit::ScrollView::PageEffect effect)
751 Toolkit::ScrollViewEffect scrollEffect;
754 case Toolkit::ScrollView::PageEffectNone:
758 case Toolkit::ScrollView::PageEffectOuterCube:
760 Toolkit::ScrollViewCustomEffect customEffect;
761 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
762 Vector2 pageSize = Stage::GetCurrent().GetSize();
763 // 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
764 // 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)
765 // the page moving off screen will slowly build a spacing from 0.0f to 20.0f
766 // the spacing from each page is added together for the final spacing between the two pages.
767 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));
768 customEffect.SetSwingAngleOut(ANGLE_CUSTOM_CUBE_SWING.x, Vector3(0.0f, -1.0f, 0.0f));
769 customEffect.SetSwingAnchor(AnchorPoint::CENTER, AnchorPoint::CENTER_LEFT);
770 customEffect.SetOpacityThreshold(0.7f);
773 case Toolkit::ScrollView::PageEffectDepth:
775 Toolkit::ScrollViewCustomEffect customEffect;
776 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
779 case Toolkit::ScrollView::PageEffectInnerCube:
781 Toolkit::ScrollViewCustomEffect customEffect;
782 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
783 customEffect.SetPageSpacing(Vector2(30.0f, 30.0f));
784 customEffect.SetAngledOriginPageRotation(ANGLE_CUBE_PAGE_ROTATE);
785 customEffect.SetSwingAngle(ANGLE_CUBE_PAGE_ROTATE.x, Vector3(0,-1,0));
786 customEffect.SetOpacityThreshold(0.5f);
789 case Toolkit::ScrollView::PageEffectCarousel:
791 Toolkit::ScrollViewCustomEffect customEffect;
792 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
793 customEffect.SetPageTranslation(Vector3(0,0,0), Vector3(-30, 0, 0));
794 customEffect.SetPageSpacing(Vector2(60.0f, 60.0f));
795 customEffect.SetAngledOriginPageRotation(-ANGLE_CUBE_PAGE_ROTATE);
796 customEffect.SetOpacityThreshold(0.2f, 0.6f);
799 case Toolkit::ScrollView::PageEffectSpiral:
801 Toolkit::ScrollViewCustomEffect customEffect;
802 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
804 Vector2 pageSize = Stage::GetCurrent().GetSize();
805 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));
806 //customEffect.SetSwingAngleAlphaFunctionOut(AlphaFunctions::EaseOut);
807 customEffect.SetSwingAnchor(AnchorPoint::CENTER_RIGHT);
808 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);
809 //customEffect.SetPageTranslateAlphaFunctionOut(AlphaFunctions::EaseOut);
810 customEffect.SetOpacityThreshold(0.75f, 0.6f);
811 customEffect.SetOpacityAlphaFunctionIn(AlphaFunctions::EaseInOut);
816 DALI_ASSERT_DEBUG(0 && "unknown scroll view effect");
819 RemoveConstraintsFromChildren();
822 ApplyEffect(scrollEffect);
827 void ScrollView::RemoveEffect(Toolkit::ScrollViewEffect effect)
829 Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
831 // remove effect from effects list
832 bool effectExistedInScrollView(false);
833 for (ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
837 mEffects.erase(iter);
838 effectExistedInScrollView = true;
843 // Assertion check to ensure effect existed.
844 DALI_ASSERT_ALWAYS(effectExistedInScrollView);
846 // invoke Detachment request to ScrollView last
847 GetImpl(effect).Detach(self);
850 void ScrollView::RemoveAllEffects()
852 Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
854 for (ScrollViewEffectIter effectIter = mEffects.begin(); effectIter != mEffects.end(); ++effectIter)
856 Toolkit::ScrollViewEffect effect = *effectIter;
858 // invoke Detachment request to ScrollView last
859 GetImpl(effect).Detach(self);
865 void ScrollView::ApplyConstraintToChildren(Constraint constraint)
867 ApplyConstraintToBoundActors(constraint);
870 void ScrollView::RemoveConstraintsFromChildren()
872 RemoveConstraintsFromBoundActors();
875 const RulerPtr ScrollView::GetRulerX() const
880 const RulerPtr ScrollView::GetRulerY() const
885 void ScrollView::SetRulerX(RulerPtr ruler)
889 Vector3 size = GetControlSize();
890 UpdatePropertyDomain(size);
891 UpdateMainInternalConstraint();
894 void ScrollView::SetRulerY(RulerPtr ruler)
898 Vector3 size = GetControlSize();
899 UpdatePropertyDomain(size);
900 UpdateMainInternalConstraint();
903 void ScrollView::UpdatePropertyDomain(const Vector3& size)
906 Vector3 min = mMinScroll;
907 Vector3 max = mMaxScroll;
908 bool scrollPositionChanged = false;
909 bool domainChanged = false;
911 bool canScrollVertical = false;
912 bool canScrollHorizontal = false;
913 UpdateLocalScrollProperties();
914 if(mRulerX->IsEnabled())
916 const Toolkit::RulerDomain& rulerDomain = mRulerX->GetDomain();
917 if( fabsf(min.x - rulerDomain.min) > Math::MACHINE_EPSILON_100
918 || fabsf(max.x - rulerDomain.max) > Math::MACHINE_EPSILON_100 )
920 domainChanged = true;
921 min.x = rulerDomain.min;
922 max.x = rulerDomain.max;
924 // make sure new scroll value is within new domain
925 if( mScrollPrePosition.x < min.x
926 || mScrollPrePosition.x > max.x )
928 scrollPositionChanged = true;
929 mScrollPrePosition.x = Clamp(mScrollPrePosition.x, -(max.x - size.x), -min.x);
932 if( (fabsf(rulerDomain.max - rulerDomain.min) - size.x) > Math::MACHINE_EPSILON_100 )
934 canScrollHorizontal = true;
937 else if( fabs(min.x) > Math::MACHINE_EPSILON_100
938 || fabs(max.x) > Math::MACHINE_EPSILON_100 )
940 // need to reset to 0
941 domainChanged = true;
944 canScrollHorizontal = false;
947 if(mRulerY->IsEnabled())
949 const Toolkit::RulerDomain& rulerDomain = mRulerY->GetDomain();
950 if( fabsf(min.y - rulerDomain.min) > Math::MACHINE_EPSILON_100
951 || fabsf(max.y - rulerDomain.max) > Math::MACHINE_EPSILON_100 )
953 domainChanged = true;
954 min.y = rulerDomain.min;
955 max.y = rulerDomain.max;
957 // make sure new scroll value is within new domain
958 if( mScrollPrePosition.y < min.y
959 || mScrollPrePosition.y > max.y )
961 scrollPositionChanged = true;
962 mScrollPrePosition.y = Clamp(mScrollPrePosition.y, -(max.y - size.y), -min.y);
965 if( (fabsf(rulerDomain.max - rulerDomain.min) - size.y) > Math::MACHINE_EPSILON_100 )
967 canScrollVertical = true;
970 else if( fabs(min.y) > Math::MACHINE_EPSILON_100
971 || fabs(max.y) > Math::MACHINE_EPSILON_100 )
973 // need to reset to 0
974 domainChanged = true;
977 canScrollVertical = false;
980 // avoid setting properties if possible, otherwise this will cause an entire update as well as triggering constraints using each property we update
981 if( mCanScrollVertical != canScrollVertical )
983 mCanScrollVertical = canScrollVertical;
984 self.SetProperty(mPropertyCanScrollVertical, canScrollVertical);
986 if( mCanScrollHorizontal != canScrollHorizontal )
988 mCanScrollHorizontal = canScrollHorizontal;
989 self.SetProperty(mPropertyCanScrollHorizontal, canScrollHorizontal);
991 if( scrollPositionChanged )
993 DALI_LOG_SCROLL_STATE("[0x%X] Domain Changed, setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
994 self.SetProperty(mPropertyPrePosition, mScrollPrePosition);
1000 self.SetProperty(mPropertyPositionMin, mMinScroll );
1001 self.SetProperty(mPropertyPositionMax, mMaxScroll );
1005 void ScrollView::SetScrollSensitive(bool sensitive)
1007 Actor self = Self();
1008 PanGestureDetector panGesture( GetPanGestureDetector() );
1010 DALI_LOG_SCROLL_STATE("[0x%X] sensitive: before:[%d] setting[%d]", this, int(mSensitive), int(sensitive));
1012 if((!mSensitive) && (sensitive))
1014 mSensitive = sensitive;
1015 panGesture.Attach(self);
1017 else if((mSensitive) && (!sensitive))
1019 DALI_LOG_SCROLL_STATE("[0x%X] BEFORE: panning:[%d]", this, int(mPanning));
1021 // while the scroll view is panning, the state needs to be reset.
1024 PanGesture cancelGesture( Gesture::Cancelled );
1025 OnPan( cancelGesture );
1028 panGesture.Detach(self);
1029 mSensitive = sensitive;
1031 mGestureStackDepth = 0;
1032 DALI_LOG_SCROLL_STATE("[0x%X] AFTER: panning:[%d]", this, int(mPanning));
1036 void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
1038 mMaxOvershoot.x = overshootX;
1039 mMaxOvershoot.y = overshootY;
1040 mUserMaxOvershoot = mMaxOvershoot;
1041 mDefaultMaxOvershoot = false;
1042 UpdateMainInternalConstraint();
1045 void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
1047 mSnapOvershootAlphaFunction = alpha;
1050 void ScrollView::SetSnapOvershootDuration(float duration)
1052 mSnapOvershootDuration = duration;
1055 void ScrollView::SetTouchesRequiredForPanning(unsigned int minTouches, unsigned int maxTouches, bool endOutside)
1057 PanGestureDetector panGesture( GetPanGestureDetector() );
1059 mMinTouchesForPanning = minTouches;
1060 mMaxTouchesForPanning = maxTouches;
1064 panGesture.SetMinimumTouchesRequired(minTouches);
1065 panGesture.SetMaximumTouchesRequired(maxTouches);
1069 panGesture.SetMinimumTouchesRequired(1);
1070 panGesture.SetMaximumTouchesRequired(UINT_MAX);
1074 void ScrollView::SetActorAutoSnap(bool enable)
1076 mActorAutoSnapEnabled = enable;
1079 void ScrollView::SetAutoResize(bool enable)
1081 mAutoResizeContainerEnabled = enable;
1082 // TODO: This needs a lot of issues to be addressed before working.
1085 bool ScrollView::GetWrapMode() const
1090 void ScrollView::SetWrapMode(bool enable)
1093 Self().SetProperty(mPropertyWrap, enable);
1096 int ScrollView::GetRefreshInterval() const
1098 return mScrollUpdateDistance;
1101 void ScrollView::SetRefreshInterval(int milliseconds)
1103 mScrollUpdateDistance = milliseconds;
1106 int ScrollView::GetScrollUpdateDistance() const
1108 return mScrollUpdateDistance;
1111 void ScrollView::SetScrollUpdateDistance(int distance)
1113 mScrollUpdateDistance = distance;
1116 bool ScrollView::GetAxisAutoLock() const
1118 return mAxisAutoLock;
1121 void ScrollView::SetAxisAutoLock(bool enable)
1123 mAxisAutoLock = enable;
1124 UpdateMainInternalConstraint();
1127 float ScrollView::GetAxisAutoLockGradient() const
1129 return mAxisAutoLockGradient;
1132 void ScrollView::SetAxisAutoLockGradient(float gradient)
1134 DALI_ASSERT_DEBUG( gradient >= 0.0f && gradient <= 1.0f );
1135 mAxisAutoLockGradient = gradient;
1136 UpdateMainInternalConstraint();
1139 float ScrollView::GetFrictionCoefficient() const
1141 return mFrictionCoefficient;
1144 void ScrollView::SetFrictionCoefficient(float friction)
1146 DALI_ASSERT_DEBUG( friction > 0.0f );
1147 mFrictionCoefficient = friction;
1150 float ScrollView::GetFlickSpeedCoefficient() const
1152 return mFlickSpeedCoefficient;
1155 void ScrollView::SetFlickSpeedCoefficient(float speed)
1157 mFlickSpeedCoefficient = speed;
1160 Vector2 ScrollView::GetMinimumDistanceForFlick() const
1162 return mMinFlickDistance;
1165 void ScrollView::SetMinimumDistanceForFlick( const Vector2& distance )
1167 mMinFlickDistance = distance;
1170 float ScrollView::GetMinimumSpeedForFlick() const
1172 return mFlickSpeedThreshold;
1175 void ScrollView::SetMinimumSpeedForFlick( float speed )
1177 mFlickSpeedThreshold = speed;
1180 float ScrollView::GetMaxFlickSpeed() const
1182 return mMaxFlickSpeed;
1185 void ScrollView::SetMaxFlickSpeed(float speed)
1187 mMaxFlickSpeed = speed;
1190 void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
1192 mMouseWheelScrollDistanceStep = step;
1195 Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
1197 return mMouseWheelScrollDistanceStep;
1200 unsigned int ScrollView::GetCurrentPage() const
1202 // in case animation is currently taking place.
1203 Vector3 position = GetPropertyPosition();
1205 Actor self = Self();
1206 unsigned int page = 0;
1207 unsigned int pagesPerVolume = 1;
1208 unsigned int volume = 0;
1210 // if rulerX is enabled, then get page count (columns)
1211 page = mRulerX->GetPageFromPosition(-position.x, mWrapMode);
1212 volume = mRulerY->GetPageFromPosition(-position.y, mWrapMode);
1213 pagesPerVolume = mRulerX->GetTotalPages();
1215 return volume * pagesPerVolume + page;
1218 Vector3 ScrollView::GetCurrentScrollPosition() const
1220 return -GetPropertyPosition();
1223 void ScrollView::SetScrollPosition(const Vector3& position)
1225 mScrollPrePosition = position;
1228 Vector3 ScrollView::GetDomainSize() const
1230 Vector3 size = Self().GetCurrentSize();
1232 const RulerDomain& xDomain = GetRulerX()->GetDomain();
1233 const RulerDomain& yDomain = GetRulerY()->GetDomain();
1235 Vector3 domainSize = Vector3( xDomain.max - xDomain.min, yDomain.max - yDomain.min, 0.0f ) - size;
1239 void ScrollView::TransformTo(const Vector3& position,
1240 DirectionBias horizontalBias, DirectionBias verticalBias)
1242 TransformTo(position, mSnapDuration, horizontalBias, verticalBias);
1245 void ScrollView::TransformTo(const Vector3& position, float duration,
1246 DirectionBias horizontalBias, DirectionBias verticalBias)
1248 Actor self( Self() );
1250 // Guard against destruction during signal emission
1251 // Note that Emit() methods are called indirectly e.g. from within ScrollView::AnimateTo()
1252 Toolkit::ScrollView handle( GetOwner() );
1254 DALI_LOG_SCROLL_STATE("[0x%X] pos[%.2f,%.2f], duration[%.2f] bias[%d, %d]",
1255 this, position.x, position.y, duration, int(horizontalBias), int(verticalBias));
1257 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1258 self.SetProperty( mPropertyScrollStartPagePosition, currentScrollPosition );
1260 if( mScrolling ) // are we interrupting a current scroll?
1262 // set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete.
1264 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
1265 mScrollCompletedSignalV2.Emit( currentScrollPosition );
1268 if( mPanning ) // are we interrupting a current pan?
1270 DALI_LOG_SCROLL_STATE("[0x%X] Interrupting Pan, set to false", this );
1272 mGestureStackDepth = 0;
1273 self.SetProperty( mPropertyPanning, false );
1275 if( mScrollMainInternalPrePositionConstraint )
1277 self.RemoveConstraint(mScrollMainInternalPrePositionConstraint);
1281 self.SetProperty(mPropertyScrolling, true);
1284 DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignalV2 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
1285 mScrollStartedSignalV2.Emit( currentScrollPosition );
1286 bool animating = AnimateTo(-position,
1287 Vector3::ONE * duration,
1296 // if not animating, then this pan has completed right now.
1297 self.SetProperty(mPropertyScrolling, false);
1300 // If we have no duration, then in the next update frame, we will be at the position specified as we just set.
1301 // In this scenario, we cannot return the currentScrollPosition as this is out-of-date and should instead return the requested final position
1302 Vector3 completedPosition( currentScrollPosition );
1303 if( duration <= Math::MACHINE_EPSILON_10 )
1305 completedPosition = position;
1308 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 2 [%.2f, %.2f]", this, completedPosition.x, completedPosition.y);
1309 SetScrollUpdateNotification(false);
1310 mScrollCompletedSignalV2.Emit( completedPosition );
1314 void ScrollView::ScrollTo(const Vector3& position)
1316 ScrollTo(position, mSnapDuration );
1319 void ScrollView::ScrollTo(const Vector3& position, float duration)
1321 ScrollTo(position, duration, DirectionBiasNone, DirectionBiasNone);
1324 void ScrollView::ScrollTo(const Vector3& position, float duration,
1325 DirectionBias horizontalBias, DirectionBias verticalBias)
1327 DALI_LOG_SCROLL_STATE("[0x%X] position[%.2f, %.2f] duration[%.2f]",
1328 this, position.x, position.y, duration, int(horizontalBias), int(verticalBias));
1330 TransformTo(position, duration, horizontalBias, verticalBias);
1333 void ScrollView::ScrollTo(unsigned int page)
1335 ScrollTo(page, mSnapDuration);
1338 void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
1341 unsigned int volume;
1342 unsigned int libraries;
1344 // The position to scroll to is continuous and linear
1345 // unless a domain has been enabled on the X axis.
1346 // or if WrapMode has been enabled.
1347 bool carryX = mRulerX->GetDomain().enabled | mWrapMode;
1348 bool carryY = mRulerY->GetDomain().enabled | mWrapMode;
1350 position.x = mRulerX->GetPositionFromPage(page, volume, carryX);
1351 position.y = mRulerY->GetPositionFromPage(volume, libraries, carryY);
1353 ScrollTo(position, duration, bias, bias);
1356 void ScrollView::ScrollTo(Actor &actor)
1358 ScrollTo(actor, mSnapDuration);
1361 void ScrollView::ScrollTo(Actor &actor, float duration)
1363 DALI_ASSERT_ALWAYS(actor.GetParent() == Self());
1365 Actor self = Self();
1366 Vector3 size = self.GetCurrentSize();
1367 Vector3 position = actor.GetCurrentPosition();
1368 position -= GetPropertyPrePosition();
1370 ScrollTo(Vector3(position.x - size.width * 0.5f, position.y - size.height * 0.5f, 0.0f), duration);
1373 Actor ScrollView::FindClosestActor()
1375 Actor self = Self();
1376 Vector3 size = self.GetCurrentSize();
1378 return FindClosestActorToPosition(Vector3(size.width * 0.5f,size.height * 0.5f,0.0f));
1381 Actor ScrollView::FindClosestActorToPosition(const Vector3& position, FindDirection dirX, FindDirection dirY, FindDirection dirZ)
1384 float closestDistance2 = 0.0f;
1385 Vector3 actualPosition = position;
1387 unsigned int numChildren = Self().GetChildCount();
1389 for(unsigned int i = 0; i < numChildren; ++i)
1391 Actor child = Self().GetChildAt(i);
1393 if(mInternalActor == child) // ignore internal actor.
1398 Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
1400 Vector3 delta = childPosition - actualPosition;
1402 // X-axis checking (only find Actors to the [dirX] of actualPosition)
1403 if(dirX > All) // != All,None
1405 FindDirection deltaH = delta.x > 0 ? Right : Left;
1412 // Y-axis checking (only find Actors to the [dirY] of actualPosition)
1413 if(dirY > All) // != All,None
1415 FindDirection deltaV = delta.y > 0 ? Down : Up;
1422 // Z-axis checking (only find Actors to the [dirZ] of actualPosition)
1423 if(dirZ > All) // != All,None
1425 FindDirection deltaV = delta.y > 0 ? In : Out;
1432 // compare child to closest child in terms of distance.
1433 float distance2 = 0.0f;
1435 // distance2 = the Square of the relevant dimensions of delta
1438 distance2 += delta.x * delta.x;
1443 distance2 += delta.y * delta.y;
1448 distance2 += delta.z * delta.z;
1451 if(closestChild) // Next time.
1453 if(distance2 < closestDistance2)
1455 closestChild = child;
1456 closestDistance2 = distance2;
1461 closestChild = child;
1462 closestDistance2 = distance2;
1466 return closestChild;
1469 bool ScrollView::ScrollToSnapPoint()
1471 DALI_LOG_SCROLL_STATE("[0x%X]", this );
1472 Vector2 stationaryVelocity = Vector2(0.0f, 0.0f);
1473 return SnapWithVelocity( stationaryVelocity );
1476 // TODO: In situations where axes are different (X snap, Y free)
1477 // Each axis should really have their own independent animation (time and equation)
1478 // Consider, X axis snapping to nearest grid point (EaseOut over fixed time)
1479 // Consider, Y axis simulating physics to arrive at a point (Physics equation over variable time)
1480 // Currently, the axes have been split however, they both use the same EaseOut equation.
1481 bool ScrollView::SnapWithVelocity(Vector2 velocity)
1483 // Animator takes over now, touches are assumed not to interfere.
1484 // And if touches do interfere, then we'll stop animation, update PrePosition
1485 // to current mScroll's properties, and then resume.
1486 // Note: For Flicking this may work a bit different...
1488 float angle = atan2(velocity.y, velocity.x);
1489 float speed2 = velocity.LengthSquared();
1490 AlphaFunction alphaFunction = mSnapAlphaFunction;
1491 Vector3 positionDuration = Vector3::ONE * mSnapDuration;
1494 FindDirection horizontal = None;
1495 FindDirection vertical = None;
1497 // orthoAngleRange = Angle tolerance within the Exact N,E,S,W direction
1498 // that will be accepted as a general N,E,S,W flick direction.
1500 const float orthoAngleRange = FLICK_ORTHO_ANGLE_RANGE * M_PI / 180.0f;
1501 const float flickSpeedThreshold2 = mFlickSpeedThreshold * mFlickSpeedThreshold;
1503 Vector3 positionSnap = mScrollPrePosition;
1505 // Flick logic X Axis
1507 if(mRulerX->IsEnabled() && mLockAxis != LockHorizontal)
1511 if( speed2 > flickSpeedThreshold2 || // exceeds flick threshold
1512 mInAccessibilityPan ) // With AccessibilityPan its easier to move between snap positions
1514 if((angle >= -orthoAngleRange) && (angle < orthoAngleRange)) // Swiping East
1516 biasX = 0.0f, horizontal = Left;
1518 // This guards against an error where no movement occurs, due to the flick finishing
1519 // before the update-thread has advanced mScrollPostPosition past the the previous snap point.
1520 positionSnap.x += 1.0f;
1522 else if((angle >= M_PI-orthoAngleRange) || (angle < -M_PI+orthoAngleRange)) // Swiping West
1524 biasX = 1.0f, horizontal = Right;
1526 // This guards against an error where no movement occurs, due to the flick finishing
1527 // before the update-thread has advanced mScrollPostPosition past the the previous snap point.
1528 positionSnap.x -= 1.0f;
1533 // Flick logic Y Axis
1535 if(mRulerY->IsEnabled() && mLockAxis != LockVertical)
1539 if( speed2 > flickSpeedThreshold2 || // exceeds flick threshold
1540 mInAccessibilityPan ) // With AccessibilityPan its easier to move between snap positions
1542 if((angle >= M_PI_2-orthoAngleRange) && (angle < M_PI_2+orthoAngleRange)) // Swiping South
1544 biasY = 0.0f, vertical = Up;
1546 else if((angle >= -M_PI_2-orthoAngleRange) && (angle < -M_PI_2+orthoAngleRange)) // Swiping North
1548 biasY = 1.0f, vertical = Down;
1553 // isFlick: Whether this gesture is a flick or not.
1554 bool isFlick = (horizontal != All || vertical != All);
1555 // isFreeFlick: Whether this gesture is a flick under free panning criteria.
1556 bool isFreeFlick = velocity.LengthSquared() > (FREE_FLICK_SPEED_THRESHOLD*FREE_FLICK_SPEED_THRESHOLD);
1558 if(isFlick || isFreeFlick)
1560 positionDuration = Vector3::ONE * mFlickDuration;
1561 alphaFunction = mFlickAlphaFunction;
1564 // Calculate next positionSnap ////////////////////////////////////////////////////////////
1566 if(mActorAutoSnapEnabled)
1568 Vector3 size = Self().GetCurrentSize();
1570 Actor child = FindClosestActorToPosition( Vector3(size.width * 0.5f,size.height * 0.5f,0.0f), horizontal, vertical );
1572 if(!child && isFlick )
1574 // If we conducted a direction limited search and found no actor, then just snap to the closest actor.
1575 child = FindClosestActorToPosition( Vector3(size.width * 0.5f,size.height * 0.5f,0.0f) );
1580 Vector3 position = Self().GetProperty<Vector3>(mPropertyPosition);
1582 // Get center-point of the Actor.
1583 Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
1585 if(mRulerX->IsEnabled())
1587 positionSnap.x = position.x - childPosition.x + size.width * 0.5f;
1589 if(mRulerY->IsEnabled())
1591 positionSnap.y = position.y - childPosition.y + size.height * 0.5f;
1596 Vector3 startPosition = positionSnap;
1597 positionSnap.x = -mRulerX->Snap(-positionSnap.x, biasX); // NOTE: X & Y rulers think in -ve coordinate system.
1598 positionSnap.y = -mRulerY->Snap(-positionSnap.y, biasY); // That is scrolling RIGHT (e.g. 100.0, 0.0) means moving LEFT.
1600 Vector3 clampDelta(Vector3::ZERO);
1601 ClampPosition(positionSnap);
1603 if( (mRulerX->GetType() == Ruler::Free || mRulerY->GetType() == Ruler::Free)
1604 && isFreeFlick && !mActorAutoSnapEnabled)
1606 // Calculate target position based on velocity of flick.
1608 // a = Deceleration (Set to diagonal stage length * friction coefficient)
1609 // u = Initial Velocity (Flick velocity)
1610 // v = 0 (Final Velocity)
1611 // t = Time (Velocity / Deceleration)
1612 Vector2 stageSize = Stage::GetCurrent().GetSize();
1613 float stageLength = Vector3(stageSize.x, stageSize.y, 0.0f).Length();
1614 float a = (stageLength * mFrictionCoefficient);
1615 Vector3 u = Vector3(velocity.x, velocity.y, 0.0f) * mFlickSpeedCoefficient;
1616 float speed = u.Length();
1619 // TODO: Change this to a decay function. (faster you flick, the slower it should be)
1620 speed = std::min(speed, stageLength * mMaxFlickSpeed );
1622 alphaFunction = ConstantDecelerationAlphaFunction;
1624 float t = speed / a;
1626 if(mRulerX->IsEnabled() && mRulerX->GetType() == Ruler::Free)
1628 positionSnap.x += t*u.x*0.5f;
1631 if(mRulerY->IsEnabled() && mRulerY->GetType() == Ruler::Free)
1633 positionSnap.y += t*u.y*0.5f;
1636 clampDelta = positionSnap;
1637 ClampPosition(positionSnap);
1638 if((positionSnap - startPosition).LengthSquared() > Math::MACHINE_EPSILON_0)
1640 clampDelta -= positionSnap;
1641 clampDelta.x = clampDelta.x > 0.0f ? std::min(clampDelta.x, mMaxOvershoot.x) : std::max(clampDelta.x, -mMaxOvershoot.x);
1642 clampDelta.y = clampDelta.y > 0.0f ? std::min(clampDelta.y, mMaxOvershoot.y) : std::max(clampDelta.y, -mMaxOvershoot.y);
1646 clampDelta = Vector3::ZERO;
1649 // If Axis is Free and has velocity, then calculate time taken
1650 // to reach target based on velocity in axis.
1651 if(mRulerX->IsEnabled() && mRulerX->GetType() == Ruler::Free)
1653 float deltaX = fabsf(startPosition.x - positionSnap.x);
1655 if(fabsf(u.x) > Math::MACHINE_EPSILON_1)
1657 positionDuration.x = fabsf(deltaX / u.x);
1661 positionDuration.x = 0;
1665 if(mRulerY->IsEnabled() && mRulerY->GetType() == Ruler::Free)
1667 float deltaY = fabsf(startPosition.y - positionSnap.y);
1669 if(fabsf(u.y) > Math::MACHINE_EPSILON_1)
1671 positionDuration.y = fabsf(deltaY / u.y);
1675 positionDuration.y = 0;
1679 positionSnap += clampDelta;
1681 bool animating = AnimateTo(positionSnap, positionDuration,
1682 alphaFunction, false,
1683 DirectionBiasNone, DirectionBiasNone,
1684 isFlick || isFreeFlick ? Flick : Snap);
1689 void ScrollView::StopAnimation(void)
1691 // Clear Snap animation if exists.
1692 StopAnimation(mInternalXAnimation);
1693 StopAnimation(mInternalYAnimation);
1694 mScrollStateFlags = 0;
1695 // remove scroll animation flags
1696 HandleStoppedAnimation();
1699 void ScrollView::StopAnimation(Animation& animation)
1708 bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDuration,
1709 AlphaFunction alpha, bool findShortcuts,
1710 DirectionBias horizontalBias, DirectionBias verticalBias,
1713 // Here we perform an animation on a number of properties (depending on which have changed)
1714 // The animation is applied to all ScrollBases
1715 Actor self = Self();
1716 mScrollTargetPosition = position;
1717 float totalDuration = 0.0f;
1719 bool positionChanged = (mScrollTargetPosition != mScrollPostPosition);
1723 totalDuration = std::max(totalDuration, positionDuration.x);
1724 totalDuration = std::max(totalDuration, positionDuration.y);
1728 // try to animate for a frame, on some occasions update will be changing scroll value while event side thinks it hasnt changed
1729 totalDuration = 0.01f;
1730 positionChanged = true;
1735 // Position Delta ///////////////////////////////////////////////////////
1738 if(mWrapMode && findShortcuts)
1740 // In Wrap Mode, the shortest distance is a little less intuitive...
1741 const RulerDomain rulerDomainX = mRulerX->GetDomain();
1742 const RulerDomain rulerDomainY = mRulerY->GetDomain();
1744 if(mRulerX->IsEnabled())
1746 float dir = VectorInDomain(-mScrollPrePosition.x, -mScrollTargetPosition.x, rulerDomainX.min, rulerDomainX.max, horizontalBias);
1747 mScrollTargetPosition.x = mScrollPrePosition.x + -dir;
1750 if(mRulerY->IsEnabled())
1752 float dir = VectorInDomain(-mScrollPrePosition.y, -mScrollTargetPosition.y, rulerDomainY.min, rulerDomainY.max, verticalBias);
1753 mScrollTargetPosition.y = mScrollPrePosition.y + -dir;
1757 // note we have two separate animations for X & Y, this deals with sliding diagonally and hitting
1758 // a horizonal/vertical wall.delay
1759 AnimateInternalXTo(mScrollTargetPosition.x, positionDuration.x, alpha);
1760 AnimateInternalYTo(mScrollTargetPosition.y, positionDuration.y, alpha);
1762 if( !(mScrollStateFlags & SCROLL_ANIMATION_FLAGS) )
1764 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollTargetPosition.x, mScrollTargetPosition.y );
1765 self.SetProperty(mPropertyPrePosition, mScrollTargetPosition);
1766 mScrollPrePosition = mScrollTargetPosition;
1767 mScrollPostPosition = mScrollTargetPosition;
1768 WrapPosition(mScrollPostPosition);
1771 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 );
1772 DALI_LOG_SCROLL_STATE("[0x%X] mPropertyPrePosition[%.2f, %.2f], mPropertyPosition[%.2f, %.2f]", this, self.GetProperty( mPropertyPrePosition ).Get<Vector3>().x, self.GetProperty( mPropertyPrePosition ).Get<Vector3>().y, self.GetProperty( mPropertyPosition ).Get<Vector3>().x, self.GetProperty( mPropertyPosition ).Get<Vector3>().y );
1775 SetScrollUpdateNotification(true);
1777 // Always send a snap event when AnimateTo is called.
1778 Toolkit::ScrollView::SnapEvent snapEvent;
1779 snapEvent.type = snapType;
1780 snapEvent.position = -mScrollTargetPosition;
1781 snapEvent.duration = totalDuration;
1783 DALI_LOG_SCROLL_STATE("[0x%X] mSnapStartedSignalV2 [%.2f, %.2f]", this, snapEvent.position.x, snapEvent.position.y);
1784 mSnapStartedSignalV2.Emit( snapEvent );
1786 return (mScrollStateFlags & SCROLL_ANIMATION_FLAGS) != 0;
1789 void ScrollView::SetOvershootEnabled(bool enabled)
1791 if(enabled && !mOvershootIndicator)
1793 mOvershootIndicator = ScrollOvershootIndicator::New();
1797 mMaxOvershoot = OVERSCROLL_CLAMP;
1798 mOvershootIndicator->AttachToScrollable(*this);
1802 mMaxOvershoot = mUserMaxOvershoot;
1803 mOvershootIndicator->DetachFromScrollable(*this);
1805 UpdateMainInternalConstraint();
1808 void ScrollView::AddOverlay(Actor actor)
1810 mInternalActor.Add( actor );
1813 void ScrollView::RemoveOverlay(Actor actor)
1815 mInternalActor.Remove( actor );
1818 void ScrollView::SetOvershootEffectColor( const Vector4& color )
1820 mOvershootEffectColor = color;
1821 if( mOvershootIndicator )
1823 mOvershootIndicator->SetOvershootEffectColor( color );
1827 void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
1829 PanGestureDetector panGesture( GetPanGestureDetector() );
1831 // First remove just in case we have some set, then add.
1832 panGesture.RemoveDirection( direction );
1833 panGesture.AddDirection( direction, threshold );
1836 void ScrollView::RemoveScrollingDirection( Radian direction )
1838 PanGestureDetector panGesture( GetPanGestureDetector() );
1839 panGesture.RemoveDirection( direction );
1842 Toolkit::ScrollView::SnapStartedSignalV2& ScrollView::SnapStartedSignal()
1844 return mSnapStartedSignalV2;
1847 void ScrollView::FindAndUnbindActor(Actor child)
1852 Vector3 ScrollView::GetPropertyPrePosition() const
1854 Vector3 position = Self().GetProperty<Vector3>(mPropertyPrePosition);
1855 WrapPosition(position);
1859 Vector3 ScrollView::GetPropertyPosition() const
1861 Vector3 position = Self().GetProperty<Vector3>(mPropertyPosition);
1862 WrapPosition(position);
1867 void ScrollView::HandleStoppedAnimation()
1869 SetScrollUpdateNotification(false);
1872 void ScrollView::HandleSnapAnimationFinished()
1874 // Emit Signal that scrolling has completed.
1876 Actor self = Self();
1877 self.SetProperty(mPropertyScrolling, false);
1879 Vector3 deltaPosition(mScrollPrePosition);
1881 UpdateLocalScrollProperties();
1882 WrapPosition(mScrollPrePosition);
1883 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
1884 self.SetProperty(mPropertyPrePosition, mScrollPrePosition);
1886 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1887 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 3 current[%.2f, %.2f], mScrollTargetPosition[%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y, -mScrollTargetPosition.x, -mScrollTargetPosition.y );
1888 mScrollCompletedSignalV2.Emit( currentScrollPosition );
1890 mDomainOffset += deltaPosition - mScrollPostPosition;
1891 self.SetProperty(mPropertyDomainOffset, mDomainOffset);
1892 HandleStoppedAnimation();
1895 void ScrollView::SetScrollUpdateNotification( bool enabled )
1897 Actor self = Self();
1898 if( mScrollXUpdateNotification )
1900 // disconnect now to avoid a notification before removed from update thread
1901 mScrollXUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
1902 self.RemovePropertyNotification(mScrollXUpdateNotification);
1903 mScrollXUpdateNotification.Reset();
1907 mScrollXUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 0, StepCondition(mScrollUpdateDistance, 0.0f));
1908 mScrollXUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification );
1910 if( mScrollYUpdateNotification )
1912 // disconnect now to avoid a notification before removed from update thread
1913 mScrollYUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
1914 self.RemovePropertyNotification(mScrollYUpdateNotification);
1915 mScrollYUpdateNotification.Reset();
1919 mScrollYUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 1, StepCondition(mScrollUpdateDistance, 0.0f));
1920 mScrollYUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification );
1924 void ScrollView::OnScrollUpdateNotification(Dali::PropertyNotification& source)
1926 // Guard against destruction during signal emission
1927 Toolkit::ScrollView handle( GetOwner() );
1929 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1930 mScrollUpdatedSignalV2.Emit( currentScrollPosition );
1933 bool ScrollView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1935 Dali::BaseHandle handle( object );
1937 bool connected( true );
1938 Toolkit::ScrollView view = Toolkit::ScrollView::DownCast( handle );
1940 if( Toolkit::ScrollView::SIGNAL_SNAP_STARTED == signalName )
1942 view.SnapStartedSignal().Connect( tracker, functor );
1946 // signalName does not match any signal
1953 void ScrollView::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1955 // need to update domain properties for new size
1956 UpdatePropertyDomain(targetSize);
1959 void ScrollView::OnControlSizeSet( const Vector3& size )
1961 // need to update domain properties for new size
1962 if( mDefaultMaxOvershoot )
1964 mUserMaxOvershoot.x = size.x * 0.5f;
1965 mUserMaxOvershoot.y = size.y * 0.5f;
1966 if( !IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
1968 mMaxOvershoot = mUserMaxOvershoot;
1971 UpdatePropertyDomain(size);
1972 UpdateMainInternalConstraint();
1973 if( IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
1975 mOvershootIndicator->Reset();
1979 void ScrollView::OnChildAdd(Actor& child)
1987 void ScrollView::OnChildRemove(Actor& child)
1989 // TODO: Actor needs a RemoveConstraint method to take out an individual constraint.
1993 void ScrollView::OnPropertySet( Property::Index index, Property::Value propertyValue )
1995 Actor self = Self();
1996 if( index == mPropertyPrePosition )
1998 DALI_LOG_SCROLL_STATE("[0x%X]: mPropertyPrePosition[%.2f, %.2f]", this, propertyValue.Get<Vector3>().x, propertyValue.Get<Vector3>().y);
1999 propertyValue.Get(mScrollPrePosition);
2003 void ScrollView::StartTouchDownTimer()
2005 if ( !mTouchDownTimer )
2007 mTouchDownTimer = Timer::New( TOUCH_DOWN_TIMER_INTERVAL );
2008 mTouchDownTimer.TickSignal().Connect( this, &ScrollView::OnTouchDownTimeout );
2011 mTouchDownTimer.Start();
2014 void ScrollView::StopTouchDownTimer()
2016 if ( mTouchDownTimer )
2018 mTouchDownTimer.Stop();
2022 bool ScrollView::OnTouchDownTimeout()
2024 DALI_LOG_SCROLL_STATE("[0x%X]", this);
2026 mTouchDownTimeoutReached = true;
2028 unsigned int currentScrollStateFlags( mScrollStateFlags ); // Cleared in StopAnimation so keep local copy for comparison
2029 if( currentScrollStateFlags & (SCROLL_ANIMATION_FLAGS | SNAP_ANIMATION_FLAGS) )
2031 DALI_LOG_SCROLL_STATE("[0x%X] Scrolling Or snapping flags set, stopping animation", this);
2034 if( currentScrollStateFlags & SCROLL_ANIMATION_FLAGS )
2036 DALI_LOG_SCROLL_STATE("[0x%X] Scrolling flags set, emitting signal", this);
2038 mScrollInterrupted = true;
2039 // reset domain offset as scrolling from original plane.
2040 mDomainOffset = Vector3::ZERO;
2041 Self().SetProperty(mPropertyDomainOffset, Vector3::ZERO);
2043 UpdateLocalScrollProperties();
2044 Vector3 currentScrollPosition = GetCurrentScrollPosition();
2045 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 4 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
2046 mScrollCompletedSignalV2.Emit( currentScrollPosition );
2053 bool ScrollView::OnTouchEvent(const TouchEvent& event)
2057 DALI_LOG_SCROLL_STATE("[0x%X], Not Sensitive, ignoring", this);
2059 // Ignore this touch event, if scrollview is insensitive.
2063 // Ignore events with multiple-touch points
2064 if (event.GetPointCount() != 1)
2066 DALI_LOG_SCROLL_STATE("[0x%X], multiple touch, ignoring", this);
2071 const TouchPoint::State pointState = event.GetPoint(0).state;
2072 if( pointState == TouchPoint::Down )
2074 DALI_LOG_SCROLL_STATE("[0x%X] Down", this);
2076 if(mGestureStackDepth==0)
2078 mTouchDownTime = event.time;
2080 // This allows time for a pan-gesture to start, to avoid breaking snap-animation behavior with fast flicks.
2081 // If touch-down does not become a pan (after timeout interval), then snap-animation can be interrupted.
2082 mTouchDownTimeoutReached = false;
2083 mScrollInterrupted = false;
2084 StartTouchDownTimer();
2087 else if( ( pointState == TouchPoint::Up ) ||
2088 ( ( pointState == TouchPoint::Interrupted ) && ( event.GetPoint(0).hitActor == Self() ) ) )
2090 DALI_LOG_SCROLL_STATE("[0x%X] %s", this, ( ( pointState == TouchPoint::Up ) ? "Up" : "Interrupted" ) );
2092 StopTouchDownTimer();
2094 // if the user touches and releases without enough movement to go
2095 // into a gesture state, then we should snap to nearest point.
2096 // otherwise our scroll could be stopped (interrupted) half way through an animation.
2097 if(mGestureStackDepth==0 && mTouchDownTimeoutReached)
2099 if( ( event.GetPoint(0).state == TouchPoint::Interrupted ) ||
2100 ( ( event.time - mTouchDownTime ) >= MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET ) )
2102 // Reset the velocity only if down was received a while ago
2103 mLastVelocity = Vector2( 0.0f, 0.0f );
2106 UpdateLocalScrollProperties();
2107 // Only finish the transform if scrolling was interrupted on down or if we are scrolling
2108 if ( mScrollInterrupted || mScrolling )
2110 DALI_LOG_SCROLL_STATE("[0x%X] Calling FinishTransform", this);
2115 mTouchDownTimeoutReached = false;
2116 mScrollInterrupted = false;
2122 bool ScrollView::OnMouseWheelEvent(const MouseWheelEvent& event)
2126 // Ignore this mouse wheel event, if scrollview is insensitive.
2130 Vector3 targetScrollPosition = GetPropertyPosition();
2132 if(mRulerX->IsEnabled() && !mRulerY->IsEnabled())
2134 // If only the ruler in the X axis is enabled, scroll in the X axis.
2135 if(mRulerX->GetType() == Ruler::Free)
2137 // Free panning mode
2138 targetScrollPosition.x += event.z * mMouseWheelScrollDistanceStep.x;
2139 ClampPosition(targetScrollPosition);
2140 ScrollTo(-targetScrollPosition);
2142 else if(!mScrolling)
2144 // Snap mode, only respond to the event when the previous snap animation is finished.
2145 ScrollTo(GetCurrentPage() - event.z);
2150 // If the ruler in the Y axis is enabled, scroll in the Y axis.
2151 if(mRulerY->GetType() == Ruler::Free)
2153 // Free panning mode
2154 targetScrollPosition.y += event.z * mMouseWheelScrollDistanceStep.y;
2155 ClampPosition(targetScrollPosition);
2156 ScrollTo(-targetScrollPosition);
2158 else if(!mScrolling)
2160 // Snap mode, only respond to the event when the previous snap animation is finished.
2161 ScrollTo(GetCurrentPage() - event.z * mRulerX->GetTotalPages());
2168 void ScrollView::ResetScrolling()
2170 Actor self = Self();
2171 self.GetProperty(mPropertyPosition).Get(mScrollPostPosition);
2172 mScrollPrePosition = mScrollPostPosition;
2173 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPostPosition.x, mScrollPostPosition.y );
2174 self.SetProperty(mPropertyPrePosition, mScrollPostPosition);
2177 void ScrollView::UpdateLocalScrollProperties()
2179 Actor self = Self();
2180 self.GetProperty(mPropertyPrePosition).Get(mScrollPrePosition);
2181 self.GetProperty(mPropertyPosition).Get(mScrollPostPosition);
2184 // private functions
2186 void ScrollView::PreAnimatedScrollSetup()
2188 // mPropertyPrePosition is our unclamped property with wrapping
2189 // mPropertyPosition is our final scroll position after clamping
2191 Actor self = Self();
2193 Vector3 deltaPosition(mScrollPostPosition);
2194 WrapPosition(mScrollPostPosition);
2195 mDomainOffset += deltaPosition - mScrollPostPosition;
2196 Self().SetProperty(mPropertyDomainOffset, mDomainOffset);
2198 if( mScrollStateFlags & SCROLL_X_STATE_MASK )
2200 // already performing animation on internal x position
2201 StopAnimation(mInternalXAnimation);
2204 if( mScrollStateFlags & SCROLL_Y_STATE_MASK )
2206 // already performing animation on internal y position
2207 StopAnimation(mInternalYAnimation);
2210 mScrollStateFlags = 0;
2212 // Update Actor position with this wrapped value.
2215 void ScrollView::FinaliseAnimatedScroll()
2217 // TODO - common animation finishing code in here
2220 void ScrollView::AnimateInternalXTo( float position, float duration, AlphaFunction alpha )
2222 StopAnimation(mInternalXAnimation);
2224 if( duration > Math::MACHINE_EPSILON_10 )
2226 Actor self = Self();
2227 DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(mPropertyPrePosition).Get<Vector3>().x, position );
2228 mInternalXAnimation = Animation::New(duration);
2229 DALI_LOG_SCROLL_STATE("[0x%X], mInternalXAnimation[0x%X]", this, mInternalXAnimation.GetObjectPtr() );
2230 mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
2231 mInternalXAnimation.AnimateTo( Property(self, mPropertyPrePosition, 0), position, alpha, duration);
2232 mInternalXAnimation.Play();
2234 // erase current state flags
2235 mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
2236 // add internal animation state flag
2237 mScrollStateFlags |= AnimatingInternalX;
2241 void ScrollView::AnimateInternalYTo( float position, float duration, AlphaFunction alpha )
2243 StopAnimation(mInternalYAnimation);
2245 if( duration > Math::MACHINE_EPSILON_10 )
2247 Actor self = Self();
2248 DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(mPropertyPrePosition).Get<Vector3>().y, position );
2249 mInternalYAnimation = Animation::New(duration);
2250 DALI_LOG_SCROLL_STATE("[0x%X], mInternalYAnimation[0x%X]", this, mInternalYAnimation.GetObjectPtr() );
2251 mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
2252 mInternalYAnimation.AnimateTo( Property(self, mPropertyPrePosition, 1), position, alpha, TimePeriod(duration));
2253 mInternalYAnimation.Play();
2255 // erase current state flags
2256 mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
2257 // add internal animation state flag
2258 mScrollStateFlags |= AnimatingInternalY;
2262 void ScrollView::OnScrollAnimationFinished( Animation& source )
2264 // Guard against destruction during signal emission
2265 // Note that ScrollCompletedSignal is emitted from HandleSnapAnimationFinished()
2266 Toolkit::ScrollView handle( GetOwner() );
2268 bool scrollingFinished = false;
2270 // update our local scroll positions
2271 UpdateLocalScrollProperties();
2273 if( source == mInternalXAnimation )
2275 DALI_LOG_SCROLL_STATE("[0x%X] mInternalXAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalXAnimation.GetObjectPtr(), mScrollTargetPosition.x, Self().GetProperty(mPropertyPrePosition).Get<Vector3>().x, mScrollPostPosition.x );
2277 if( !(mScrollStateFlags & AnimatingInternalY) )
2279 scrollingFinished = true;
2281 mInternalXAnimation.Reset();
2282 // wrap pre scroll x position and set it
2285 const RulerDomain rulerDomain = mRulerX->GetDomain();
2286 mScrollPrePosition.x = -WrapInDomain(-mScrollPrePosition.x, rulerDomain.min, rulerDomain.max);
2287 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
2288 handle.SetProperty(mPropertyPrePosition, mScrollPrePosition);
2290 SnapInternalXTo(mScrollPostPosition.x);
2293 if( source == mInternalYAnimation )
2295 DALI_LOG_SCROLL_STATE("[0x%X] mInternalYAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalYAnimation.GetObjectPtr(), mScrollTargetPosition.y, Self().GetProperty(mPropertyPrePosition).Get<Vector3>().y, mScrollPostPosition.y );
2297 if( !(mScrollStateFlags & AnimatingInternalX) )
2299 scrollingFinished = true;
2301 mInternalYAnimation.Reset();
2304 // wrap pre scroll y position and set it
2305 const RulerDomain rulerDomain = mRulerY->GetDomain();
2306 mScrollPrePosition.y = -WrapInDomain(-mScrollPrePosition.y, rulerDomain.min, rulerDomain.max);
2307 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
2308 handle.SetProperty(mPropertyPrePosition, mScrollPrePosition);
2310 SnapInternalYTo(mScrollPostPosition.y);
2313 DALI_LOG_SCROLL_STATE("[0x%X] scrollingFinished[%d] Animation[0x%X]", this, scrollingFinished, source.GetObjectPtr());
2315 if(scrollingFinished)
2317 HandleSnapAnimationFinished();
2321 void ScrollView::OnSnapInternalPositionFinished( Animation& source )
2323 Actor self = Self();
2324 UpdateLocalScrollProperties();
2325 if( source == mInternalXAnimation )
2327 DALI_LOG_SCROLL_STATE("[0x%X] Finished X PostPosition Animation", this );
2329 // clear internal x animation flags
2330 mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
2331 mInternalXAnimation.Reset();
2332 WrapPosition(mScrollPrePosition);
2334 if( source == mInternalYAnimation )
2336 DALI_LOG_SCROLL_STATE("[0x%X] Finished Y PostPosition Animation", this );
2338 mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
2339 mInternalYAnimation.Reset();
2340 WrapPosition(mScrollPrePosition);
2344 void ScrollView::SnapInternalXTo(float position)
2346 Actor self = Self();
2348 StopAnimation(mInternalXAnimation);
2350 // erase current state flags
2351 mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
2353 // if internal x not equal to inputed parameter, animate it
2354 float duration = std::min(fabsf((position - mScrollPrePosition.x) / mMaxOvershoot.x) * mSnapOvershootDuration, mSnapOvershootDuration);
2355 DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration );
2356 if( duration > Math::MACHINE_EPSILON_1 )
2358 DALI_LOG_SCROLL_STATE("[0x%X] Starting X Snap Animation to[%.2f]", this, position );
2360 mInternalXAnimation = Animation::New(duration);
2361 mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
2362 mInternalXAnimation.AnimateTo(Property(self, mPropertyPrePosition, 0), position);
2363 mInternalXAnimation.Play();
2365 // add internal animation state flag
2366 mScrollStateFlags |= SnappingInternalX;
2370 void ScrollView::SnapInternalYTo(float position)
2372 Actor self = Self();
2374 StopAnimation(mInternalYAnimation);
2376 // erase current state flags
2377 mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
2379 // if internal y not equal to inputed parameter, animate it
2380 float duration = std::min(fabsf((position - mScrollPrePosition.y) / mMaxOvershoot.y) * mSnapOvershootDuration, mSnapOvershootDuration);
2381 DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration );
2382 if( duration > Math::MACHINE_EPSILON_1 )
2384 DALI_LOG_SCROLL_STATE("[0x%X] Starting Y Snap Animation to[%.2f]", this, position );
2386 mInternalYAnimation = Animation::New(duration);
2387 mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
2388 mInternalYAnimation.AnimateTo(Property(self, mPropertyPrePosition, 1), position);
2389 mInternalYAnimation.Play();
2391 // add internal animation state flag
2392 mScrollStateFlags |= SnappingInternalY;
2396 void ScrollView::GestureStarted()
2398 // we handle the first gesture.
2399 // if we're currently doing a gesture and receive another
2400 // we continue and combine the effects of the gesture instead of reseting.
2401 if(mGestureStackDepth++==0)
2403 Actor self = Self();
2404 StopTouchDownTimer();
2406 mPanDelta = Vector3::ZERO;
2407 mLastVelocity = Vector2(0.0f, 0.0f);
2410 mLockAxis = LockPossible;
2413 if( mScrollStateFlags & SCROLL_X_STATE_MASK )
2415 StopAnimation(mInternalXAnimation);
2417 if( mScrollStateFlags & SCROLL_Y_STATE_MASK )
2419 StopAnimation(mInternalYAnimation);
2421 mScrollStateFlags = 0;
2423 if(mScrolling) // are we interrupting a current scroll?
2425 // set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete.
2427 // send negative scroll position since scroll internal scroll position works as an offset for actors,
2428 // give applications the position within the domain from the scroll view's anchor position
2429 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 5 [%.2f, %.2f]", this, -mScrollPostPosition.x, -mScrollPostPosition.y);
2430 mScrollCompletedSignalV2.Emit( -mScrollPostPosition );
2435 void ScrollView::GestureContinuing(const Vector2& panDelta)
2437 mPanDelta.x+= panDelta.x;
2438 mPanDelta.y+= panDelta.y;
2440 // Save the velocity, there is a bug in PanGesture
2441 // Whereby the Gesture::Finished's velocity is either:
2442 // NaN (due to time delta of zero between the last two events)
2443 // or 0 (due to position being the same between the last two events)
2445 // Axis Auto Lock - locks the panning to the horizontal or vertical axis if the pan
2446 // appears mostly horizontal or mostly vertical respectively.
2449 mLockAxis = GetLockAxis(mPanDelta.GetVectorXY(), mLockAxis, mAxisAutoLockGradient);
2450 } // end if mAxisAutoLock
2453 // TODO: Upgrade to use a more powerful gesture detector (one that supports multiple touches on pan - so works as pan and flick gesture)
2454 // BUG: Gesture::Finished doesn't always return velocity on release (due to
2455 // timeDelta between last two events being 0 sometimes, or posiiton being the same)
2456 void ScrollView::OnPan(PanGesture gesture)
2458 // Guard against destruction during signal emission
2459 // Note that Emit() methods are called indirectly e.g. from within ScrollView::OnGestureEx()
2460 Actor self( Self() );
2464 DALI_LOG_SCROLL_STATE("[0x%X] Pan Ignored, Insensitive", this);
2466 // If another callback on the same original signal disables sensitivity,
2467 // this callback will still be called, so we must suppress it.
2471 // translate Gesture input to get useful data...
2472 switch(gesture.state)
2474 case Gesture::Started:
2476 DALI_LOG_SCROLL_STATE("[0x%X] Pan Started", this);
2477 mPanStartPosition = gesture.position - gesture.displacement;
2478 UpdateLocalScrollProperties();
2481 self.SetProperty( mPropertyPanning, true );
2482 self.SetProperty( mPropertyScrollStartPagePosition, Vector3(gesture.position.x, gesture.position.y, 0.0f) );
2484 UpdateMainInternalConstraint();
2488 case Gesture::Continuing:
2492 DALI_LOG_SCROLL_STATE("[0x%X] Pan Continuing", this);
2493 GestureContinuing(gesture.screenDisplacement);
2497 // If we do not think we are panning, then we should not do anything here
2503 case Gesture::Finished:
2504 case Gesture::Cancelled:
2508 DALI_LOG_SCROLL_STATE("[0x%X] Pan %s", this, ( ( gesture.state == Gesture::Finished ) ? "Finished" : "Cancelled" ) );
2510 UpdateLocalScrollProperties();
2511 mLastVelocity = gesture.velocity;
2513 self.SetProperty( mPropertyPanning, false );
2515 if( mScrollMainInternalPrePositionConstraint )
2517 self.RemoveConstraint(mScrollMainInternalPrePositionConstraint);
2520 if( mOvershootIndicator )
2522 mOvershootIndicator->ClearOvershoot();
2527 // If we do not think we are panning, then we should not do anything here
2533 case Gesture::Possible:
2534 case Gesture::Clear:
2536 // Nothing to do, not needed.
2540 } // end switch(gesture.state)
2542 OnGestureEx(gesture.state);
2545 void ScrollView::OnGestureEx(Gesture::State state)
2547 // call necessary signals for application developer
2549 if(state == Gesture::Started)
2551 Vector3 currentScrollPosition = GetCurrentScrollPosition();
2552 Self().SetProperty(mPropertyScrolling, true);
2554 DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignalV2 2 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
2555 mScrollStartedSignalV2.Emit( currentScrollPosition );
2557 else if( (state == Gesture::Finished) ||
2558 (state == Gesture::Cancelled) ) // Finished/default
2560 // when all the gestures have finished, we finish the transform.
2561 // so if a user decides to pan (1 gesture), and then pan+zoom (2 gestures)
2562 // then stop panning (back to 1 gesture), and then stop zooming (0 gestures).
2563 // this is the point we end, and perform necessary snapping.
2564 mGestureStackDepth--;
2565 if(mGestureStackDepth==0)
2567 // no flick if we have not exceeded min flick distance
2568 if( (fabsf(mPanDelta.x) < mMinFlickDistance.x)
2569 && (fabsf(mPanDelta.y) < mMinFlickDistance.y) )
2571 // reset flick velocity
2572 mLastVelocity = Vector2::ZERO;
2578 DALI_LOG_SCROLL_STATE("[0x%X] mGestureStackDepth[%d]", this, mGestureStackDepth);
2583 void ScrollView::FinishTransform()
2585 // at this stage internal x and x scroll position should have followed prescroll position exactly
2586 Actor self = Self();
2588 PreAnimatedScrollSetup();
2590 // convert pixels/millisecond to pixels per second
2591 bool animating = SnapWithVelocity(mLastVelocity * 1000.0f);
2595 // if not animating, then this pan has completed right now.
2596 SetScrollUpdateNotification(false);
2598 Self().SetProperty(mPropertyScrolling, false);
2600 if( fabs(mScrollPrePosition.x - mScrollTargetPosition.x) > Math::MACHINE_EPSILON_10 )
2602 SnapInternalXTo(mScrollTargetPosition.x);
2604 if( fabs(mScrollPrePosition.y - mScrollTargetPosition.y) > Math::MACHINE_EPSILON_10 )
2606 SnapInternalYTo(mScrollTargetPosition.y);
2608 Vector3 currentScrollPosition = GetCurrentScrollPosition();
2609 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 6 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
2610 mScrollCompletedSignalV2.Emit( currentScrollPosition );
2614 Vector3 ScrollView::GetOvershoot(Vector3& position) const
2616 Vector3 size = Self().GetCurrentSize();
2619 const RulerDomain rulerDomainX = mRulerX->GetDomain();
2620 const RulerDomain rulerDomainY = mRulerY->GetDomain();
2622 if(mRulerX->IsEnabled() && rulerDomainX.enabled)
2624 const float left = rulerDomainX.min - position.x;
2625 const float right = size.width - rulerDomainX.max - position.x;
2632 overshoot.x = right;
2636 if(mRulerY->IsEnabled() && rulerDomainY.enabled)
2638 const float top = rulerDomainY.min - position.y;
2639 const float bottom = size.height - rulerDomainY.max - position.y;
2646 overshoot.y = bottom;
2653 bool ScrollView::OnAccessibilityPan(PanGesture gesture)
2655 // Keep track of whether this is an AccessibilityPan
2656 mInAccessibilityPan = true;
2658 mInAccessibilityPan = false;
2663 void ScrollView::ClampPosition(Vector3& position) const
2665 ClampState3 clamped;
2666 ClampPosition(position, clamped);
2669 void ScrollView::ClampPosition(Vector3& position, ClampState3 &clamped) const
2671 Vector3 size = Self().GetCurrentSize();
2673 position.x = -mRulerX->Clamp(-position.x, size.width, 1.0f, clamped.x); // NOTE: X & Y rulers think in -ve coordinate system.
2674 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.
2676 clamped.z = NotClamped;
2679 void ScrollView::WrapPosition(Vector3& position) const
2683 const RulerDomain rulerDomainX = mRulerX->GetDomain();
2684 const RulerDomain rulerDomainY = mRulerY->GetDomain();
2686 if(mRulerX->IsEnabled())
2688 position.x = -WrapInDomain(-position.x, rulerDomainX.min, rulerDomainX.max);
2691 if(mRulerY->IsEnabled())
2693 position.y = -WrapInDomain(-position.y, rulerDomainY.min, rulerDomainY.max);
2698 void ScrollView::UpdateMainInternalConstraint()
2700 // TODO: Only update the constraints which have changed, rather than remove all and add all again.
2701 // Requires a dali-core ApplyConstraintAt, or a ReplaceConstraint. The former is probably more flexible.
2702 Actor self = Self();
2703 PanGestureDetector detector( GetPanGestureDetector() );
2705 if(mScrollMainInternalPositionConstraint)
2707 self.RemoveConstraint(mScrollMainInternalPositionConstraint);
2708 self.RemoveConstraint(mScrollMainInternalDeltaConstraint);
2709 self.RemoveConstraint(mScrollMainInternalFinalConstraint);
2710 self.RemoveConstraint(mScrollMainInternalRelativeConstraint);
2712 if( mScrollMainInternalPrePositionConstraint )
2714 self.RemoveConstraint(mScrollMainInternalPrePositionConstraint);
2717 // TODO: It's probably better to use a local displacement value as this will give a displacement when scrolling just commences
2718 // but we need to make sure than the gesture system gives displacement since last frame (60Hz), not displacement since last touch event (90Hz).
2720 // 1. First calculate the pre-position (this is the scroll position if no clamping has taken place)
2721 Vector2 initialPanMask = Vector2(mRulerX->IsEnabled() ? 1.0f : 0.0f, mRulerY->IsEnabled() ? 1.0f : 0.0f);
2723 if( mLockAxis == LockVertical )
2725 initialPanMask.y = 0.0f;
2727 else if( mLockAxis == LockHorizontal )
2729 initialPanMask.x = 0.0f;
2731 Constraint constraint;
2735 constraint = Constraint::New<Vector3>( mPropertyPrePosition,
2736 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2737 Source( self, Actor::SIZE ),
2738 InternalPrePositionConstraint( mPanStartPosition, initialPanMask, mAxisAutoLock, mAxisAutoLockGradient, mLockAxis, mMaxOvershoot, mRulerX->GetDomain(), mRulerY->GetDomain() ) );
2739 mScrollMainInternalPrePositionConstraint = self.ApplyConstraint( constraint );
2742 // 2. Second calculate the clamped position (actual position)
2743 constraint = Constraint::New<Vector3>( mPropertyPosition,
2744 LocalSource( mPropertyPrePosition ),
2745 LocalSource( mPropertyPositionMin ),
2746 LocalSource( mPropertyPositionMax ),
2747 Source( self, Actor::SIZE ),
2748 InternalPositionConstraint( mRulerX->GetDomain(),
2749 mRulerY->GetDomain(), mWrapMode ) );
2750 mScrollMainInternalPositionConstraint = self.ApplyConstraint( constraint );
2752 constraint = Constraint::New<Vector3>( mPropertyPositionDelta,
2753 LocalSource( mPropertyPosition ),
2754 LocalSource( mPropertyDomainOffset ),
2755 InternalPositionDeltaConstraint );
2756 mScrollMainInternalDeltaConstraint = self.ApplyConstraint( constraint );
2758 constraint = Constraint::New<Vector3>( mPropertyFinal,
2759 LocalSource( mPropertyPosition ),
2760 LocalSource( mPropertyOvershootX ),
2761 LocalSource( mPropertyOvershootY ),
2762 InternalFinalConstraint( FinalDefaultAlphaFunction,
2763 FinalDefaultAlphaFunction ) );
2764 mScrollMainInternalFinalConstraint = self.ApplyConstraint( constraint );
2766 constraint = Constraint::New<Vector3>( mPropertyRelativePosition,
2767 LocalSource( mPropertyPosition ),
2768 LocalSource( mPropertyPositionMin ),
2769 LocalSource( mPropertyPositionMax ),
2770 LocalSource( Actor::SIZE ),
2771 InternalRelativePositionConstraint );
2772 mScrollMainInternalRelativeConstraint = self.ApplyConstraint( constraint );
2774 // When panning we want to make sure overshoot values are affected by pre position and post position
2775 SetOvershootConstraintsEnabled(!mWrapMode);
2778 void ScrollView::SetOvershootConstraintsEnabled(bool enabled)
2780 Actor self( Self() );
2781 // remove and reset, it may now be in wrong order with the main internal constraints
2782 if( mScrollMainInternalOvershootXConstraint )
2784 self.RemoveConstraint(mScrollMainInternalOvershootXConstraint);
2785 mScrollMainInternalOvershootXConstraint.Reset();
2786 self.RemoveConstraint(mScrollMainInternalOvershootYConstraint);
2787 mScrollMainInternalOvershootYConstraint.Reset();
2791 Constraint constraint = Constraint::New<float>( mPropertyOvershootX,
2792 LocalSource( mPropertyPrePosition ),
2793 LocalSource( mPropertyPosition ),
2794 LocalSource( mPropertyCanScrollHorizontal ),
2795 OvershootXConstraint(mMaxOvershoot.x) );
2796 mScrollMainInternalOvershootXConstraint = self.ApplyConstraint( constraint );
2798 constraint = Constraint::New<float>( mPropertyOvershootY,
2799 LocalSource( mPropertyPrePosition ),
2800 LocalSource( mPropertyPosition ),
2801 LocalSource( mPropertyCanScrollVertical ),
2802 OvershootYConstraint(mMaxOvershoot.y) );
2803 mScrollMainInternalOvershootYConstraint = self.ApplyConstraint( constraint );
2807 self.SetProperty(mPropertyOvershootX, 0.0f);
2808 self.SetProperty(mPropertyOvershootY, 0.0f);
2812 void ScrollView::SetInternalConstraints()
2814 // Internal constraints (applied to target ScrollBase Actor itself) /////////
2815 UpdateMainInternalConstraint();
2817 // User definable constraints to apply to all child actors //////////////////
2818 Actor self = Self();
2820 // Apply some default constraints to ScrollView & its bound actors
2821 // Movement + Wrap function
2823 Constraint constraint;
2825 // MoveActor (scrolling)
2826 constraint = Constraint::New<Vector3>( Actor::POSITION,
2827 Source( self, mPropertyPosition ),
2828 MoveActorConstraint );
2829 constraint.SetRemoveAction(Constraint::Discard);
2830 ApplyConstraintToBoundActors(constraint);
2832 // WrapActor (wrap functionality)
2833 constraint = Constraint::New<Vector3>( Actor::POSITION,
2834 LocalSource( Actor::SCALE ),
2835 LocalSource( Actor::ANCHOR_POINT ),
2836 LocalSource( Actor::SIZE ),
2837 Source( self, mPropertyPositionMin ),
2838 Source( self, mPropertyPositionMax ),
2839 Source( self, mPropertyWrap ),
2840 WrapActorConstraint );
2841 constraint.SetRemoveAction(Constraint::Discard);
2842 ApplyConstraintToBoundActors(constraint);
2845 } // namespace Internal
2847 } // namespace Toolkit