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 <cstring> // for strcmp
23 #include <dali/public-api/animation/constraints.h>
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/events/mouse-wheel-event.h>
26 #include <dali/public-api/events/touch-event.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/debug.h>
32 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
33 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
34 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
35 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-overshoot-indicator-impl.h>
36 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-effect-impl.h>
38 //#define ENABLED_SCROLL_STATE_LOGGING
40 #ifdef ENABLED_SCROLL_STATE_LOGGING
41 #define DALI_LOG_SCROLL_STATE(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d " format "\n", __PRETTY_FUNCTION__, __LINE__, ## args)
43 #define DALI_LOG_SCROLL_STATE(format, args...)
46 // TODO: Change to two class system:
47 // 1. DraggableActor (is an actor which can be dragged anywhere, can be set to range using the ruler)
48 // 2. ScrollView (contains a draggable actor that can a) be dragged in the negative X, and Y domain, b) has a hitArea for touches)
49 // TODO: external components (page and status overlays).
51 // TODO: upgrade Vector2/3 to support returning Unit vectors, normals, & cross product (dot product is already provided)
58 const Vector2 DEFAULT_MIN_FLICK_DISTANCE(30.0f, 30.0f); ///< minimum distance for pan before flick allowed
59 const float DEFAULT_MIN_FLICK_SPEED_THRESHOLD(500.0f); ///< Minimum pan speed required for flick in pixels/s
60 const float FREE_FLICK_SPEED_THRESHOLD = 200.0f; ///< Free-Flick threshold in pixels/ms
61 const float AUTOLOCK_AXIS_MINIMUM_DISTANCE2 = 100.0f; ///< Auto-lock axis after minimum distance squared.
62 const float FLICK_ORTHO_ANGLE_RANGE = 75.0f; ///< degrees. (if >45, then supports diagonal flicking)
63 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.
64 const unsigned long MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET( 150u );
65 const float TOUCH_DOWN_TIMER_INTERVAL = 100.0f;
66 const float DEFAULT_SCROLL_UPDATE_DISTANCE( 30.0f ); ///< Default distance to travel in pixels for scroll update signal
68 // Helpers ////////////////////////////////////////////////////////////////////////////////////////
71 * Find the vector (distance) from (a) to (b)
72 * in domain (start) to (end)
73 * (\ / start) (\ / end)
76 * @note assumes both (a) and (b) are already with the domain
79 * @param[in] a the current point
80 * @param[in] b the target point
81 * @param[in] start the start of the domain
82 * @param[in] end the end of the domain
83 * @param[in] bias whether to only take the right direction or the left direction,
84 * or the shortest direction.
85 * @return the shortest direction and distance
87 float VectorInDomain(float a, float b, float start, float end, Dali::Toolkit::DirectionBias bias)
89 if(bias == Dali::Toolkit::DirectionBiasNone)
91 return ShortestDistanceInDomain( a, b, start, end );
94 float size = end-start;
100 if(bias == Dali::Toolkit::DirectionBiasRight) // going right, take the vector.
106 float aRight = a+size;
113 if(bias == Dali::Toolkit::DirectionBiasLeft) // going left, take the vector.
119 float aLeft = a-size;
126 * Returns the position of the anchor within actor
128 * @param actor The Actor
129 * @param anchor The Anchor point of interest.
130 * @return The position of the Anchor
132 Vector3 GetPositionOfAnchor(Actor &actor, const Vector3 &anchor)
134 Vector3 childPosition = actor.GetCurrentPosition();
135 Vector3 childAnchor = - actor.GetCurrentAnchorPoint() + anchor;
136 Vector3 childSize = actor.GetCurrentSize();
138 return childPosition + childAnchor * childSize;
141 // AlphaFunctions /////////////////////////////////////////////////////////////////////////////////
143 float FinalDefaultAlphaFunction(float offset)
145 return offset * 0.5f;
149 * ConstantDecelerationAlphaFunction
150 * Newtoninan distance for constant deceleration
151 * v = 1 - t, s = t - 1/2 t^2
152 * when t = 0, s = 0.0 (min distance)
153 * when t = 1, s = 0.5 (max distance)
154 * progress = s / (max-min) = 2t - t^2
156 * @param[in] offset The input progress
157 * @return The output progress
159 float ConstantDecelerationAlphaFunction(float progress)
161 return progress * 2.0f - progress * progress;
164 // Internal Constraints ///////////////////////////////////////////////////////////////////////////
167 * Internal Relative position Constraint
168 * Generates the relative position value of the scroll view
169 * based on the absolute position, and it's relation to the
170 * scroll domain. This is a value from 0.0f to 1.0f in each
171 * scroll position axis.
173 void InternalRelativePositionConstraint( Vector3& relativePosition, const PropertyInputContainer& inputs)
175 Vector3 position = -inputs[0]->GetVector3();
176 const Vector3& min = inputs[1]->GetVector3();
177 const Vector3& max = inputs[2]->GetVector3();
178 const Vector3& size = inputs[3]->GetVector3();
180 position.x = WrapInDomain(position.x, min.x, max.x);
181 position.y = WrapInDomain(position.y, min.y, max.y);
183 Vector3 domainSize = (max - min) - size;
185 relativePosition.x = domainSize.x > Math::MACHINE_EPSILON_1 ? fabsf((position.x - min.x) / domainSize.x) : 0.0f;
186 relativePosition.y = domainSize.y > Math::MACHINE_EPSILON_1 ? fabsf((position.y - min.y) / domainSize.y) : 0.0f;
187 relativePosition.z = 0.0f;
190 } // unnamed namespace
206 return Toolkit::ScrollView::New();
209 // Setup properties, signals and actions using the type-registry.
210 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ScrollView, Toolkit::Scrollable, Create )
212 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "scroll-position", VECTOR3, SCROLL_POSITION )
213 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "scroll-pre-position", VECTOR3, SCROLL_PRE_POSITION )
214 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "overshoot-x", FLOAT, OVERSHOOT_X )
215 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "overshoot-y", FLOAT, OVERSHOOT_Y )
216 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "scroll-final", VECTOR3, SCROLL_FINAL )
217 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "wrap", BOOLEAN, WRAP )
218 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "panning", BOOLEAN, PANNING )
219 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "scrolling", BOOLEAN, SCROLLING )
220 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "scroll-domain-offset", VECTOR3, SCROLL_DOMAIN_OFFSET )
221 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "scroll-position-delta", VECTOR3, SCROLL_POSITION_DELTA )
222 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "start-page-position", VECTOR3, START_PAGE_POSITION )
224 DALI_SIGNAL_REGISTRATION( Toolkit, ScrollView, "value-changed", SIGNAL_SNAP_STARTED )
226 DALI_TYPE_REGISTRATION_END()
229 * Returns whether to lock scrolling to a particular axis
231 * @param[in] panDelta Distance panned since gesture started
232 * @param[in] currentLockAxis The current lock axis value
233 * @param[in] lockGradient How quickly to lock to a particular axis
235 * @return The new axis lock state
237 ScrollView::LockAxis GetLockAxis(const Vector2& panDelta, ScrollView::LockAxis currentLockAxis, float lockGradient)
239 if(panDelta.LengthSquared() > AUTOLOCK_AXIS_MINIMUM_DISTANCE2 &&
240 currentLockAxis == ScrollView::LockPossible)
242 float dx = fabsf(panDelta.x);
243 float dy = fabsf(panDelta.y);
244 if(dx * lockGradient >= dy)
246 // 0.36:1 gradient to the horizontal (deviate < 20 degrees)
247 currentLockAxis = ScrollView::LockVertical;
249 else if(dy * lockGradient > dx)
251 // 0.36:1 gradient to the vertical (deviate < 20 degrees)
252 currentLockAxis = ScrollView::LockHorizontal;
256 currentLockAxis = ScrollView::LockNone;
259 return currentLockAxis;
263 * Internal Pre-Position Property Constraint.
265 * Generates position property based on current position + gesture displacement.
266 * Or generates position property based on positionX/Y.
267 * Note: This is the position prior to any clamping at scroll boundaries.
269 struct InternalPrePositionConstraint
271 InternalPrePositionConstraint(const Vector2& initialPanPosition,
272 const Vector2& initialPanMask,
274 float axisAutoLockGradient,
275 ScrollView::LockAxis initialLockAxis,
276 const Vector2& maxOvershoot,
277 const RulerDomain& domainX, const RulerDomain& domainY)
278 : mLocalStart(initialPanPosition),
279 mInitialPanMask(initialPanMask),
280 mDomainMin( -domainX.min, -domainY.min ),
281 mDomainMax( -domainX.max, -domainY.max ),
282 mMaxOvershoot(maxOvershoot),
283 mAxisAutoLockGradient(axisAutoLockGradient),
284 mLockAxis(initialLockAxis),
285 mAxisAutoLock(axisAutoLock),
287 mClampX( domainX.enabled ),
288 mClampY( domainY.enabled )
292 void operator()( Vector3& scrollPostPosition, const PropertyInputContainer& inputs )
294 const Vector2& panPosition = inputs[0]->GetVector2();
298 mPrePosition = scrollPostPosition;
299 mCurrentPanMask = mInitialPanMask;
303 // Calculate Deltas...
304 const Vector2& currentPosition = panPosition;
305 Vector2 panDelta( currentPosition - mLocalStart );
307 // Axis Auto Lock - locks the panning to the horizontal or vertical axis if the pan
308 // appears mostly horizontal or mostly vertical respectively...
311 mLockAxis = GetLockAxis(panDelta, mLockAxis, mAxisAutoLockGradient);
312 if( mLockAxis == ScrollView::LockVertical )
314 mCurrentPanMask.y = 0.0f;
316 else if( mLockAxis == ScrollView::LockHorizontal )
318 mCurrentPanMask.x = 0.0f;
322 // Restrict deltas based on ruler enable/disable and axis-lock state...
323 panDelta *= mCurrentPanMask;
325 // Perform Position transform based on input deltas...
326 scrollPostPosition = mPrePosition;
327 scrollPostPosition.GetVectorXY() += panDelta;
329 // if no wrapping then clamp preposition to maximum overshoot amount
330 const Vector3& size = inputs[1]->GetVector3();
333 float newXPosition = Clamp(scrollPostPosition.x, (mDomainMax.x + size.x) - mMaxOvershoot.x, mDomainMin.x + mMaxOvershoot.x );
334 if( (newXPosition < scrollPostPosition.x - Math::MACHINE_EPSILON_1)
335 || (newXPosition > scrollPostPosition.x + Math::MACHINE_EPSILON_1) )
337 mPrePosition.x = newXPosition;
338 mLocalStart.x = panPosition.x;
340 scrollPostPosition.x = newXPosition;
344 float newYPosition = Clamp(scrollPostPosition.y, (mDomainMax.y + size.y) - mMaxOvershoot.y, mDomainMin.y + mMaxOvershoot.y );
345 if( (newYPosition < scrollPostPosition.y - Math::MACHINE_EPSILON_1)
346 || (newYPosition > scrollPostPosition.y + Math::MACHINE_EPSILON_1) )
348 mPrePosition.y = newYPosition;
349 mLocalStart.y = panPosition.y;
351 scrollPostPosition.y = newYPosition;
355 Vector3 mPrePosition;
357 Vector2 mInitialPanMask; ///< Initial pan mask (based on ruler settings)
358 Vector2 mCurrentPanMask; ///< Current pan mask that can be altered by axis lock mode.
361 Vector2 mMaxOvershoot;
363 float mAxisAutoLockGradient; ///< Set by ScrollView
364 ScrollView::LockAxis mLockAxis;
366 bool mAxisAutoLock:1; ///< Set by ScrollView
373 * Internal Position Property Constraint.
375 * Generates position property based on pre-position
376 * Note: This is the position after clamping.
377 * (uses result of InternalPrePositionConstraint)
379 struct InternalPositionConstraint
381 InternalPositionConstraint(const RulerDomain& domainX, const RulerDomain& domainY, bool wrap)
382 : mDomainMin( -domainX.min, -domainY.min ),
383 mDomainMax( -domainX.max, -domainY.max ),
384 mClampX( domainX.enabled ),
385 mClampY( domainY.enabled ),
390 void operator()( Vector3& position, const PropertyInputContainer& inputs )
392 position = inputs[0]->GetVector3();
393 const Vector2& size = inputs[3]->GetVector3().GetVectorXY();
394 const Vector3& min = inputs[1]->GetVector3();
395 const Vector3& max = inputs[2]->GetVector3();
399 position.x = -WrapInDomain(-position.x, min.x, max.x);
400 position.y = -WrapInDomain(-position.y, min.y, max.y);
404 // clamp post position to domain
405 position.x = mClampX ? Clamp(position.x, mDomainMax.x + size.x, mDomainMin.x ) : position.x;
406 position.y = mClampY ? Clamp(position.y, mDomainMax.y + size.y, mDomainMin.y ) : position.y;
419 * This constraint updates the X overshoot property using the difference
420 * SCROLL_PRE_POSITION.x and SCROLL_POSITION.x, returning a relative value between 0.0f and 1.0f
422 struct OvershootXConstraint
424 OvershootXConstraint(float maxOvershoot) : mMaxOvershoot(maxOvershoot) {}
426 void operator()( float& current, const PropertyInputContainer& inputs )
428 if( inputs[2]->GetBoolean() )
430 const Vector3& scrollPrePosition = inputs[0]->GetVector3();
431 const Vector3& scrollPostPosition = inputs[1]->GetVector3();
432 float newOvershoot = scrollPrePosition.x - scrollPostPosition.x;
433 current = (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
445 * This constraint updates the Y overshoot property using the difference
446 * SCROLL_PRE_POSITION.y and SCROLL_POSITION.y, returning a relative value between 0.0f and 1.0f
448 struct OvershootYConstraint
450 OvershootYConstraint(float maxOvershoot) : mMaxOvershoot(maxOvershoot) {}
452 void operator()( float& current, const PropertyInputContainer& inputs )
454 if( inputs[2]->GetBoolean() )
456 const Vector3& scrollPrePosition = inputs[0]->GetVector3();
457 const Vector3& scrollPostPosition = inputs[1]->GetVector3();
458 float newOvershoot = scrollPrePosition.y - scrollPostPosition.y;
459 current = (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
471 * Internal Position-Delta Property Constraint.
473 * Generates position-delta property based on scroll-position + scroll-offset properties.
475 void InternalPositionDeltaConstraint( Vector3& current, const PropertyInputContainer& inputs )
477 const Vector3& scrollPosition = inputs[0]->GetVector3();
478 const Vector3& scrollOffset = inputs[1]->GetVector3();
480 current = scrollPosition + scrollOffset;
484 * Internal Final Position Constraint
485 * The position of content is:
486 * of scroll-position + f(scroll-overshoot)
487 * where f(...) function defines how overshoot
488 * should affect final-position.
490 struct InternalFinalConstraint
492 InternalFinalConstraint(AlphaFunctionPrototype functionX,
493 AlphaFunctionPrototype functionY)
494 : mFunctionX(functionX),
495 mFunctionY(functionY)
499 void operator()( Vector3& current, const PropertyInputContainer& inputs )
501 const float& overshootx = inputs[1]->GetFloat();
502 const float& overshooty = inputs[2]->GetFloat();
503 Vector3 offset( mFunctionX(overshootx),
504 mFunctionY(overshooty),
507 current = inputs[0]->GetVector3() - offset;
510 AlphaFunctionPrototype mFunctionX;
511 AlphaFunctionPrototype mFunctionY;
517 ///////////////////////////////////////////////////////////////////////////////////////////////////
519 ///////////////////////////////////////////////////////////////////////////////////////////////////
521 Dali::Toolkit::ScrollView ScrollView::New()
523 // Create the implementation
524 ScrollViewPtr scrollView(new ScrollView());
526 // Pass ownership to CustomActor via derived handle
527 Dali::Toolkit::ScrollView handle(*scrollView);
529 // Second-phase init of the implementation
530 // This can only be done after the CustomActor connection has been made...
531 scrollView->Initialize();
536 ScrollView::ScrollView()
537 : ScrollBase( ControlBehaviour( REQUIRES_MOUSE_WHEEL_EVENTS ) ), // Enable size negotiation
539 mGestureStackDepth(0),
540 mScrollStateFlags(0),
541 mLockAxis(LockPossible),
542 mScrollUpdateDistance(DEFAULT_SCROLL_UPDATE_DISTANCE),
543 mMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT),
544 mUserMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT),
545 mSnapOvershootDuration(Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION),
546 mSnapOvershootAlphaFunction(AlphaFunction::EASE_OUT),
547 mSnapDuration(Toolkit::ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION),
548 mSnapAlphaFunction(AlphaFunction::EASE_OUT),
549 mMinFlickDistance(DEFAULT_MIN_FLICK_DISTANCE),
550 mFlickSpeedThreshold(DEFAULT_MIN_FLICK_SPEED_THRESHOLD),
551 mFlickDuration(Toolkit::ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION),
552 mFlickAlphaFunction(AlphaFunction::EASE_OUT),
553 mAxisAutoLockGradient(Toolkit::ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT),
554 mFrictionCoefficient(Toolkit::ScrollView::DEFAULT_FRICTION_COEFFICIENT),
555 mFlickSpeedCoefficient(Toolkit::ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT),
556 mMaxFlickSpeed(Toolkit::ScrollView::DEFAULT_MAX_FLICK_SPEED),
557 mInAccessibilityPan(false),
560 mScrollInterrupted(false),
563 mTouchDownTimeoutReached(false),
564 mActorAutoSnapEnabled(false),
565 mAutoResizeContainerEnabled(false),
567 mAxisAutoLock(false),
569 mDefaultMaxOvershoot(true),
570 mCanScrollHorizontal(true),
571 mCanScrollVertical(true)
575 void ScrollView::OnInitialize()
579 // Internal Actor, used to hide actors from enumerations.
580 // Also actors added to Internal actor appear as overlays e.g. ScrollBar components.
581 mInternalActor = Actor::New();
582 mInternalActor.SetDrawMode(DrawMode::OVERLAY);
583 self.Add(mInternalActor);
584 Constraint constraint = Constraint::New<Vector3>( mInternalActor, Actor::Property::SIZE, EqualToConstraint() );
585 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
587 mInternalActor.SetParentOrigin(ParentOrigin::CENTER);
588 mInternalActor.SetAnchorPoint(AnchorPoint::CENTER);
592 mScrollPostPosition = mScrollPrePosition = Vector3::ZERO;
594 mMouseWheelScrollDistanceStep = Stage::GetCurrent().GetSize() * DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION;
598 mGestureStackDepth = 0;
600 EnableGestureDetection( Gesture::Type( Gesture::Pan ) );
602 // By default we'll allow the user to freely drag the scroll view,
603 // while disabling the other rulers.
604 RulerPtr ruler = new DefaultRuler();
608 EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator);
610 self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL, mCanScrollVertical);
611 self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_HORIZONTAL, mCanScrollHorizontal);
613 Vector3 size = GetControlSize();
614 UpdatePropertyDomain(size);
615 SetInternalConstraints();
618 void ScrollView::OnControlStageConnection()
620 DALI_LOG_SCROLL_STATE("[0x%X]", this);
624 SetScrollSensitive( false );
625 SetScrollSensitive( true );
627 if(IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator))
629 // try and make sure property notifications are set
630 EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator);
634 void ScrollView::OnControlStageDisconnection()
636 DALI_LOG_SCROLL_STATE("[0x%X]", this);
641 ScrollView::~ScrollView()
643 DALI_LOG_SCROLL_STATE("[0x%X]", this);
646 AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
648 return mSnapAlphaFunction;
651 void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
653 mSnapAlphaFunction = alpha;
656 AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
658 return mFlickAlphaFunction;
661 void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
663 mFlickAlphaFunction = alpha;
666 float ScrollView::GetScrollSnapDuration() const
668 return mSnapDuration;
671 void ScrollView::SetScrollSnapDuration(float time)
673 mSnapDuration = time;
676 float ScrollView::GetScrollFlickDuration() const
678 return mFlickDuration;
681 void ScrollView::SetScrollFlickDuration(float time)
683 mFlickDuration = time;
686 void ScrollView::ApplyEffect(Toolkit::ScrollViewEffect effect)
688 Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
690 // Assertion check to ensure effect doesn't already exist in this scrollview
691 bool effectAlreadyExistsInScrollView(false);
692 for (ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
696 effectAlreadyExistsInScrollView = true;
701 DALI_ASSERT_ALWAYS(!effectAlreadyExistsInScrollView);
703 // add effect to effects list
704 mEffects.push_back(effect);
706 // invoke Attachment request to ScrollView first
707 GetImpl(effect).Attach(self);
710 void ScrollView::RemoveEffect(Toolkit::ScrollViewEffect effect)
712 Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
714 // remove effect from effects list
715 bool effectExistedInScrollView(false);
716 for (ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
720 mEffects.erase(iter);
721 effectExistedInScrollView = true;
726 // Assertion check to ensure effect existed.
727 DALI_ASSERT_ALWAYS(effectExistedInScrollView);
729 // invoke Detachment request to ScrollView last
730 GetImpl(effect).Detach(self);
733 void ScrollView::RemoveAllEffects()
735 Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
737 for (ScrollViewEffectIter effectIter = mEffects.begin(); effectIter != mEffects.end(); ++effectIter)
739 Toolkit::ScrollViewEffect effect = *effectIter;
741 // invoke Detachment request to ScrollView last
742 GetImpl(effect).Detach(self);
748 void ScrollView::ApplyConstraintToChildren(Constraint constraint)
750 ApplyConstraintToBoundActors(constraint);
753 void ScrollView::RemoveConstraintsFromChildren()
755 RemoveConstraintsFromBoundActors();
758 const RulerPtr ScrollView::GetRulerX() const
763 const RulerPtr ScrollView::GetRulerY() const
768 void ScrollView::SetRulerX(RulerPtr ruler)
772 Vector3 size = GetControlSize();
773 UpdatePropertyDomain(size);
774 UpdateMainInternalConstraint();
777 void ScrollView::SetRulerY(RulerPtr ruler)
781 Vector3 size = GetControlSize();
782 UpdatePropertyDomain(size);
783 UpdateMainInternalConstraint();
786 void ScrollView::UpdatePropertyDomain(const Vector3& size)
789 Vector3 min = mMinScroll;
790 Vector3 max = mMaxScroll;
791 bool scrollPositionChanged = false;
792 bool domainChanged = false;
794 bool canScrollVertical = false;
795 bool canScrollHorizontal = false;
796 UpdateLocalScrollProperties();
797 if(mRulerX->IsEnabled())
799 const Toolkit::RulerDomain& rulerDomain = mRulerX->GetDomain();
800 if( fabsf(min.x - rulerDomain.min) > Math::MACHINE_EPSILON_100
801 || fabsf(max.x - rulerDomain.max) > Math::MACHINE_EPSILON_100 )
803 domainChanged = true;
804 min.x = rulerDomain.min;
805 max.x = rulerDomain.max;
807 // make sure new scroll value is within new domain
808 if( mScrollPrePosition.x < min.x
809 || mScrollPrePosition.x > max.x )
811 scrollPositionChanged = true;
812 mScrollPrePosition.x = Clamp(mScrollPrePosition.x, -(max.x - size.x), -min.x);
815 if( (fabsf(rulerDomain.max - rulerDomain.min) - size.x) > Math::MACHINE_EPSILON_100 )
817 canScrollHorizontal = true;
820 else if( fabs(min.x) > Math::MACHINE_EPSILON_100
821 || fabs(max.x) > Math::MACHINE_EPSILON_100 )
823 // need to reset to 0
824 domainChanged = true;
827 canScrollHorizontal = false;
830 if(mRulerY->IsEnabled())
832 const Toolkit::RulerDomain& rulerDomain = mRulerY->GetDomain();
833 if( fabsf(min.y - rulerDomain.min) > Math::MACHINE_EPSILON_100
834 || fabsf(max.y - rulerDomain.max) > Math::MACHINE_EPSILON_100 )
836 domainChanged = true;
837 min.y = rulerDomain.min;
838 max.y = rulerDomain.max;
840 // make sure new scroll value is within new domain
841 if( mScrollPrePosition.y < min.y
842 || mScrollPrePosition.y > max.y )
844 scrollPositionChanged = true;
845 mScrollPrePosition.y = Clamp(mScrollPrePosition.y, -(max.y - size.y), -min.y);
848 if( (fabsf(rulerDomain.max - rulerDomain.min) - size.y) > Math::MACHINE_EPSILON_100 )
850 canScrollVertical = true;
853 else if( fabs(min.y) > Math::MACHINE_EPSILON_100
854 || fabs(max.y) > Math::MACHINE_EPSILON_100 )
856 // need to reset to 0
857 domainChanged = true;
860 canScrollVertical = false;
863 // avoid setting properties if possible, otherwise this will cause an entire update as well as triggering constraints using each property we update
864 if( mCanScrollVertical != canScrollVertical )
866 mCanScrollVertical = canScrollVertical;
867 self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL, canScrollVertical);
869 if( mCanScrollHorizontal != canScrollHorizontal )
871 mCanScrollHorizontal = canScrollHorizontal;
872 self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_HORIZONTAL, canScrollHorizontal);
874 if( scrollPositionChanged )
876 DALI_LOG_SCROLL_STATE("[0x%X] Domain Changed, setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
877 self.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPrePosition);
883 self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MIN, mMinScroll );
884 self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX, mMaxScroll );
888 void ScrollView::SetScrollSensitive(bool sensitive)
891 PanGestureDetector panGesture( GetPanGestureDetector() );
893 DALI_LOG_SCROLL_STATE("[0x%X] sensitive: before:[%d] setting[%d]", this, int(mSensitive), int(sensitive));
895 if((!mSensitive) && (sensitive))
897 mSensitive = sensitive;
898 panGesture.Attach(self);
900 else if((mSensitive) && (!sensitive))
902 DALI_LOG_SCROLL_STATE("[0x%X] BEFORE: panning:[%d]", this, int(mPanning));
904 // while the scroll view is panning, the state needs to be reset.
907 PanGesture cancelGesture( Gesture::Cancelled );
908 OnPan( cancelGesture );
911 panGesture.Detach(self);
912 mSensitive = sensitive;
914 mGestureStackDepth = 0;
915 DALI_LOG_SCROLL_STATE("[0x%X] AFTER: panning:[%d]", this, int(mPanning));
919 void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
921 mMaxOvershoot.x = overshootX;
922 mMaxOvershoot.y = overshootY;
923 mUserMaxOvershoot = mMaxOvershoot;
924 mDefaultMaxOvershoot = false;
925 UpdateMainInternalConstraint();
928 void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
930 mSnapOvershootAlphaFunction = alpha;
933 void ScrollView::SetSnapOvershootDuration(float duration)
935 mSnapOvershootDuration = duration;
938 void ScrollView::SetActorAutoSnap(bool enable)
940 mActorAutoSnapEnabled = enable;
943 void ScrollView::SetAutoResize(bool enable)
945 mAutoResizeContainerEnabled = enable;
946 // TODO: This needs a lot of issues to be addressed before working.
949 bool ScrollView::GetWrapMode() const
954 void ScrollView::SetWrapMode(bool enable)
957 Self().SetProperty(Toolkit::ScrollView::Property::WRAP, enable);
960 int ScrollView::GetScrollUpdateDistance() const
962 return mScrollUpdateDistance;
965 void ScrollView::SetScrollUpdateDistance(int distance)
967 mScrollUpdateDistance = distance;
970 bool ScrollView::GetAxisAutoLock() const
972 return mAxisAutoLock;
975 void ScrollView::SetAxisAutoLock(bool enable)
977 mAxisAutoLock = enable;
978 UpdateMainInternalConstraint();
981 float ScrollView::GetAxisAutoLockGradient() const
983 return mAxisAutoLockGradient;
986 void ScrollView::SetAxisAutoLockGradient(float gradient)
988 DALI_ASSERT_DEBUG( gradient >= 0.0f && gradient <= 1.0f );
989 mAxisAutoLockGradient = gradient;
990 UpdateMainInternalConstraint();
993 float ScrollView::GetFrictionCoefficient() const
995 return mFrictionCoefficient;
998 void ScrollView::SetFrictionCoefficient(float friction)
1000 DALI_ASSERT_DEBUG( friction > 0.0f );
1001 mFrictionCoefficient = friction;
1004 float ScrollView::GetFlickSpeedCoefficient() const
1006 return mFlickSpeedCoefficient;
1009 void ScrollView::SetFlickSpeedCoefficient(float speed)
1011 mFlickSpeedCoefficient = speed;
1014 Vector2 ScrollView::GetMinimumDistanceForFlick() const
1016 return mMinFlickDistance;
1019 void ScrollView::SetMinimumDistanceForFlick( const Vector2& distance )
1021 mMinFlickDistance = distance;
1024 float ScrollView::GetMinimumSpeedForFlick() const
1026 return mFlickSpeedThreshold;
1029 void ScrollView::SetMinimumSpeedForFlick( float speed )
1031 mFlickSpeedThreshold = speed;
1034 float ScrollView::GetMaxFlickSpeed() const
1036 return mMaxFlickSpeed;
1039 void ScrollView::SetMaxFlickSpeed(float speed)
1041 mMaxFlickSpeed = speed;
1044 void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
1046 mMouseWheelScrollDistanceStep = step;
1049 Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
1051 return mMouseWheelScrollDistanceStep;
1054 unsigned int ScrollView::GetCurrentPage() const
1056 // in case animation is currently taking place.
1057 Vector3 position = GetPropertyPosition();
1059 Actor self = Self();
1060 unsigned int page = 0;
1061 unsigned int pagesPerVolume = 1;
1062 unsigned int volume = 0;
1064 // if rulerX is enabled, then get page count (columns)
1065 page = mRulerX->GetPageFromPosition(-position.x, mWrapMode);
1066 volume = mRulerY->GetPageFromPosition(-position.y, mWrapMode);
1067 pagesPerVolume = mRulerX->GetTotalPages();
1069 return volume * pagesPerVolume + page;
1072 Vector3 ScrollView::GetCurrentScrollPosition() const
1074 return -GetPropertyPosition();
1077 void ScrollView::SetScrollPosition(const Vector3& position)
1079 mScrollPrePosition = position;
1082 Vector3 ScrollView::GetDomainSize() const
1084 Vector3 size = Self().GetCurrentSize();
1086 const RulerDomain& xDomain = GetRulerX()->GetDomain();
1087 const RulerDomain& yDomain = GetRulerY()->GetDomain();
1089 Vector3 domainSize = Vector3( xDomain.max - xDomain.min, yDomain.max - yDomain.min, 0.0f ) - size;
1093 void ScrollView::TransformTo(const Vector3& position,
1094 DirectionBias horizontalBias, DirectionBias verticalBias)
1096 TransformTo(position, mSnapDuration, mSnapAlphaFunction, horizontalBias, verticalBias);
1099 void ScrollView::TransformTo(const Vector3& position, float duration, AlphaFunction alpha,
1100 DirectionBias horizontalBias, DirectionBias verticalBias)
1102 // If this is called while the timer is running, then cancel it
1103 StopTouchDownTimer();
1105 Actor self( Self() );
1107 // Guard against destruction during signal emission
1108 // Note that Emit() methods are called indirectly e.g. from within ScrollView::AnimateTo()
1109 Toolkit::ScrollView handle( GetOwner() );
1111 DALI_LOG_SCROLL_STATE("[0x%X] pos[%.2f,%.2f], duration[%.2f] bias[%d, %d]",
1112 this, position.x, position.y, duration, int(horizontalBias), int(verticalBias));
1114 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1115 self.SetProperty( Toolkit::ScrollView::Property::START_PAGE_POSITION, currentScrollPosition );
1117 if( mScrolling ) // are we interrupting a current scroll?
1119 // set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete.
1121 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
1122 mScrollCompletedSignal.Emit( currentScrollPosition );
1125 if( mPanning ) // are we interrupting a current pan?
1127 DALI_LOG_SCROLL_STATE("[0x%X] Interrupting Pan, set to false", this );
1129 mGestureStackDepth = 0;
1130 self.SetProperty( Toolkit::ScrollView::Property::PANNING, false );
1132 if( mScrollMainInternalPrePositionConstraint )
1134 mScrollMainInternalPrePositionConstraint.Remove();
1138 self.SetProperty(Toolkit::ScrollView::Property::SCROLLING, true);
1141 DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignal 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
1142 mScrollStartedSignal.Emit( currentScrollPosition );
1143 bool animating = AnimateTo(-position,
1144 Vector3::ONE * duration,
1153 // if not animating, then this pan has completed right now.
1154 self.SetProperty(Toolkit::ScrollView::Property::SCROLLING, false);
1157 // If we have no duration, then in the next update frame, we will be at the position specified as we just set.
1158 // In this scenario, we cannot return the currentScrollPosition as this is out-of-date and should instead return the requested final position
1159 Vector3 completedPosition( currentScrollPosition );
1160 if( duration <= Math::MACHINE_EPSILON_10 )
1162 completedPosition = position;
1165 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 2 [%.2f, %.2f]", this, completedPosition.x, completedPosition.y);
1166 SetScrollUpdateNotification(false);
1167 mScrollCompletedSignal.Emit( completedPosition );
1171 void ScrollView::ScrollTo(const Vector3& position)
1173 ScrollTo(position, mSnapDuration );
1176 void ScrollView::ScrollTo(const Vector3& position, float duration)
1178 ScrollTo(position, duration, DirectionBiasNone, DirectionBiasNone);
1181 void ScrollView::ScrollTo(const Vector3& position, float duration, AlphaFunction alpha)
1183 ScrollTo(position, duration, alpha, DirectionBiasNone, DirectionBiasNone);
1186 void ScrollView::ScrollTo(const Vector3& position, float duration,
1187 DirectionBias horizontalBias, DirectionBias verticalBias)
1189 ScrollTo(position, duration, mSnapAlphaFunction, horizontalBias, verticalBias);
1192 void ScrollView::ScrollTo(const Vector3& position, float duration, AlphaFunction alpha,
1193 DirectionBias horizontalBias, DirectionBias verticalBias)
1195 DALI_LOG_SCROLL_STATE("[0x%X] position[%.2f, %.2f] duration[%.2f], bias[%d, %d]", this, position.x, position.y, duration, int(horizontalBias), int(verticalBias));
1196 TransformTo(position, duration, alpha, horizontalBias, verticalBias);
1199 void ScrollView::ScrollTo(unsigned int page)
1201 ScrollTo(page, mSnapDuration);
1204 void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
1207 unsigned int volume;
1208 unsigned int libraries;
1210 // The position to scroll to is continuous and linear
1211 // unless a domain has been enabled on the X axis.
1212 // or if WrapMode has been enabled.
1213 bool carryX = mRulerX->GetDomain().enabled | mWrapMode;
1214 bool carryY = mRulerY->GetDomain().enabled | mWrapMode;
1216 position.x = mRulerX->GetPositionFromPage(page, volume, carryX);
1217 position.y = mRulerY->GetPositionFromPage(volume, libraries, carryY);
1219 ScrollTo(position, duration, bias, bias);
1222 void ScrollView::ScrollTo(Actor &actor)
1224 ScrollTo(actor, mSnapDuration);
1227 void ScrollView::ScrollTo(Actor &actor, float duration)
1229 DALI_ASSERT_ALWAYS(actor.GetParent() == Self());
1231 Actor self = Self();
1232 Vector3 size = self.GetCurrentSize();
1233 Vector3 position = actor.GetCurrentPosition();
1234 position -= GetPropertyPrePosition();
1236 ScrollTo(Vector3(position.x - size.width * 0.5f, position.y - size.height * 0.5f, 0.0f), duration);
1239 Actor ScrollView::FindClosestActor()
1241 Actor self = Self();
1242 Vector3 size = self.GetCurrentSize();
1244 return FindClosestActorToPosition(Vector3(size.width * 0.5f,size.height * 0.5f,0.0f));
1247 Actor ScrollView::FindClosestActorToPosition(const Vector3& position, FindDirection dirX, FindDirection dirY, FindDirection dirZ)
1250 float closestDistance2 = 0.0f;
1251 Vector3 actualPosition = position;
1253 unsigned int numChildren = Self().GetChildCount();
1255 for(unsigned int i = 0; i < numChildren; ++i)
1257 Actor child = Self().GetChildAt(i);
1259 if(mInternalActor == child) // ignore internal actor.
1264 Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
1266 Vector3 delta = childPosition - actualPosition;
1268 // X-axis checking (only find Actors to the [dirX] of actualPosition)
1269 if(dirX > All) // != All,None
1271 FindDirection deltaH = delta.x > 0 ? Right : Left;
1278 // Y-axis checking (only find Actors to the [dirY] of actualPosition)
1279 if(dirY > All) // != All,None
1281 FindDirection deltaV = delta.y > 0 ? Down : Up;
1288 // Z-axis checking (only find Actors to the [dirZ] of actualPosition)
1289 if(dirZ > All) // != All,None
1291 FindDirection deltaV = delta.y > 0 ? In : Out;
1298 // compare child to closest child in terms of distance.
1299 float distance2 = 0.0f;
1301 // distance2 = the Square of the relevant dimensions of delta
1304 distance2 += delta.x * delta.x;
1309 distance2 += delta.y * delta.y;
1314 distance2 += delta.z * delta.z;
1317 if(closestChild) // Next time.
1319 if(distance2 < closestDistance2)
1321 closestChild = child;
1322 closestDistance2 = distance2;
1327 closestChild = child;
1328 closestDistance2 = distance2;
1332 return closestChild;
1335 bool ScrollView::ScrollToSnapPoint()
1337 DALI_LOG_SCROLL_STATE("[0x%X]", this );
1338 Vector2 stationaryVelocity = Vector2(0.0f, 0.0f);
1339 return SnapWithVelocity( stationaryVelocity );
1342 // TODO: In situations where axes are different (X snap, Y free)
1343 // Each axis should really have their own independent animation (time and equation)
1344 // Consider, X axis snapping to nearest grid point (EaseOut over fixed time)
1345 // Consider, Y axis simulating physics to arrive at a point (Physics equation over variable time)
1346 // Currently, the axes have been split however, they both use the same EaseOut equation.
1347 bool ScrollView::SnapWithVelocity(Vector2 velocity)
1349 // Animator takes over now, touches are assumed not to interfere.
1350 // And if touches do interfere, then we'll stop animation, update PrePosition
1351 // to current mScroll's properties, and then resume.
1352 // Note: For Flicking this may work a bit different...
1354 float angle = atan2(velocity.y, velocity.x);
1355 float speed2 = velocity.LengthSquared();
1356 AlphaFunction alphaFunction = mSnapAlphaFunction;
1357 Vector3 positionDuration = Vector3::ONE * mSnapDuration;
1360 FindDirection horizontal = None;
1361 FindDirection vertical = None;
1363 // orthoAngleRange = Angle tolerance within the Exact N,E,S,W direction
1364 // that will be accepted as a general N,E,S,W flick direction.
1366 const float orthoAngleRange = FLICK_ORTHO_ANGLE_RANGE * M_PI / 180.0f;
1367 const float flickSpeedThreshold2 = mFlickSpeedThreshold * mFlickSpeedThreshold;
1369 Vector3 positionSnap = mScrollPrePosition;
1371 // Flick logic X Axis
1373 if(mRulerX->IsEnabled() && mLockAxis != LockHorizontal)
1377 if( speed2 > flickSpeedThreshold2 || // exceeds flick threshold
1378 mInAccessibilityPan ) // With AccessibilityPan its easier to move between snap positions
1380 if((angle >= -orthoAngleRange) && (angle < orthoAngleRange)) // Swiping East
1382 biasX = 0.0f, horizontal = Left;
1384 // This guards against an error where no movement occurs, due to the flick finishing
1385 // before the update-thread has advanced mScrollPostPosition past the the previous snap point.
1386 positionSnap.x += 1.0f;
1388 else if((angle >= M_PI-orthoAngleRange) || (angle < -M_PI+orthoAngleRange)) // Swiping West
1390 biasX = 1.0f, horizontal = Right;
1392 // This guards against an error where no movement occurs, due to the flick finishing
1393 // before the update-thread has advanced mScrollPostPosition past the the previous snap point.
1394 positionSnap.x -= 1.0f;
1399 // Flick logic Y Axis
1401 if(mRulerY->IsEnabled() && mLockAxis != LockVertical)
1405 if( speed2 > flickSpeedThreshold2 || // exceeds flick threshold
1406 mInAccessibilityPan ) // With AccessibilityPan its easier to move between snap positions
1408 if((angle >= M_PI_2-orthoAngleRange) && (angle < M_PI_2+orthoAngleRange)) // Swiping South
1410 biasY = 0.0f, vertical = Up;
1412 else if((angle >= -M_PI_2-orthoAngleRange) && (angle < -M_PI_2+orthoAngleRange)) // Swiping North
1414 biasY = 1.0f, vertical = Down;
1419 // isFlick: Whether this gesture is a flick or not.
1420 bool isFlick = (horizontal != All || vertical != All);
1421 // isFreeFlick: Whether this gesture is a flick under free panning criteria.
1422 bool isFreeFlick = velocity.LengthSquared() > (FREE_FLICK_SPEED_THRESHOLD*FREE_FLICK_SPEED_THRESHOLD);
1424 if(isFlick || isFreeFlick)
1426 positionDuration = Vector3::ONE * mFlickDuration;
1427 alphaFunction = mFlickAlphaFunction;
1430 // Calculate next positionSnap ////////////////////////////////////////////////////////////
1432 if(mActorAutoSnapEnabled)
1434 Vector3 size = Self().GetCurrentSize();
1436 Actor child = FindClosestActorToPosition( Vector3(size.width * 0.5f,size.height * 0.5f,0.0f), horizontal, vertical );
1438 if(!child && isFlick )
1440 // If we conducted a direction limited search and found no actor, then just snap to the closest actor.
1441 child = FindClosestActorToPosition( Vector3(size.width * 0.5f,size.height * 0.5f,0.0f) );
1446 Vector3 position = Self().GetProperty<Vector3>(Toolkit::ScrollView::Property::SCROLL_POSITION);
1448 // Get center-point of the Actor.
1449 Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
1451 if(mRulerX->IsEnabled())
1453 positionSnap.x = position.x - childPosition.x + size.width * 0.5f;
1455 if(mRulerY->IsEnabled())
1457 positionSnap.y = position.y - childPosition.y + size.height * 0.5f;
1462 Vector3 startPosition = positionSnap;
1463 positionSnap.x = -mRulerX->Snap(-positionSnap.x, biasX); // NOTE: X & Y rulers think in -ve coordinate system.
1464 positionSnap.y = -mRulerY->Snap(-positionSnap.y, biasY); // That is scrolling RIGHT (e.g. 100.0, 0.0) means moving LEFT.
1466 Vector3 clampDelta(Vector3::ZERO);
1467 ClampPosition(positionSnap);
1469 if( (mRulerX->GetType() == Ruler::Free || mRulerY->GetType() == Ruler::Free)
1470 && isFreeFlick && !mActorAutoSnapEnabled)
1472 // Calculate target position based on velocity of flick.
1474 // a = Deceleration (Set to diagonal stage length * friction coefficient)
1475 // u = Initial Velocity (Flick velocity)
1476 // v = 0 (Final Velocity)
1477 // t = Time (Velocity / Deceleration)
1478 Vector2 stageSize = Stage::GetCurrent().GetSize();
1479 float stageLength = Vector3(stageSize.x, stageSize.y, 0.0f).Length();
1480 float a = (stageLength * mFrictionCoefficient);
1481 Vector3 u = Vector3(velocity.x, velocity.y, 0.0f) * mFlickSpeedCoefficient;
1482 float speed = u.Length();
1485 // TODO: Change this to a decay function. (faster you flick, the slower it should be)
1486 speed = std::min(speed, stageLength * mMaxFlickSpeed );
1488 alphaFunction = ConstantDecelerationAlphaFunction;
1490 float t = speed / a;
1492 if(mRulerX->IsEnabled() && mRulerX->GetType() == Ruler::Free)
1494 positionSnap.x += t*u.x*0.5f;
1497 if(mRulerY->IsEnabled() && mRulerY->GetType() == Ruler::Free)
1499 positionSnap.y += t*u.y*0.5f;
1502 clampDelta = positionSnap;
1503 ClampPosition(positionSnap);
1504 if((positionSnap - startPosition).LengthSquared() > Math::MACHINE_EPSILON_0)
1506 clampDelta -= positionSnap;
1507 clampDelta.x = clampDelta.x > 0.0f ? std::min(clampDelta.x, mMaxOvershoot.x) : std::max(clampDelta.x, -mMaxOvershoot.x);
1508 clampDelta.y = clampDelta.y > 0.0f ? std::min(clampDelta.y, mMaxOvershoot.y) : std::max(clampDelta.y, -mMaxOvershoot.y);
1512 clampDelta = Vector3::ZERO;
1515 // If Axis is Free and has velocity, then calculate time taken
1516 // to reach target based on velocity in axis.
1517 if(mRulerX->IsEnabled() && mRulerX->GetType() == Ruler::Free)
1519 float deltaX = fabsf(startPosition.x - positionSnap.x);
1521 if(fabsf(u.x) > Math::MACHINE_EPSILON_1)
1523 positionDuration.x = fabsf(deltaX / u.x);
1527 positionDuration.x = 0;
1531 if(mRulerY->IsEnabled() && mRulerY->GetType() == Ruler::Free)
1533 float deltaY = fabsf(startPosition.y - positionSnap.y);
1535 if(fabsf(u.y) > Math::MACHINE_EPSILON_1)
1537 positionDuration.y = fabsf(deltaY / u.y);
1541 positionDuration.y = 0;
1546 if(IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator))
1548 // Scroll to the end of the overshoot only when overshoot is enabled.
1549 positionSnap += clampDelta;
1552 bool animating = AnimateTo(positionSnap, positionDuration,
1553 alphaFunction, false,
1554 DirectionBiasNone, DirectionBiasNone,
1555 isFlick || isFreeFlick ? Flick : Snap);
1560 void ScrollView::StopAnimation(void)
1562 // Clear Snap animation if exists.
1563 StopAnimation(mInternalXAnimation);
1564 StopAnimation(mInternalYAnimation);
1565 mScrollStateFlags = 0;
1566 // remove scroll animation flags
1567 HandleStoppedAnimation();
1570 void ScrollView::StopAnimation(Animation& animation)
1579 bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDuration,
1580 AlphaFunction alpha, bool findShortcuts,
1581 DirectionBias horizontalBias, DirectionBias verticalBias,
1584 // Here we perform an animation on a number of properties (depending on which have changed)
1585 // The animation is applied to all ScrollBases
1586 Actor self = Self();
1587 mScrollTargetPosition = position;
1588 float totalDuration = 0.0f;
1590 bool positionChanged = (mScrollTargetPosition != mScrollPostPosition);
1594 totalDuration = std::max(totalDuration, positionDuration.x);
1595 totalDuration = std::max(totalDuration, positionDuration.y);
1599 // try to animate for a frame, on some occasions update will be changing scroll value while event side thinks it hasnt changed
1600 totalDuration = 0.01f;
1601 positionChanged = true;
1606 // Position Delta ///////////////////////////////////////////////////////
1609 if(mWrapMode && findShortcuts)
1611 // In Wrap Mode, the shortest distance is a little less intuitive...
1612 const RulerDomain rulerDomainX = mRulerX->GetDomain();
1613 const RulerDomain rulerDomainY = mRulerY->GetDomain();
1615 if(mRulerX->IsEnabled())
1617 float dir = VectorInDomain(-mScrollPrePosition.x, -mScrollTargetPosition.x, rulerDomainX.min, rulerDomainX.max, horizontalBias);
1618 mScrollTargetPosition.x = mScrollPrePosition.x + -dir;
1621 if(mRulerY->IsEnabled())
1623 float dir = VectorInDomain(-mScrollPrePosition.y, -mScrollTargetPosition.y, rulerDomainY.min, rulerDomainY.max, verticalBias);
1624 mScrollTargetPosition.y = mScrollPrePosition.y + -dir;
1628 // note we have two separate animations for X & Y, this deals with sliding diagonally and hitting
1629 // a horizonal/vertical wall.delay
1630 AnimateInternalXTo(mScrollTargetPosition.x, positionDuration.x, alpha);
1631 AnimateInternalYTo(mScrollTargetPosition.y, positionDuration.y, alpha);
1633 if( !(mScrollStateFlags & SCROLL_ANIMATION_FLAGS) )
1635 DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollTargetPosition.x, mScrollTargetPosition.y );
1636 self.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollTargetPosition);
1637 mScrollPrePosition = mScrollTargetPosition;
1638 mScrollPostPosition = mScrollTargetPosition;
1639 WrapPosition(mScrollPostPosition);
1642 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 );
1643 DALI_LOG_SCROLL_STATE("[0x%X] SCROLL_PRE_POSITION[%.2f, %.2f], SCROLL_POSITION[%.2f, %.2f]", this, self.GetProperty( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ).Get<Vector3>().x, self.GetProperty( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ).Get<Vector3>().y, self.GetProperty( Toolkit::ScrollView::Property::SCROLL_POSITION ).Get<Vector3>().x, self.GetProperty( Toolkit::ScrollView::Property::SCROLL_POSITION ).Get<Vector3>().y );
1646 SetScrollUpdateNotification(true);
1648 // Always send a snap event when AnimateTo is called.
1649 Toolkit::ScrollView::SnapEvent snapEvent;
1650 snapEvent.type = snapType;
1651 snapEvent.position = -mScrollTargetPosition;
1652 snapEvent.duration = totalDuration;
1654 DALI_LOG_SCROLL_STATE("[0x%X] mSnapStartedSignal [%.2f, %.2f]", this, snapEvent.position.x, snapEvent.position.y);
1655 mSnapStartedSignal.Emit( snapEvent );
1657 return (mScrollStateFlags & SCROLL_ANIMATION_FLAGS) != 0;
1660 void ScrollView::SetOvershootEnabled(bool enabled)
1662 if(enabled && !mOvershootIndicator)
1664 mOvershootIndicator = ScrollOvershootIndicator::New();
1668 mOvershootIndicator->AttachToScrollable(*this);
1672 mMaxOvershoot = mUserMaxOvershoot;
1673 mOvershootIndicator->DetachFromScrollable(*this);
1675 UpdateMainInternalConstraint();
1678 void ScrollView::AddOverlay(Actor actor)
1680 mInternalActor.Add( actor );
1683 void ScrollView::RemoveOverlay(Actor actor)
1685 mInternalActor.Remove( actor );
1688 void ScrollView::SetOvershootEffectColor( const Vector4& color )
1690 mOvershootEffectColor = color;
1691 if( mOvershootIndicator )
1693 mOvershootIndicator->SetOvershootEffectColor( color );
1697 void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
1699 PanGestureDetector panGesture( GetPanGestureDetector() );
1701 // First remove just in case we have some set, then add.
1702 panGesture.RemoveDirection( direction );
1703 panGesture.AddDirection( direction, threshold );
1706 void ScrollView::RemoveScrollingDirection( Radian direction )
1708 PanGestureDetector panGesture( GetPanGestureDetector() );
1709 panGesture.RemoveDirection( direction );
1712 Toolkit::ScrollView::SnapStartedSignalType& ScrollView::SnapStartedSignal()
1714 return mSnapStartedSignal;
1717 void ScrollView::FindAndUnbindActor(Actor child)
1722 Vector3 ScrollView::GetPropertyPrePosition() const
1724 Vector3 position = Self().GetProperty<Vector3>(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION);
1725 WrapPosition(position);
1729 Vector3 ScrollView::GetPropertyPosition() const
1731 Vector3 position = Self().GetProperty<Vector3>(Toolkit::ScrollView::Property::SCROLL_POSITION);
1732 WrapPosition(position);
1737 void ScrollView::HandleStoppedAnimation()
1739 SetScrollUpdateNotification(false);
1742 void ScrollView::HandleSnapAnimationFinished()
1744 // Emit Signal that scrolling has completed.
1746 Actor self = Self();
1747 self.SetProperty(Toolkit::ScrollView::Property::SCROLLING, false);
1749 Vector3 deltaPosition(mScrollPrePosition);
1751 UpdateLocalScrollProperties();
1752 WrapPosition(mScrollPrePosition);
1753 DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
1754 self.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPrePosition);
1756 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1757 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 3 current[%.2f, %.2f], mScrollTargetPosition[%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y, -mScrollTargetPosition.x, -mScrollTargetPosition.y );
1758 mScrollCompletedSignal.Emit( currentScrollPosition );
1760 mDomainOffset += deltaPosition - mScrollPostPosition;
1761 self.SetProperty(Toolkit::ScrollView::Property::SCROLL_DOMAIN_OFFSET, mDomainOffset);
1762 HandleStoppedAnimation();
1765 void ScrollView::SetScrollUpdateNotification( bool enabled )
1767 Actor self = Self();
1768 if( mScrollXUpdateNotification )
1770 // disconnect now to avoid a notification before removed from update thread
1771 mScrollXUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
1772 self.RemovePropertyNotification(mScrollXUpdateNotification);
1773 mScrollXUpdateNotification.Reset();
1775 if( enabled && !mScrollUpdatedSignal.Empty())
1777 // Only set up the notification when the application has connected to the updated signal
1778 mScrollXUpdateNotification = self.AddPropertyNotification(Toolkit::ScrollView::Property::SCROLL_POSITION, 0, StepCondition(mScrollUpdateDistance, 0.0f));
1779 mScrollXUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification );
1781 if( mScrollYUpdateNotification )
1783 // disconnect now to avoid a notification before removed from update thread
1784 mScrollYUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
1785 self.RemovePropertyNotification(mScrollYUpdateNotification);
1786 mScrollYUpdateNotification.Reset();
1788 if( enabled && !mScrollUpdatedSignal.Empty())
1790 // Only set up the notification when the application has connected to the updated signal
1791 mScrollYUpdateNotification = self.AddPropertyNotification(Toolkit::ScrollView::Property::SCROLL_POSITION, 1, StepCondition(mScrollUpdateDistance, 0.0f));
1792 mScrollYUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification );
1796 void ScrollView::OnScrollUpdateNotification(Dali::PropertyNotification& source)
1798 // Guard against destruction during signal emission
1799 Toolkit::ScrollView handle( GetOwner() );
1801 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1802 mScrollUpdatedSignal.Emit( currentScrollPosition );
1805 bool ScrollView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1807 Dali::BaseHandle handle( object );
1809 bool connected( true );
1810 Toolkit::ScrollView view = Toolkit::ScrollView::DownCast( handle );
1812 if( 0 == strcmp( signalName.c_str(), SIGNAL_SNAP_STARTED ) )
1814 view.SnapStartedSignal().Connect( tracker, functor );
1818 // signalName does not match any signal
1825 void ScrollView::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1827 // need to update domain properties for new size
1828 UpdatePropertyDomain(targetSize);
1831 void ScrollView::OnControlSizeSet( const Vector3& size )
1833 // need to update domain properties for new size
1834 if( mDefaultMaxOvershoot )
1836 mUserMaxOvershoot.x = size.x * 0.5f;
1837 mUserMaxOvershoot.y = size.y * 0.5f;
1838 if( !IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
1840 mMaxOvershoot = mUserMaxOvershoot;
1843 UpdatePropertyDomain(size);
1844 UpdateMainInternalConstraint();
1845 if( IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
1847 mOvershootIndicator->Reset();
1851 void ScrollView::OnChildAdd(Actor& child)
1859 void ScrollView::OnChildRemove(Actor& child)
1861 // TODO: Actor needs a RemoveConstraint method to take out an individual constraint.
1865 void ScrollView::StartTouchDownTimer()
1867 if ( !mTouchDownTimer )
1869 mTouchDownTimer = Timer::New( TOUCH_DOWN_TIMER_INTERVAL );
1870 mTouchDownTimer.TickSignal().Connect( this, &ScrollView::OnTouchDownTimeout );
1873 mTouchDownTimer.Start();
1876 void ScrollView::StopTouchDownTimer()
1878 if ( mTouchDownTimer )
1880 mTouchDownTimer.Stop();
1884 bool ScrollView::OnTouchDownTimeout()
1886 DALI_LOG_SCROLL_STATE("[0x%X]", this);
1888 mTouchDownTimeoutReached = true;
1890 unsigned int currentScrollStateFlags( mScrollStateFlags ); // Cleared in StopAnimation so keep local copy for comparison
1891 if( currentScrollStateFlags & (SCROLL_ANIMATION_FLAGS | SNAP_ANIMATION_FLAGS) )
1893 DALI_LOG_SCROLL_STATE("[0x%X] Scrolling Or snapping flags set, stopping animation", this);
1896 if( currentScrollStateFlags & SCROLL_ANIMATION_FLAGS )
1898 DALI_LOG_SCROLL_STATE("[0x%X] Scrolling flags set, emitting signal", this);
1900 mScrollInterrupted = true;
1901 // reset domain offset as scrolling from original plane.
1902 mDomainOffset = Vector3::ZERO;
1903 Self().SetProperty(Toolkit::ScrollView::Property::SCROLL_DOMAIN_OFFSET, Vector3::ZERO);
1905 UpdateLocalScrollProperties();
1906 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1907 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 4 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
1908 mScrollCompletedSignal.Emit( currentScrollPosition );
1915 bool ScrollView::OnTouchEvent(const TouchEvent& event)
1919 DALI_LOG_SCROLL_STATE("[0x%X], Not Sensitive, ignoring", this);
1921 // Ignore this touch event, if scrollview is insensitive.
1925 // Ignore events with multiple-touch points
1926 if (event.GetPointCount() != 1)
1928 DALI_LOG_SCROLL_STATE("[0x%X], multiple touch, ignoring", this);
1933 const TouchPoint::State pointState = event.GetPoint(0).state;
1934 if( pointState == TouchPoint::Down )
1936 DALI_LOG_SCROLL_STATE("[0x%X] Down", this);
1938 if(mGestureStackDepth==0)
1940 mTouchDownTime = event.time;
1942 // This allows time for a pan-gesture to start, to avoid breaking snap-animation behavior with fast flicks.
1943 // If touch-down does not become a pan (after timeout interval), then snap-animation can be interrupted.
1944 mTouchDownTimeoutReached = false;
1945 mScrollInterrupted = false;
1946 StartTouchDownTimer();
1949 else if( ( pointState == TouchPoint::Up ) ||
1950 ( ( pointState == TouchPoint::Interrupted ) && ( event.GetPoint(0).hitActor == Self() ) ) )
1952 DALI_LOG_SCROLL_STATE("[0x%X] %s", this, ( ( pointState == TouchPoint::Up ) ? "Up" : "Interrupted" ) );
1954 StopTouchDownTimer();
1956 // if the user touches and releases without enough movement to go
1957 // into a gesture state, then we should snap to nearest point.
1958 // otherwise our scroll could be stopped (interrupted) half way through an animation.
1959 if(mGestureStackDepth==0 && mTouchDownTimeoutReached)
1961 if( ( event.GetPoint(0).state == TouchPoint::Interrupted ) ||
1962 ( ( event.time - mTouchDownTime ) >= MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET ) )
1964 // Reset the velocity only if down was received a while ago
1965 mLastVelocity = Vector2( 0.0f, 0.0f );
1968 UpdateLocalScrollProperties();
1969 // Only finish the transform if scrolling was interrupted on down or if we are scrolling
1970 if ( mScrollInterrupted || mScrolling )
1972 DALI_LOG_SCROLL_STATE("[0x%X] Calling FinishTransform", this);
1977 mTouchDownTimeoutReached = false;
1978 mScrollInterrupted = false;
1984 bool ScrollView::OnMouseWheelEvent(const MouseWheelEvent& event)
1988 // Ignore this mouse wheel event, if scrollview is insensitive.
1992 Vector3 targetScrollPosition = GetPropertyPosition();
1994 if(mRulerX->IsEnabled() && !mRulerY->IsEnabled())
1996 // If only the ruler in the X axis is enabled, scroll in the X axis.
1997 if(mRulerX->GetType() == Ruler::Free)
1999 // Free panning mode
2000 targetScrollPosition.x += event.z * mMouseWheelScrollDistanceStep.x;
2001 ClampPosition(targetScrollPosition);
2002 ScrollTo(-targetScrollPosition);
2004 else if(!mScrolling)
2006 // Snap mode, only respond to the event when the previous snap animation is finished.
2007 ScrollTo(GetCurrentPage() - event.z);
2012 // If the ruler in the Y axis is enabled, scroll in the Y axis.
2013 if(mRulerY->GetType() == Ruler::Free)
2015 // Free panning mode
2016 targetScrollPosition.y += event.z * mMouseWheelScrollDistanceStep.y;
2017 ClampPosition(targetScrollPosition);
2018 ScrollTo(-targetScrollPosition);
2020 else if(!mScrolling)
2022 // Snap mode, only respond to the event when the previous snap animation is finished.
2023 ScrollTo(GetCurrentPage() - event.z * mRulerX->GetTotalPages());
2030 void ScrollView::ResetScrolling()
2032 Actor self = Self();
2033 self.GetProperty(Toolkit::ScrollView::Property::SCROLL_POSITION).Get(mScrollPostPosition);
2034 mScrollPrePosition = mScrollPostPosition;
2035 DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPostPosition.x, mScrollPostPosition.y );
2036 self.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPostPosition);
2039 void ScrollView::UpdateLocalScrollProperties()
2041 Actor self = Self();
2042 self.GetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get(mScrollPrePosition);
2043 self.GetProperty(Toolkit::ScrollView::Property::SCROLL_POSITION).Get(mScrollPostPosition);
2046 // private functions
2048 void ScrollView::PreAnimatedScrollSetup()
2050 // SCROLL_PRE_POSITION is our unclamped property with wrapping
2051 // SCROLL_POSITION is our final scroll position after clamping
2053 Actor self = Self();
2055 Vector3 deltaPosition(mScrollPostPosition);
2056 WrapPosition(mScrollPostPosition);
2057 mDomainOffset += deltaPosition - mScrollPostPosition;
2058 Self().SetProperty(Toolkit::ScrollView::Property::SCROLL_DOMAIN_OFFSET, mDomainOffset);
2060 if( mScrollStateFlags & SCROLL_X_STATE_MASK )
2062 // already performing animation on internal x position
2063 StopAnimation(mInternalXAnimation);
2066 if( mScrollStateFlags & SCROLL_Y_STATE_MASK )
2068 // already performing animation on internal y position
2069 StopAnimation(mInternalYAnimation);
2072 mScrollStateFlags = 0;
2074 // Update Actor position with this wrapped value.
2077 void ScrollView::FinaliseAnimatedScroll()
2079 // TODO - common animation finishing code in here
2082 void ScrollView::AnimateInternalXTo( float position, float duration, AlphaFunction alpha )
2084 StopAnimation(mInternalXAnimation);
2086 if( duration > Math::MACHINE_EPSILON_10 )
2088 Actor self = Self();
2089 DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get<Vector3>().x, position );
2090 mInternalXAnimation = Animation::New(duration);
2091 DALI_LOG_SCROLL_STATE("[0x%X], mInternalXAnimation[0x%X]", this, mInternalXAnimation.GetObjectPtr() );
2092 mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
2093 mInternalXAnimation.AnimateTo( Property(self, Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, 0), position, alpha, TimePeriod(duration));
2094 mInternalXAnimation.Play();
2096 // erase current state flags
2097 mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
2098 // add internal animation state flag
2099 mScrollStateFlags |= AnimatingInternalX;
2103 void ScrollView::AnimateInternalYTo( float position, float duration, AlphaFunction alpha )
2105 StopAnimation(mInternalYAnimation);
2107 if( duration > Math::MACHINE_EPSILON_10 )
2109 Actor self = Self();
2110 DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get<Vector3>().y, position );
2111 mInternalYAnimation = Animation::New(duration);
2112 DALI_LOG_SCROLL_STATE("[0x%X], mInternalYAnimation[0x%X]", this, mInternalYAnimation.GetObjectPtr() );
2113 mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
2114 mInternalYAnimation.AnimateTo( Property(self, Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, 1), position, alpha, TimePeriod(duration));
2115 mInternalYAnimation.Play();
2117 // erase current state flags
2118 mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
2119 // add internal animation state flag
2120 mScrollStateFlags |= AnimatingInternalY;
2124 void ScrollView::OnScrollAnimationFinished( Animation& source )
2126 // Guard against destruction during signal emission
2127 // Note that ScrollCompletedSignal is emitted from HandleSnapAnimationFinished()
2128 Toolkit::ScrollView handle( GetOwner() );
2130 bool scrollingFinished = false;
2132 // update our local scroll positions
2133 UpdateLocalScrollProperties();
2135 if( source == mInternalXAnimation )
2137 DALI_LOG_SCROLL_STATE("[0x%X] mInternalXAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalXAnimation.GetObjectPtr(), mScrollTargetPosition.x, Self().GetProperty(SCROLL_PRE_POSITION).Get<Vector3>().x, mScrollPostPosition.x );
2139 if( !(mScrollStateFlags & AnimatingInternalY) )
2141 scrollingFinished = true;
2143 mInternalXAnimation.Reset();
2144 // wrap pre scroll x position and set it
2147 const RulerDomain rulerDomain = mRulerX->GetDomain();
2148 mScrollPrePosition.x = -WrapInDomain(-mScrollPrePosition.x, rulerDomain.min, rulerDomain.max);
2149 DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
2150 handle.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPrePosition);
2152 SnapInternalXTo(mScrollPostPosition.x);
2155 if( source == mInternalYAnimation )
2157 DALI_LOG_SCROLL_STATE("[0x%X] mInternalYAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalYAnimation.GetObjectPtr(), mScrollTargetPosition.y, Self().GetProperty(SCROLL_PRE_POSITION).Get<Vector3>().y, mScrollPostPosition.y );
2159 if( !(mScrollStateFlags & AnimatingInternalX) )
2161 scrollingFinished = true;
2163 mInternalYAnimation.Reset();
2166 // wrap pre scroll y position and set it
2167 const RulerDomain rulerDomain = mRulerY->GetDomain();
2168 mScrollPrePosition.y = -WrapInDomain(-mScrollPrePosition.y, rulerDomain.min, rulerDomain.max);
2169 DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
2170 handle.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPrePosition);
2172 SnapInternalYTo(mScrollPostPosition.y);
2175 DALI_LOG_SCROLL_STATE("[0x%X] scrollingFinished[%d] Animation[0x%X]", this, scrollingFinished, source.GetObjectPtr());
2177 if(scrollingFinished)
2179 HandleSnapAnimationFinished();
2183 void ScrollView::OnSnapInternalPositionFinished( Animation& source )
2185 Actor self = Self();
2186 UpdateLocalScrollProperties();
2187 if( source == mInternalXAnimation )
2189 DALI_LOG_SCROLL_STATE("[0x%X] Finished X PostPosition Animation", this );
2191 // clear internal x animation flags
2192 mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
2193 mInternalXAnimation.Reset();
2194 WrapPosition(mScrollPrePosition);
2196 if( source == mInternalYAnimation )
2198 DALI_LOG_SCROLL_STATE("[0x%X] Finished Y PostPosition Animation", this );
2200 mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
2201 mInternalYAnimation.Reset();
2202 WrapPosition(mScrollPrePosition);
2206 void ScrollView::SnapInternalXTo(float position)
2208 Actor self = Self();
2210 StopAnimation(mInternalXAnimation);
2212 // erase current state flags
2213 mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
2215 // if internal x not equal to inputed parameter, animate it
2216 float duration = std::min(fabsf((position - mScrollPrePosition.x) / mMaxOvershoot.x) * mSnapOvershootDuration, mSnapOvershootDuration);
2217 DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration );
2218 if( duration > Math::MACHINE_EPSILON_1 )
2220 DALI_LOG_SCROLL_STATE("[0x%X] Starting X Snap Animation to[%.2f]", this, position );
2222 mInternalXAnimation = Animation::New(duration);
2223 mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
2224 mInternalXAnimation.AnimateTo(Property(self, Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, 0), position);
2225 mInternalXAnimation.Play();
2227 // add internal animation state flag
2228 mScrollStateFlags |= SnappingInternalX;
2232 void ScrollView::SnapInternalYTo(float position)
2234 Actor self = Self();
2236 StopAnimation(mInternalYAnimation);
2238 // erase current state flags
2239 mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
2241 // if internal y not equal to inputed parameter, animate it
2242 float duration = std::min(fabsf((position - mScrollPrePosition.y) / mMaxOvershoot.y) * mSnapOvershootDuration, mSnapOvershootDuration);
2243 DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration );
2244 if( duration > Math::MACHINE_EPSILON_1 )
2246 DALI_LOG_SCROLL_STATE("[0x%X] Starting Y Snap Animation to[%.2f]", this, position );
2248 mInternalYAnimation = Animation::New(duration);
2249 mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
2250 mInternalYAnimation.AnimateTo(Property(self, Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, 1), position);
2251 mInternalYAnimation.Play();
2253 // add internal animation state flag
2254 mScrollStateFlags |= SnappingInternalY;
2258 void ScrollView::GestureStarted()
2260 // we handle the first gesture.
2261 // if we're currently doing a gesture and receive another
2262 // we continue and combine the effects of the gesture instead of reseting.
2263 if(mGestureStackDepth++==0)
2265 Actor self = Self();
2266 StopTouchDownTimer();
2268 mPanDelta = Vector3::ZERO;
2269 mLastVelocity = Vector2(0.0f, 0.0f);
2272 mLockAxis = LockPossible;
2275 if( mScrollStateFlags & SCROLL_X_STATE_MASK )
2277 StopAnimation(mInternalXAnimation);
2279 if( mScrollStateFlags & SCROLL_Y_STATE_MASK )
2281 StopAnimation(mInternalYAnimation);
2283 mScrollStateFlags = 0;
2285 if(mScrolling) // are we interrupting a current scroll?
2287 // set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete.
2289 // send negative scroll position since scroll internal scroll position works as an offset for actors,
2290 // give applications the position within the domain from the scroll view's anchor position
2291 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 5 [%.2f, %.2f]", this, -mScrollPostPosition.x, -mScrollPostPosition.y);
2292 mScrollCompletedSignal.Emit( -mScrollPostPosition );
2297 void ScrollView::GestureContinuing(const Vector2& panDelta)
2299 mPanDelta.x+= panDelta.x;
2300 mPanDelta.y+= panDelta.y;
2302 // Save the velocity, there is a bug in PanGesture
2303 // Whereby the Gesture::Finished's velocity is either:
2304 // NaN (due to time delta of zero between the last two events)
2305 // or 0 (due to position being the same between the last two events)
2307 // Axis Auto Lock - locks the panning to the horizontal or vertical axis if the pan
2308 // appears mostly horizontal or mostly vertical respectively.
2311 mLockAxis = GetLockAxis(mPanDelta.GetVectorXY(), mLockAxis, mAxisAutoLockGradient);
2312 } // end if mAxisAutoLock
2315 // TODO: Upgrade to use a more powerful gesture detector (one that supports multiple touches on pan - so works as pan and flick gesture)
2316 // BUG: Gesture::Finished doesn't always return velocity on release (due to
2317 // timeDelta between last two events being 0 sometimes, or posiiton being the same)
2318 void ScrollView::OnPan( const PanGesture& gesture )
2320 // Guard against destruction during signal emission
2321 // Note that Emit() methods are called indirectly e.g. from within ScrollView::OnGestureEx()
2322 Actor self( Self() );
2326 DALI_LOG_SCROLL_STATE("[0x%X] Pan Ignored, Insensitive", this);
2328 // If another callback on the same original signal disables sensitivity,
2329 // this callback will still be called, so we must suppress it.
2333 // translate Gesture input to get useful data...
2334 switch(gesture.state)
2336 case Gesture::Started:
2338 DALI_LOG_SCROLL_STATE("[0x%X] Pan Started", this);
2339 mPanStartPosition = gesture.position - gesture.displacement;
2340 UpdateLocalScrollProperties();
2343 self.SetProperty( Toolkit::ScrollView::Property::PANNING, true );
2344 self.SetProperty( Toolkit::ScrollView::Property::START_PAGE_POSITION, Vector3(gesture.position.x, gesture.position.y, 0.0f) );
2346 UpdateMainInternalConstraint();
2350 case Gesture::Continuing:
2354 DALI_LOG_SCROLL_STATE("[0x%X] Pan Continuing", this);
2355 GestureContinuing(gesture.screenDisplacement);
2359 // If we do not think we are panning, then we should not do anything here
2365 case Gesture::Finished:
2366 case Gesture::Cancelled:
2370 DALI_LOG_SCROLL_STATE("[0x%X] Pan %s", this, ( ( gesture.state == Gesture::Finished ) ? "Finished" : "Cancelled" ) );
2372 UpdateLocalScrollProperties();
2373 mLastVelocity = gesture.velocity;
2375 self.SetProperty( Toolkit::ScrollView::Property::PANNING, false );
2377 if( mScrollMainInternalPrePositionConstraint )
2379 mScrollMainInternalPrePositionConstraint.Remove();
2382 if( mOvershootIndicator )
2384 mOvershootIndicator->ClearOvershoot();
2389 // If we do not think we are panning, then we should not do anything here
2395 case Gesture::Possible:
2396 case Gesture::Clear:
2398 // Nothing to do, not needed.
2402 } // end switch(gesture.state)
2404 OnGestureEx(gesture.state);
2407 void ScrollView::OnGestureEx(Gesture::State state)
2409 // call necessary signals for application developer
2411 if(state == Gesture::Started)
2413 Vector3 currentScrollPosition = GetCurrentScrollPosition();
2414 Self().SetProperty(Toolkit::ScrollView::Property::SCROLLING, true);
2416 DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignal 2 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
2417 mScrollStartedSignal.Emit( currentScrollPosition );
2419 else if( (state == Gesture::Finished) ||
2420 (state == Gesture::Cancelled) ) // Finished/default
2422 // when all the gestures have finished, we finish the transform.
2423 // so if a user decides to pan (1 gesture), and then pan+zoom (2 gestures)
2424 // then stop panning (back to 1 gesture), and then stop zooming (0 gestures).
2425 // this is the point we end, and perform necessary snapping.
2426 mGestureStackDepth--;
2427 if(mGestureStackDepth==0)
2429 // no flick if we have not exceeded min flick distance
2430 if( (fabsf(mPanDelta.x) < mMinFlickDistance.x)
2431 && (fabsf(mPanDelta.y) < mMinFlickDistance.y) )
2433 // reset flick velocity
2434 mLastVelocity = Vector2::ZERO;
2440 DALI_LOG_SCROLL_STATE("[0x%X] mGestureStackDepth[%d]", this, mGestureStackDepth);
2445 void ScrollView::FinishTransform()
2447 // at this stage internal x and x scroll position should have followed prescroll position exactly
2448 Actor self = Self();
2450 PreAnimatedScrollSetup();
2452 // convert pixels/millisecond to pixels per second
2453 bool animating = SnapWithVelocity(mLastVelocity * 1000.0f);
2457 // if not animating, then this pan has completed right now.
2458 SetScrollUpdateNotification(false);
2460 Self().SetProperty(Toolkit::ScrollView::Property::SCROLLING, false);
2462 if( fabs(mScrollPrePosition.x - mScrollTargetPosition.x) > Math::MACHINE_EPSILON_10 )
2464 SnapInternalXTo(mScrollTargetPosition.x);
2466 if( fabs(mScrollPrePosition.y - mScrollTargetPosition.y) > Math::MACHINE_EPSILON_10 )
2468 SnapInternalYTo(mScrollTargetPosition.y);
2470 Vector3 currentScrollPosition = GetCurrentScrollPosition();
2471 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignal 6 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
2472 mScrollCompletedSignal.Emit( currentScrollPosition );
2476 Vector3 ScrollView::GetOvershoot(Vector3& position) const
2478 Vector3 size = Self().GetCurrentSize();
2481 const RulerDomain rulerDomainX = mRulerX->GetDomain();
2482 const RulerDomain rulerDomainY = mRulerY->GetDomain();
2484 if(mRulerX->IsEnabled() && rulerDomainX.enabled)
2486 const float left = rulerDomainX.min - position.x;
2487 const float right = size.width - rulerDomainX.max - position.x;
2494 overshoot.x = right;
2498 if(mRulerY->IsEnabled() && rulerDomainY.enabled)
2500 const float top = rulerDomainY.min - position.y;
2501 const float bottom = size.height - rulerDomainY.max - position.y;
2508 overshoot.y = bottom;
2515 bool ScrollView::OnAccessibilityPan(PanGesture gesture)
2517 // Keep track of whether this is an AccessibilityPan
2518 mInAccessibilityPan = true;
2520 mInAccessibilityPan = false;
2525 void ScrollView::ClampPosition(Vector3& position) const
2527 ClampState3D clamped;
2528 ClampPosition(position, clamped);
2531 void ScrollView::ClampPosition(Vector3& position, ClampState3D &clamped) const
2533 Vector3 size = Self().GetCurrentSize();
2535 position.x = -mRulerX->Clamp(-position.x, size.width, 1.0f, clamped.x); // NOTE: X & Y rulers think in -ve coordinate system.
2536 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.
2538 clamped.z = NotClamped;
2541 void ScrollView::WrapPosition(Vector3& position) const
2545 const RulerDomain rulerDomainX = mRulerX->GetDomain();
2546 const RulerDomain rulerDomainY = mRulerY->GetDomain();
2548 if(mRulerX->IsEnabled())
2550 position.x = -WrapInDomain(-position.x, rulerDomainX.min, rulerDomainX.max);
2553 if(mRulerY->IsEnabled())
2555 position.y = -WrapInDomain(-position.y, rulerDomainY.min, rulerDomainY.max);
2560 void ScrollView::UpdateMainInternalConstraint()
2562 // TODO: Only update the constraints which have changed, rather than remove all and add all again.
2563 // Requires a dali-core ApplyConstraintAt, or a ReplaceConstraint. The former is probably more flexible.
2564 Actor self = Self();
2565 PanGestureDetector detector( GetPanGestureDetector() );
2567 if(mScrollMainInternalPositionConstraint)
2569 mScrollMainInternalPositionConstraint.Remove();
2570 mScrollMainInternalDeltaConstraint.Remove();
2571 mScrollMainInternalFinalConstraint.Remove();
2572 mScrollMainInternalRelativeConstraint.Remove();
2574 if( mScrollMainInternalPrePositionConstraint )
2576 mScrollMainInternalPrePositionConstraint.Remove();
2579 // TODO: It's probably better to use a local displacement value as this will give a displacement when scrolling just commences
2580 // but we need to make sure than the gesture system gives displacement since last frame (60Hz), not displacement since last touch event (90Hz).
2582 // 1. First calculate the pre-position (this is the scroll position if no clamping has taken place)
2583 Vector2 initialPanMask = Vector2(mRulerX->IsEnabled() ? 1.0f : 0.0f, mRulerY->IsEnabled() ? 1.0f : 0.0f);
2585 if( mLockAxis == LockVertical )
2587 initialPanMask.y = 0.0f;
2589 else if( mLockAxis == LockHorizontal )
2591 initialPanMask.x = 0.0f;
2596 mScrollMainInternalPrePositionConstraint = Constraint::New<Vector3>( self,
2597 Toolkit::ScrollView::Property::SCROLL_PRE_POSITION,
2598 InternalPrePositionConstraint( mPanStartPosition,
2601 mAxisAutoLockGradient,
2604 mRulerX->GetDomain(),
2605 mRulerY->GetDomain() ) );
2606 mScrollMainInternalPrePositionConstraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2607 mScrollMainInternalPrePositionConstraint.AddSource( Source( self, Actor::Property::SIZE ) );
2608 mScrollMainInternalPrePositionConstraint.Apply();
2611 // 2. Second calculate the clamped position (actual position)
2612 mScrollMainInternalPositionConstraint = Constraint::New<Vector3>( self,
2613 Toolkit::ScrollView::Property::SCROLL_POSITION,
2614 InternalPositionConstraint( mRulerX->GetDomain(),
2615 mRulerY->GetDomain(),
2617 mScrollMainInternalPositionConstraint.AddSource( LocalSource( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ) );
2618 mScrollMainInternalPositionConstraint.AddSource( LocalSource( Toolkit::Scrollable::Property::SCROLL_POSITION_MIN ) );
2619 mScrollMainInternalPositionConstraint.AddSource( LocalSource( Toolkit::Scrollable::Property::SCROLL_POSITION_MAX ) );
2620 mScrollMainInternalPositionConstraint.AddSource( Source( self, Actor::Property::SIZE ) );
2621 mScrollMainInternalPositionConstraint.Apply();
2623 mScrollMainInternalDeltaConstraint = Constraint::New<Vector3>( self, Toolkit::ScrollView::Property::SCROLL_POSITION_DELTA, InternalPositionDeltaConstraint );
2624 mScrollMainInternalDeltaConstraint.AddSource( LocalSource( Toolkit::ScrollView::Property::SCROLL_POSITION ) );
2625 mScrollMainInternalDeltaConstraint.AddSource( LocalSource( Toolkit::ScrollView::Property::SCROLL_DOMAIN_OFFSET ) );
2626 mScrollMainInternalDeltaConstraint.Apply();
2628 mScrollMainInternalFinalConstraint = Constraint::New<Vector3>( self, Toolkit::ScrollView::Property::SCROLL_FINAL,
2629 InternalFinalConstraint( FinalDefaultAlphaFunction,
2630 FinalDefaultAlphaFunction ) );
2631 mScrollMainInternalFinalConstraint .AddSource( LocalSource( Toolkit::ScrollView::Property::SCROLL_POSITION ) );
2632 mScrollMainInternalFinalConstraint .AddSource( LocalSource( Toolkit::ScrollView::Property::OVERSHOOT_X ) );
2633 mScrollMainInternalFinalConstraint .AddSource( LocalSource( Toolkit::ScrollView::Property::OVERSHOOT_Y ) );
2634 mScrollMainInternalFinalConstraint.Apply();
2636 mScrollMainInternalRelativeConstraint = Constraint::New<Vector3>( self, Toolkit::Scrollable::Property::SCROLL_RELATIVE_POSITION, InternalRelativePositionConstraint );
2637 mScrollMainInternalRelativeConstraint.AddSource( LocalSource( Toolkit::ScrollView::Property::SCROLL_POSITION ) );
2638 mScrollMainInternalRelativeConstraint.AddSource( LocalSource( Toolkit::Scrollable::Property::SCROLL_POSITION_MIN ) );
2639 mScrollMainInternalRelativeConstraint.AddSource( LocalSource( Toolkit::Scrollable::Property::SCROLL_POSITION_MAX ) );
2640 mScrollMainInternalRelativeConstraint.AddSource( LocalSource( Actor::Property::SIZE ) );
2641 mScrollMainInternalRelativeConstraint.Apply();
2643 // When panning we want to make sure overshoot values are affected by pre position and post position
2644 SetOvershootConstraintsEnabled(!mWrapMode);
2647 void ScrollView::SetOvershootConstraintsEnabled(bool enabled)
2649 Actor self( Self() );
2650 // remove and reset, it may now be in wrong order with the main internal constraints
2651 if( mScrollMainInternalOvershootXConstraint )
2653 mScrollMainInternalOvershootXConstraint.Remove();
2654 mScrollMainInternalOvershootXConstraint.Reset();
2655 mScrollMainInternalOvershootYConstraint.Remove();
2656 mScrollMainInternalOvershootYConstraint.Reset();
2660 mScrollMainInternalOvershootXConstraint= Constraint::New<float>( self, Toolkit::ScrollView::Property::OVERSHOOT_X, OvershootXConstraint(mMaxOvershoot.x) );
2661 mScrollMainInternalOvershootXConstraint.AddSource( LocalSource( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ) );
2662 mScrollMainInternalOvershootXConstraint.AddSource( LocalSource( Toolkit::ScrollView::Property::SCROLL_POSITION ) );
2663 mScrollMainInternalOvershootXConstraint.AddSource( LocalSource( Toolkit::Scrollable::Property::CAN_SCROLL_HORIZONTAL ) );
2664 mScrollMainInternalOvershootXConstraint.Apply();
2666 mScrollMainInternalOvershootYConstraint = Constraint::New<float>( self, Toolkit::ScrollView::Property::OVERSHOOT_Y, OvershootYConstraint(mMaxOvershoot.y) );
2667 mScrollMainInternalOvershootYConstraint.AddSource( LocalSource( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ) );
2668 mScrollMainInternalOvershootYConstraint.AddSource( LocalSource( Toolkit::ScrollView::Property::SCROLL_POSITION ) );
2669 mScrollMainInternalOvershootYConstraint.AddSource( LocalSource( Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL ) );
2670 mScrollMainInternalOvershootYConstraint.Apply();
2674 self.SetProperty(Toolkit::ScrollView::Property::OVERSHOOT_X, 0.0f);
2675 self.SetProperty(Toolkit::ScrollView::Property::OVERSHOOT_Y, 0.0f);
2679 void ScrollView::SetInternalConstraints()
2681 // Internal constraints (applied to target ScrollBase Actor itself) /////////
2682 UpdateMainInternalConstraint();
2684 // User definable constraints to apply to all child actors //////////////////
2685 Actor self = Self();
2687 // Apply some default constraints to ScrollView & its bound actors
2688 // Movement + Wrap function
2690 Constraint constraint;
2692 // MoveActor (scrolling)
2693 constraint = Constraint::New<Vector3>( self, Actor::Property::POSITION, MoveActorConstraint );
2694 constraint.AddSource( Source( self, Toolkit::ScrollView::Property::SCROLL_POSITION ) );
2695 constraint.SetRemoveAction(Constraint::Discard);
2696 ApplyConstraintToBoundActors(constraint);
2698 // WrapActor (wrap functionality)
2699 constraint = Constraint::New<Vector3>( self, Actor::Property::POSITION, WrapActorConstraint );
2700 constraint.AddSource( LocalSource( Actor::Property::SCALE ) );
2701 constraint.AddSource( LocalSource( Actor::Property::ANCHOR_POINT ) );
2702 constraint.AddSource( LocalSource( Actor::Property::SIZE ) );
2703 constraint.AddSource( Source( self, Toolkit::Scrollable::Property::SCROLL_POSITION_MIN ) );
2704 constraint.AddSource( Source( self, Toolkit::Scrollable::Property::SCROLL_POSITION_MAX ) );
2705 constraint.AddSource( Source( self, Toolkit::ScrollView::Property::WRAP ) );
2706 constraint.SetRemoveAction(Constraint::Discard);
2707 ApplyConstraintToBoundActors(constraint);
2710 } // namespace Internal
2712 } // namespace Toolkit