ScrollView - Overshoot Fix
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-impl.cpp
index 2779369..9d465e4 100644 (file)
@@ -434,12 +434,17 @@ struct OvershootXConstraint
 
   float operator()(const float&    current,
       const PropertyInput& scrollPrePositionProperty,
 
   float operator()(const float&    current,
       const PropertyInput& scrollPrePositionProperty,
-      const PropertyInput& scrollPostPositionProperty)
+      const PropertyInput& scrollPostPositionProperty,
+      const PropertyInput& canScrollProperty)
   {
   {
-    const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
-    const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
-    float newOvershoot = scrollPrePosition.x - scrollPostPosition.x;
-    return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
+    if( canScrollProperty.GetBoolean() )
+    {
+      const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
+      const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
+      float newOvershoot = scrollPrePosition.x - scrollPostPosition.x;
+      return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
+    }
+    return 0.0f;
   }
 
   float mMaxOvershoot;
   }
 
   float mMaxOvershoot;
@@ -455,12 +460,17 @@ struct OvershootYConstraint
 
   float operator()(const float&    current,
       const PropertyInput& scrollPrePositionProperty,
 
   float operator()(const float&    current,
       const PropertyInput& scrollPrePositionProperty,
-      const PropertyInput& scrollPostPositionProperty)
+      const PropertyInput& scrollPostPositionProperty,
+      const PropertyInput& canScrollProperty)
   {
   {
-    const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
-    const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
-    float newOvershoot = scrollPrePosition.y - scrollPostPosition.y;
-    return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
+    if( canScrollProperty.GetBoolean() )
+    {
+      const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
+      const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
+      float newOvershoot = scrollPrePosition.y - scrollPostPosition.y;
+      return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
+    }
+    return 0.0f;
   }
 
   float mMaxOvershoot;
   }
 
   float mMaxOvershoot;
@@ -929,10 +939,10 @@ void ScrollView::UpdatePropertyDomain(const Vector3& size)
         scrollPositionChanged = true;
         mScrollPrePosition.x = Clamp(mScrollPrePosition.x, -(max.x - size.x), -min.x);
       }
         scrollPositionChanged = true;
         mScrollPrePosition.x = Clamp(mScrollPrePosition.x, -(max.x - size.x), -min.x);
       }
-      if((fabsf(max.x - min.x) - size.x) > Math::MACHINE_EPSILON_10000)
-      {
-        canScrollHorizontal = true;
-      }
+    }
+    if( (fabsf(rulerDomain.max - rulerDomain.min) - size.x) > Math::MACHINE_EPSILON_10000 )
+    {
+      canScrollHorizontal = true;
     }
   }
 
     }
   }
 
@@ -953,10 +963,10 @@ void ScrollView::UpdatePropertyDomain(const Vector3& size)
         scrollPositionChanged = true;
         mScrollPrePosition.y = Clamp(mScrollPrePosition.y, -(max.y - size.y), -min.y);
       }
         scrollPositionChanged = true;
         mScrollPrePosition.y = Clamp(mScrollPrePosition.y, -(max.y - size.y), -min.y);
       }
-      if((fabsf(max.y - min.y) - size.y) > Math::MACHINE_EPSILON_10000)
-      {
-        canScrollVertical = true;
-      }
+    }
+    if( (fabsf(rulerDomain.max - rulerDomain.min) - size.y) > Math::MACHINE_EPSILON_10000 )
+    {
+      canScrollVertical = true;
     }
   }
   // avoid setting properties if possible, otherwise this will cause an entire update as well as triggering constraints using each property we update
     }
   }
   // avoid setting properties if possible, otherwise this will cause an entire update as well as triggering constraints using each property we update
@@ -966,7 +976,7 @@ void ScrollView::UpdatePropertyDomain(const Vector3& size)
   }
   if( self.GetProperty<bool>(mPropertyCanScrollHorizontal) != canScrollHorizontal )
   {
   }
   if( self.GetProperty<bool>(mPropertyCanScrollHorizontal) != canScrollHorizontal )
   {
-    self.SetProperty(mPropertyCanScrollHorizontal, canScrollVertical);
+    self.SetProperty(mPropertyCanScrollHorizontal, canScrollHorizontal);
   }
   if( scrollPositionChanged )
   {
   }
   if( scrollPositionChanged )
   {
@@ -2271,15 +2281,17 @@ void ScrollView::SnapInternalXTo(float position)
   mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
 
   // if internal x not equal to inputed parameter, animate it
   mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
 
   // if internal x not equal to inputed parameter, animate it
-  float current = self.GetProperty<Vector3>(mPropertyPrePosition).x;
-  float duration = fabsf(position - current);
-  mInternalXAnimation = Animation::New(duration);
-  mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
-  mInternalXAnimation.AnimateTo(Property(self, mPropertyPrePosition, 0), position);
-  mInternalXAnimation.Play();
+  float duration = std::min(fabsf((position - mScrollPrePosition.x) / mMaxOvershoot.x) * mSnapOvershootDuration, mSnapOvershootDuration);
+  if( duration > Math::MACHINE_EPSILON_1 )
+  {
+    mInternalXAnimation = Animation::New(duration);
+    mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
+    mInternalXAnimation.AnimateTo(Property(self, mPropertyPrePosition, 0), position);
+    mInternalXAnimation.Play();
 
 
-  // add internal animation state flag
-  mScrollStateFlags |= SnappingInternalX;
+    // add internal animation state flag
+    mScrollStateFlags |= SnappingInternalX;
+  }
 }
 
 void ScrollView::SnapInternalYTo(float position)
 }
 
 void ScrollView::SnapInternalYTo(float position)
@@ -2292,15 +2304,17 @@ void ScrollView::SnapInternalYTo(float position)
   mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
 
   // if internal y not equal to inputed parameter, animate it
   mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
 
   // if internal y not equal to inputed parameter, animate it
-  float current = self.GetProperty<Vector3>(mPropertyPrePosition).y;
-  float duration = fabsf(position - current);
-  mInternalYAnimation = Animation::New(duration);
-  mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
-  mInternalYAnimation.AnimateTo(Property(self, mPropertyPrePosition, 1), position);
-  mInternalYAnimation.Play();
+  float duration = std::min(fabsf((position - mScrollPrePosition.y) / mMaxOvershoot.y) * mSnapOvershootDuration, mSnapOvershootDuration);
+  if( duration > Math::MACHINE_EPSILON_1 )
+  {
+    mInternalYAnimation = Animation::New(duration);
+    mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
+    mInternalYAnimation.AnimateTo(Property(self, mPropertyPrePosition, 1), position);
+    mInternalYAnimation.Play();
 
 
-  // add internal animation state flag
-  mScrollStateFlags |= SnappingInternalY;
+    // add internal animation state flag
+    mScrollStateFlags |= SnappingInternalY;
+  }
 }
 
 void ScrollView::GestureStarted()
 }
 
 void ScrollView::GestureStarted()
@@ -2477,14 +2491,6 @@ void ScrollView::FinishTransform()
     Self().SetProperty(mPropertyScrolling, false);
     Vector3 currentScrollPosition = GetCurrentScrollPosition();
     mScrollCompletedSignalV2.Emit( currentScrollPosition );
     Self().SetProperty(mPropertyScrolling, false);
     Vector3 currentScrollPosition = GetCurrentScrollPosition();
     mScrollCompletedSignalV2.Emit( currentScrollPosition );
-    if( fabs(mScrollPrePosition.x - mScrollTargetPosition.x) > Math::MACHINE_EPSILON_10 )
-    {
-      SnapInternalXTo(mScrollTargetPosition.x);
-    }
-    if( fabs(mScrollPrePosition.y - mScrollTargetPosition.y) > Math::MACHINE_EPSILON_10 )
-    {
-      SnapInternalYTo(mScrollTargetPosition.y);
-    }
   }
 }
 
   }
 }
 
@@ -2706,12 +2712,14 @@ void ScrollView::SetOvershootConstraintsEnabled(bool enabled)
     Constraint constraint = Constraint::New<float>( mPropertyOvershootX,
                                            LocalSource( mPropertyPrePosition ),
                                            LocalSource( mPropertyPosition ),
     Constraint constraint = Constraint::New<float>( mPropertyOvershootX,
                                            LocalSource( mPropertyPrePosition ),
                                            LocalSource( mPropertyPosition ),
+                                           LocalSource( mPropertyCanScrollHorizontal ),
                                            OvershootXConstraint(mMaxOvershoot.x) );
     mScrollMainInternalOvershootXConstraint = self.ApplyConstraint( constraint );
 
     constraint = Constraint::New<float>( mPropertyOvershootY,
                                            LocalSource( mPropertyPrePosition ),
                                            LocalSource( mPropertyPosition ),
                                            OvershootXConstraint(mMaxOvershoot.x) );
     mScrollMainInternalOvershootXConstraint = self.ApplyConstraint( constraint );
 
     constraint = Constraint::New<float>( mPropertyOvershootY,
                                            LocalSource( mPropertyPrePosition ),
                                            LocalSource( mPropertyPosition ),
+                                           LocalSource( mPropertyCanScrollVertical ),
                                            OvershootYConstraint(mMaxOvershoot.y) );
     mScrollMainInternalOvershootYConstraint = self.ApplyConstraint( constraint );
   }
                                            OvershootYConstraint(mMaxOvershoot.y) );
     mScrollMainInternalOvershootYConstraint = self.ApplyConstraint( constraint );
   }