Fix for ItemView OVERSHOOT_SIZE 32/111132/5
authorFerran Sole <ferran.sole@samsung.com>
Thu, 19 Jan 2017 11:58:46 +0000 (11:58 +0000)
committerFerran Sole <ferran.sole@samsung.com>
Fri, 20 Jan 2017 10:56:09 +0000 (10:56 +0000)
Setting overshoot size after overshoot was enabled was not working

Change-Id: Ibb7cc6268f85aa68aa5476b8a99222abab6f6525

automated-tests/src/dali-toolkit/utc-Dali-ItemView.cpp
automated-tests/src/dali-toolkit/utc-Dali-ScrollView.cpp
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/scroll-view/scroll-view-impl.cpp
dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h
dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp
dali-toolkit/internal/controls/scrollable/scrollable-impl.h

index 3e3e303..040fb1c 100755 (executable)
@@ -1011,6 +1011,12 @@ int UtcDaliItemViewSetGetProperty(void)
   view.SetProperty( Scrollable::Property::OVERSHOOT_ENABLED, false );
   DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_ENABLED).Get<bool>(), false, TEST_LOCATION );
 
+  // Test "overshootSize" property
+  DALI_TEST_CHECK( view.GetPropertyIndex("overshootSize") == Scrollable::Property::OVERSHOOT_SIZE  );
+  Vector2 overshootSize = Vector2(100.0f,100.0f);
+  view.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, overshootSize );
+  DALI_TEST_EQUALS( view.GetProperty(Scrollable::Property::OVERSHOOT_SIZE).Get<Vector2>(), overshootSize, TEST_LOCATION );
+
   // Animatable properties
 
   // Test "layoutPosition" property
index 883aacc..fdd32b5 100644 (file)
@@ -1198,6 +1198,11 @@ int UtcDaliToolkitScrollViewOvershoot(void)
   // Set up a scrollView...
   ScrollView scrollView = ScrollView::New();
   scrollView.SetOvershootEnabled(true);
+
+  Vector2 overshootSize = Vector2(100.0f,100.0f);
+  scrollView.SetProperty( Scrollable::Property::OVERSHOOT_SIZE, overshootSize );
+  DALI_TEST_EQUALS( scrollView.GetProperty(Scrollable::Property::OVERSHOOT_SIZE).Get<Vector2>(), overshootSize, TEST_LOCATION );
+
   Stage::GetCurrent().Add( scrollView );
   Vector2 stageSize = Stage::GetCurrent().GetSize();
   scrollView.SetSize(stageSize);
index 1724f83..8b84088 100755 (executable)
@@ -69,6 +69,8 @@ const float OVERSHOOT_BOUNCE_ACTOR_RESIZE_THRESHOLD = 180.0f;
 const Vector4 OVERSHOOT_OVERLAY_NINE_PATCH_BORDER(0.0f, 0.0f, 1.0f, 12.0f);
 const float DEFAULT_KEYBOARD_FOCUS_SCROLL_DURATION = 0.2f;
 
+const unsigned int OVERSHOOT_SIZE_CONSTRAINT_TAG(42);
+
 /**
  * Local helper to convert pan distance (in actor coordinates) to the layout-specific scrolling direction
  */
@@ -291,6 +293,21 @@ bool FindById( const ItemContainer& items, ItemId id )
   return false;
 }
 
+/**
+  * Helper to apply size constraint to mOvershootOverlay
+  * @param[in] overshootOverlay The overshootOverlay actor
+  * @param[in] The required height
+  */
+void ApplyOvershootSizeConstraint( Actor overshootOverlay, float height )
+{
+  Constraint constraint = Constraint::New<Vector3>( overshootOverlay, Actor::Property::SIZE, OvershootOverlaySizeConstraint( height ) );
+  constraint.AddSource( ParentSource( Dali::Toolkit::ItemView::Property::SCROLL_DIRECTION ) );
+  constraint.AddSource( ParentSource( Dali::Toolkit::ItemView::Property::LAYOUT_ORIENTATION ) );
+  constraint.AddSource( ParentSource( Dali::Actor::Property::SIZE ) );
+  constraint.SetTag( OVERSHOOT_SIZE_CONSTRAINT_TAG );
+  constraint.Apply();
+}
+
 } // unnamed namespace
 
 Dali::Toolkit::ItemView ItemView::New(ItemFactory& factory)
@@ -1519,6 +1536,18 @@ void ItemView::ScrollTo(const Vector2& position, float duration)
   mRefreshEnabled = true;
 }
 
+void ItemView::SetOvershootSize( const Vector2& size )
+{
+  mOvershootSize = size;
+
+  if( mOvershootOverlay )
+  {
+    // Remove old & add new size constraint
+    mOvershootOverlay.RemoveConstraints( OVERSHOOT_SIZE_CONSTRAINT_TAG );
+    ApplyOvershootSizeConstraint( mOvershootOverlay, mOvershootSize.height );
+  }
+}
+
 void ItemView::SetOvershootEffectColor( const Vector4& color )
 {
   mOvershootEffectColor = color;
@@ -1543,15 +1572,9 @@ void ItemView::EnableScrollOvershoot( bool enable )
       mOvershootOverlay.SetDrawMode( DrawMode::OVERLAY_2D );
       self.Add(mOvershootOverlay);
 
-      Constraint constraint = Constraint::New<Vector3>( mOvershootOverlay, Actor::Property::SIZE, OvershootOverlaySizeConstraint(mOvershootSize.height) );
-      constraint.AddSource( ParentSource( Toolkit::ItemView::Property::SCROLL_DIRECTION ) );
-      constraint.AddSource( ParentSource( Toolkit::ItemView::Property::LAYOUT_ORIENTATION ) );
-      constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
-      constraint.Apply();
-
-      mOvershootOverlay.SetSize(mOvershootSize.width, mOvershootSize.height);
+      ApplyOvershootSizeConstraint( mOvershootOverlay, mOvershootSize.height );
 
-      constraint = Constraint::New<Quaternion>( mOvershootOverlay, Actor::Property::ORIENTATION, OvershootOverlayRotationConstraint );
+      Constraint constraint = Constraint::New<Quaternion>( mOvershootOverlay, Actor::Property::ORIENTATION, OvershootOverlayRotationConstraint );
       constraint.AddSource( ParentSource( Toolkit::ItemView::Property::SCROLL_DIRECTION ) );
       constraint.AddSource( ParentSource( Toolkit::ItemView::Property::LAYOUT_ORIENTATION ) );
       constraint.AddSource( ParentSource( Toolkit::ItemView::Property::OVERSHOOT ) );
index f49ee81..d0a2bf1 100755 (executable)
@@ -239,6 +239,11 @@ public:
   void ScrollTo(const Vector2& position, float duration);
 
   /**
+   * @copydoc Toolkit::Internal::Scrollable::SetOvershootSize
+   */
+  void SetOvershootSize( const Vector2& size );
+
+  /**
    * @copydoc Toolkit::Internal::Scrollable::SetOvershootEffectColor
    */
   void SetOvershootEffectColor( const Vector4& color );
index 0da1660..3330f13 100644 (file)
@@ -1781,6 +1781,15 @@ void ScrollView::RemoveOverlay(Actor actor)
   mInternalActor.Remove( actor );
 }
 
+void ScrollView::SetOvershootSize( const Vector2& size )
+{
+  mOvershootSize = size;
+  if( IsOvershootEnabled() && mOvershootIndicator )
+  {
+    mOvershootIndicator->AttachToScrollable(*this);
+  }
+}
+
 void ScrollView::SetOvershootEffectColor( const Vector4& color )
 {
   mOvershootEffectColor = color;
index b288720..9a16624 100644 (file)
@@ -494,6 +494,11 @@ public:
   void RemoveOverlay(Actor actor);
 
   /**
+   * @copydoc Toolkit::Internal::Scrollable::SetOvershootSize
+   */
+  void SetOvershootSize( const Vector2& size );
+
+  /**
    * @copydoc Toolkit::Internal::Scrollable::SetOvershootEffectColor
    */
   void SetOvershootEffectColor( const Vector4& color );
index 20da41c..31201ee 100644 (file)
@@ -204,12 +204,7 @@ void Scrollable::SetProperty( BaseObject* object, Property::Index index, const P
       }
       case Toolkit::Scrollable::Property::OVERSHOOT_SIZE:
       {
-        Vector2 input;
-        if( value.Get( input ) )
-        {
-          scrollableImpl.mOvershootSize = input;
-        }
-        scrollableImpl.EnableScrollOvershoot( scrollableImpl.IsOvershootEnabled() );
+        scrollableImpl.SetOvershootSize( value.Get<Vector2>() );
         break;
       }
       case Toolkit::Scrollable::Property::SCROLL_TO_ALPHA_FUNCTION:
index 660606c..bf6fa98 100644 (file)
@@ -112,6 +112,12 @@ public:
    */
   const Vector2& GetOvershootSize() const;
 
+  /**
+   * Set the size of the overshoot effect.
+   * @parm[in] size The size of the overshoot effect
+   */
+  virtual void SetOvershootSize( const Vector2& size ) = 0;
+
 private:
 
   /**