Add ItemView stopScrolling action 51/68351/10
authorPaul Wisbey <p.wisbey@samsung.com>
Tue, 3 May 2016 18:15:17 +0000 (19:15 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Thu, 12 May 2016 10:22:41 +0000 (11:22 +0100)
+ Added a property for choosing one of the built-in alpha functions,
for scroll-to animations

Change-Id: I536672d27d6aec1ad06a3051f4b76cb63bad7b5c

dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp
dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h
dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp
dali-toolkit/internal/controls/scrollable/scrollable-impl.h
dali-toolkit/public-api/controls/scrollable/item-view/item-view.h
dali-toolkit/public-api/controls/scrollable/scrollable.h
docs/content/shared-javascript-and-cpp-documentation/item-view.md

index 9403c8a..ba2000b 100644 (file)
@@ -260,6 +260,8 @@ DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "scrollContentSize",
 
 DALI_SIGNAL_REGISTRATION(              Toolkit, ItemView, "layoutActivated",     LAYOUT_ACTIVATED_SIGNAL )
 
 
 DALI_SIGNAL_REGISTRATION(              Toolkit, ItemView, "layoutActivated",     LAYOUT_ACTIVATED_SIGNAL )
 
+DALI_ACTION_REGISTRATION(              Toolkit, ItemView, "stopScrolling",       ACTION_STOP_SCROLLING   )
+
 DALI_TYPE_REGISTRATION_END()
 
 bool FindById( const ItemContainer& items, ItemId id )
 DALI_TYPE_REGISTRATION_END()
 
 bool FindById( const ItemContainer& items, ItemId id )
@@ -1378,7 +1380,7 @@ void ItemView::ScrollToItem(unsigned int itemId, float durationSeconds)
   {
     RemoveAnimation(mScrollAnimation);
     mScrollAnimation = Animation::New(durationSeconds);
   {
     RemoveAnimation(mScrollAnimation);
     mScrollAnimation = Animation::New(durationSeconds);
-    mScrollAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::LAYOUT_POSITION), firstItemScrollPosition, AlphaFunction::EASE_OUT );
+    mScrollAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::LAYOUT_POSITION), firstItemScrollPosition, mScrollToAlphaFunction );
     mScrollAnimation.FinishedSignal().Connect(this, &ItemView::OnScrollFinished);
     mScrollAnimation.Play();
   }
     mScrollAnimation.FinishedSignal().Connect(this, &ItemView::OnScrollFinished);
     mScrollAnimation.Play();
   }
@@ -1492,7 +1494,7 @@ void ItemView::ScrollTo(const Vector2& position, float duration)
   {
     RemoveAnimation(mScrollAnimation);
     mScrollAnimation = Animation::New(duration);
   {
     RemoveAnimation(mScrollAnimation);
     mScrollAnimation = Animation::New(duration);
-    mScrollAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::LAYOUT_POSITION), firstItemScrollPosition, AlphaFunction::EASE_OUT );
+    mScrollAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::LAYOUT_POSITION), firstItemScrollPosition, mScrollToAlphaFunction );
     mScrollAnimation.FinishedSignal().Connect(this, &ItemView::OnScrollFinished);
     mScrollAnimation.Play();
   }
     mScrollAnimation.FinishedSignal().Connect(this, &ItemView::OnScrollFinished);
     mScrollAnimation.Play();
   }
@@ -1778,6 +1780,31 @@ Property::Value ItemView::GetProperty( BaseObject* object, Property::Index index
   return value;
 }
 
   return value;
 }
 
+bool ItemView::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
+{
+  Dali::BaseHandle handle( object );
+
+  Toolkit::ItemView itemView = Toolkit::ItemView::DownCast( handle );
+
+  DALI_ASSERT_ALWAYS( itemView );
+
+  if( 0 == strcmp( actionName.c_str(), ACTION_STOP_SCROLLING ) )
+  {
+    GetImpl( itemView ).DoStopScrolling();
+  }
+
+  return true;
+}
+
+void ItemView::DoStopScrolling()
+{
+  if( mScrollAnimation )
+  {
+    mScrollAnimation.Stop();
+    mScrollAnimation.Reset();
+  }
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
 } // namespace Internal
 
 } // namespace Toolkit
index 2b3a52f..3d31e1c 100644 (file)
@@ -326,6 +326,20 @@ public:
    */
   static Property::Value GetProperty( BaseObject* object, Property::Index index );
 
    */
   static Property::Value GetProperty( BaseObject* object, Property::Index index );
 
+  /**
+   * Performs actions as requested using the action name.
+   * @param[in] object The object on which to perform the action.
+   * @param[in] actionName The action to perform.
+   * @param[in] attributes The attributes with which to perfrom this action.
+   * @return true if action has been accepted by this control
+   */
+  static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
+
+  /**
+   * Helper for DoAction( ACTION_STOP_SCROLLING ).
+   */
+  void DoStopScrolling();
+
 private:
 
   /**
 private:
 
   /**
index 3a4ad99..70e5c11 100644 (file)
@@ -50,6 +50,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootEffectColor",      VE
 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootAnimationSpeed",   FLOAT,   OVERSHOOT_ANIMATION_SPEED )
 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootEnabled",          BOOLEAN, OVERSHOOT_ENABLED )
 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootSize",             VECTOR2, OVERSHOOT_SIZE )
 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootAnimationSpeed",   FLOAT,   OVERSHOOT_ANIMATION_SPEED )
 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootEnabled",          BOOLEAN, OVERSHOOT_ENABLED )
 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootSize",             VECTOR2, OVERSHOOT_SIZE )
+DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "scrollToAlphaFunction",     INTEGER, SCROLL_TO_ALPHA_FUNCTION )
 
 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Scrollable, "scrollRelativePosition",   VECTOR2, SCROLL_RELATIVE_POSITION)
 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Scrollable, "scrollPositionMin",        VECTOR2, SCROLL_POSITION_MIN)
 
 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Scrollable, "scrollRelativePosition",   VECTOR2, SCROLL_RELATIVE_POSITION)
 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Scrollable, "scrollPositionMin",        VECTOR2, SCROLL_POSITION_MIN)
@@ -84,6 +85,7 @@ Scrollable::Scrollable()
   mOvershootEffectColor(  DEFAULT_OVERSHOOT_COLOUR ),
   mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ),
   mOvershootSize( OVERSHOOT_DEFAULT_SIZE ),
   mOvershootEffectColor(  DEFAULT_OVERSHOOT_COLOUR ),
   mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ),
   mOvershootSize( OVERSHOOT_DEFAULT_SIZE ),
+  mScrollToAlphaFunction( AlphaFunction::EASE_OUT ),
   mOvershootEnabled(true)
 {
 }
   mOvershootEnabled(true)
 {
 }
@@ -93,6 +95,7 @@ Scrollable::Scrollable( ControlBehaviour behaviourFlags )
   mOvershootEffectColor(  DEFAULT_OVERSHOOT_COLOUR ),
   mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ),
   mOvershootSize( OVERSHOOT_DEFAULT_SIZE ),
   mOvershootEffectColor(  DEFAULT_OVERSHOOT_COLOUR ),
   mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ),
   mOvershootSize( OVERSHOOT_DEFAULT_SIZE ),
+  mScrollToAlphaFunction( AlphaFunction::EASE_OUT ),
   mOvershootEnabled(true)
 {
 }
   mOvershootEnabled(true)
 {
 }
@@ -209,6 +212,17 @@ void Scrollable::SetProperty( BaseObject* object, Property::Index index, const P
         scrollableImpl.EnableScrollOvershoot( scrollableImpl.IsOvershootEnabled() );
         break;
       }
         scrollableImpl.EnableScrollOvershoot( scrollableImpl.IsOvershootEnabled() );
         break;
       }
+      case Toolkit::Scrollable::Property::SCROLL_TO_ALPHA_FUNCTION:
+      {
+        int alphaFunction = value.Get<int>();
+
+        if( alphaFunction >= AlphaFunction::DEFAULT &&
+            alphaFunction <  AlphaFunction::COUNT )
+        {
+          scrollableImpl.mScrollToAlphaFunction = static_cast< AlphaFunction::BuiltinFunction >( alphaFunction );
+        }
+        break;
+      }
     }
   }
 }
     }
   }
 }
@@ -244,6 +258,11 @@ Property::Value Scrollable::GetProperty( BaseObject* object, Property::Index ind
         value = scrollableImpl.mOvershootSize;
         break;
       }
         value = scrollableImpl.mOvershootSize;
         break;
       }
+      case Toolkit::Scrollable::Property::SCROLL_TO_ALPHA_FUNCTION:
+      {
+        value = static_cast<int>( scrollableImpl.mScrollToAlphaFunction );
+        break;
+      }
     }
   }
 
     }
   }
 
index 97b3107..0d5d045 100644 (file)
@@ -18,6 +18,9 @@
  *
  */
 
  *
  */
 
+// EXTERNAL INCLUDES
+#include <dali/public-api/animation/alpha-function.h>
+
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
@@ -212,6 +215,8 @@ protected:
   float           mOvershootAnimationSpeed; ///<The speed of the overshoot animation (pixels per second)
   Vector2         mOvershootSize;           ///<The size of the overshoot effect
 
   float           mOvershootAnimationSpeed; ///<The speed of the overshoot animation (pixels per second)
   Vector2         mOvershootSize;           ///<The size of the overshoot effect
 
+  Dali::AlphaFunction::BuiltinFunction mScrollToAlphaFunction; ///< The ScrollTo() animations use this
+
   Toolkit::Scrollable::ScrollStartedSignalType mScrollStartedSignal;
   Toolkit::Scrollable::ScrollUpdatedSignalType mScrollUpdatedSignal;
   Toolkit::Scrollable::ScrollCompletedSignalType mScrollCompletedSignal;
   Toolkit::Scrollable::ScrollStartedSignalType mScrollStartedSignal;
   Toolkit::Scrollable::ScrollUpdatedSignalType mScrollUpdatedSignal;
   Toolkit::Scrollable::ScrollCompletedSignalType mScrollCompletedSignal;
index 78ed3b8..e1907c5 100644 (file)
@@ -56,6 +56,12 @@ typedef IntrusivePtr<ItemLayout> ItemLayoutPtr;
  * |---------------------------------|--------------------------------------------|
  * | layoutActivated                 | @ref LayoutActivatedSignal()               |
  * @SINCE_1_0.0
  * |---------------------------------|--------------------------------------------|
  * | layoutActivated                 | @ref LayoutActivatedSignal()               |
  * @SINCE_1_0.0
+ *
+ * Actions
+ * | %Action Name  | Attributes              | Description                                     |
+ * |---------------|-------------------------|-------------------------------------------------|
+ * | stopScrolling | Doesn't have attributes | Stops the scroll animation. See @ref DoAction() |
+ * @SINCE_1_1.33
  */
 
 class DALI_IMPORT_API ItemView : public Scrollable
  */
 
 class DALI_IMPORT_API ItemView : public Scrollable
index e8af489..0df8a58 100644 (file)
@@ -46,8 +46,8 @@ class Scrollable;
  * | %Signal Name     | Method                       |
  * |------------------|------------------------------|
  * | scrollStarted    | @ref ScrollStartedSignal()   |
  * | %Signal Name     | Method                       |
  * |------------------|------------------------------|
  * | scrollStarted    | @ref ScrollStartedSignal()   |
- * | scrollCompleted  | @ref ScrollUpdatedSignal()   |
- * | scrollUpdated    | @ref ScrollCompletedSignal() |
+ * | scrollCompleted  | @ref ScrollCompletedSignal() |
+ * | scrollUpdated    | @ref ScrollUpdatedSignal()   |
  * @SINCE_1_0.0
  */
 class DALI_IMPORT_API Scrollable : public Control
  * @SINCE_1_0.0
  */
 class DALI_IMPORT_API Scrollable : public Control
@@ -80,6 +80,7 @@ public:
       OVERSHOOT_ANIMATION_SPEED,                     ///< Property, name "overshootAnimationSpeed",   @see SetOvershootAnimationSpeed(), type float @SINCE_1_0.0
       OVERSHOOT_ENABLED,                             ///< Property, name "overshootEnabled",          @see SetOvershootEnabled(),        type bool,    @SINCE_1_1.18
       OVERSHOOT_SIZE,                                ///< Property, name "overshootSize",                                                type Vector2, @SINCE_1_1.31
       OVERSHOOT_ANIMATION_SPEED,                     ///< Property, name "overshootAnimationSpeed",   @see SetOvershootAnimationSpeed(), type float @SINCE_1_0.0
       OVERSHOOT_ENABLED,                             ///< Property, name "overshootEnabled",          @see SetOvershootEnabled(),        type bool,    @SINCE_1_1.18
       OVERSHOOT_SIZE,                                ///< Property, name "overshootSize",                                                type Vector2, @SINCE_1_1.31
+      SCROLL_TO_ALPHA_FUNCTION,                      ///< Property, name "scrollToAlphaFunction",                                        type int,     @SINCE_1_1.33
 
       // Animatable properties
       SCROLL_RELATIVE_POSITION = ANIMATABLE_PROPERTY_START_INDEX, ///< Property, name "scrollRelativePosition",   type Vector2 @SINCE_1_0.0
 
       // Animatable properties
       SCROLL_RELATIVE_POSITION = ANIMATABLE_PROPERTY_START_INDEX, ///< Property, name "scrollRelativePosition",   type Vector2 @SINCE_1_0.0
index 93c4816..0242d19 100644 (file)
@@ -69,4 +69,13 @@ itemView.ActivateLayout(
 Dali::Stage::GetCurrent().Add( itemView );
 ~~~
 
 Dali::Stage::GetCurrent().Add( itemView );
 ~~~
 
+## Actions
+The item-view provides an action to stop the scroll animation if desired.
+
+~~~{.cpp}
+Property::Map attributes;
+itemView.DoAction( "stopScrolling", attributes );
+~~~
+
+
 */
\ No newline at end of file
 */
\ No newline at end of file