Fixed DGEUF-1841. 55/243755/1
authorGyörgy Straub <g.straub@partner.samsung.com>
Wed, 9 Sep 2020 14:49:51 +0000 (15:49 +0100)
committerGyörgy Straub <g.straub@partner.samsung.com>
Wed, 9 Sep 2020 14:49:51 +0000 (15:49 +0100)
Since the text labels are supposed to be aligned to a grid, the
new target position is calculated based on this instead of getting
the position of the supposedly related text label, which might be
midway through an animation at the time.

Change-Id: Id83e89c13f2e03325966ab890aa5ca00e94fa100
Signed-off-by: György Straub <g.straub@partner.samsung.com>
examples/drag-and-drop/drag-and-drop-example.cpp

index 22e733f..b9e7f08 100644 (file)
@@ -44,6 +44,8 @@ const float TEXT_LABEL_WIDTH = 250.0f;
 const float TEXT_LABEL_HEIGHT = 70.0f;
 const unsigned int TEXT_LABEL_NUM = sizeof(TEXT_LABEL_COLOR) / sizeof(TEXT_LABEL_COLOR[0]);
 
+const float DROP_ANIMATION_DURATION_S = 0.5f;
+
 #if defined(DEBUG_ENABLED)
   Debug::Filter* gDragAndDropFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_DRAG_AND_DROP_EXAMPLE");
 #endif
@@ -183,14 +185,14 @@ public:
       }
     }
 
-    Animation mAnimation = Animation::New(0.5f);
+    Animation mAnimation = Animation::New(DROP_ANIMATION_DURATION_S);
 
     if(droppedIndex > mDragIndex)
     {
       for(int i = mDragIndex + 1; i <= droppedIndex; i++)
       {
-        float y = mTextLabel[mOrder[i]].GetCurrentProperty< Vector3 >( Actor::Property::POSITION ).y;
-        mAnimation.AnimateTo(Property(mTextLabel[mOrder[i]], Actor::Property::POSITION), Vector3(TEXT_LABEL_POSITION_X, y - TEXT_LABEL_HEIGHT, 0.0f), AlphaFunction::EASE_OUT);
+        mAnimation.AnimateTo(Property(mTextLabel[mOrder[i]], Actor::Property::POSITION),
+         Vector3(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * (i - 1), 0.0f), AlphaFunction::EASE_OUT);
         mAnimation.Play();
       }
 
@@ -204,11 +206,10 @@ public:
     }
     else if(droppedIndex < mDragIndex)
     {
-
       for(int i = mDragIndex - 1; i >= droppedIndex; i--)
       {
-        float y = mTextLabel[mOrder[i]].GetCurrentProperty< Vector3 >( Actor::Property::POSITION ).y;
-        mAnimation.AnimateTo(Property(mTextLabel[mOrder[i]], Actor::Property::POSITION), Vector3(TEXT_LABEL_POSITION_X, y + TEXT_LABEL_HEIGHT, 0.0f), AlphaFunction::EASE_OUT);
+        mAnimation.AnimateTo(Property(mTextLabel[mOrder[i]], Actor::Property::POSITION),
+          Vector3(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * (i + 1), 0.0f), AlphaFunction::EASE_OUT);
         mAnimation.Play();
       }
 
@@ -219,23 +220,21 @@ public:
       }
 
       mOrder[droppedIndex] = tmpId;
-
     }
 
-
     Vector2 pos = detector.GetCurrentScreenPosition();
     Vector2 localPos;
     control.GetParent().ScreenToLocal(localPos.x, localPos.y, pos.x, pos.y);
 
     KeyFrames k0 = KeyFrames::New();
     k0.Add(0.0f, Vector3(localPos.x - mDragLocalPos.x, localPos.y - mDragLocalPos.y, 0.0f));
-    k0.Add(1.0f, Vector3(control.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ).x, control.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ).y, 0.0f));
+    k0.Add(1.0f, Vector3(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * droppedIndex, 0.0f));
 
     KeyFrames k1 = KeyFrames::New();
     k1.Add(0.0f, 0.1f);
     k1.Add(1.0f, 1.0f);
 
-    Animation dropAnimation = Animation::New(0.5f);
+    Animation dropAnimation = Animation::New(DROP_ANIMATION_DURATION_S);
     dropAnimation.AnimateBetween(Property(mTextLabel[mDragRealIndex], Actor::Property::POSITION), k0, AlphaFunction::EASE_OUT);
     dropAnimation.AnimateBetween(Property(mTextLabel[mDragRealIndex], Actor::Property::OPACITY), k1, AlphaFunction::EASE_OUT);
     dropAnimation.Play();