Add support for ItemView layout customisation through properties.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / item-view / depth-layout.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 2fa572d..3b53bac
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-view.h>
+#include <dali-toolkit/devel-api/controls/scrollable/item-view/default-item-layout-property.h>
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -390,7 +391,7 @@ float DepthLayout::GetClosestAnchorPosition(float layoutPosition) const
 
 float DepthLayout::GetItemScrollToPosition(unsigned int itemId) const
 {
-  float rowIndex = static_cast<float>(itemId / mImpl->mNumberOfColumns);
+  float rowIndex = static_cast< float >( itemId ) / mImpl->mNumberOfColumns;
   return -rowIndex * static_cast<float>(mImpl->mNumberOfColumns);
 }
 
@@ -418,14 +419,6 @@ void DepthLayout::GetDefaultItemSize( unsigned int itemId, const Vector3& layout
   itemSize.width = itemSize.height = itemSize.depth = ( IsVertical( GetOrientation() ) ? layoutSize.width : layoutSize.height ) / static_cast<float>( mImpl->mNumberOfColumns + 1 );
 }
 
-void DepthLayout::GetResizeAnimation(Animation& animation, Actor actor, Vector3 size, float durationSeconds) const
-{
-  if(animation)
-  {
-    animation.AnimateTo( Property( actor, Actor::Property::SIZE ), size );
-  }
-}
-
 Degree DepthLayout::GetScrollDirection() const
 {
   Degree scrollDirection(0.0f);
@@ -453,6 +446,11 @@ Degree DepthLayout::GetScrollDirection() const
 
 void DepthLayout::ApplyConstraints( Actor& actor, const int itemId, const Vector3& layoutSize, const Actor& itemViewActor )
 {
+
+  if(HasLayoutChanged())
+  {
+    SetDepthLayoutProperties(GetLayoutProperties());
+  }
   Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast( itemViewActor );
   if( itemView )
   {
@@ -507,6 +505,63 @@ void DepthLayout::ApplyConstraints( Actor& actor, const int itemId, const Vector
   }
 }
 
+void DepthLayout::SetDepthLayoutProperties(const Property::Map& properties)
+{
+  // Set any properties specified for DepthLayout.
+  for( unsigned int idx = 0, mapCount = properties.Count(); idx < mapCount; ++idx )
+  {
+    KeyValuePair propertyPair = properties.GetKeyValue( idx );
+    switch(DefaultItemLayoutProperty::Property(propertyPair.first.indexKey))
+    {
+      case DefaultItemLayoutProperty::DEPTH_COLUMN_NUMBER:
+      {
+        SetNumberOfColumns(propertyPair.second.Get<int>());
+        break;
+      }
+      case DefaultItemLayoutProperty::DEPTH_ROW_NUMBER:
+      {
+        SetNumberOfRows(propertyPair.second.Get<int>());
+        break;
+      }
+      case DefaultItemLayoutProperty::DEPTH_ROW_SPACING:
+      {
+        SetRowSpacing(propertyPair.second.Get<float>());
+        break;
+      }
+      case DefaultItemLayoutProperty::DEPTH_MAXIMUM_SWIPE_SPEED:
+      {
+        SetMaximumSwipeSpeed(propertyPair.second.Get<float>());
+        break;
+      }
+      case DefaultItemLayoutProperty::DEPTH_SCROLL_SPEED_FACTOR:
+      {
+        SetScrollSpeedFactor(propertyPair.second.Get<float>());
+        break;
+      }
+      case DefaultItemLayoutProperty::DEPTH_TILT_ANGLE:
+      {
+        SetTiltAngle(Degree(Radian(propertyPair.second.Get<float>())));
+        break;
+      }
+      case DefaultItemLayoutProperty::DEPTH_ITEM_TILT_ANGLE:
+      {
+        SetItemTiltAngle(Degree(Radian(propertyPair.second.Get<float>())));
+        break;
+      }
+      case DefaultItemLayoutProperty::DEPTH_ITEM_FLICK_ANIMATION_DURATION:
+      {
+        SetItemFlickAnimationDuration(propertyPair.second.Get<float>());
+        break;
+      }
+      default:
+      {
+        break;
+      }
+    }
+  }
+  ResetLayoutChangedFlag();
+}
+
 Vector3 DepthLayout::GetItemPosition( int itemID, float currentLayoutPosition, const Vector3& layoutSize ) const
 {
   Vector3 itemPosition = Vector3::ZERO;
@@ -607,6 +662,10 @@ int DepthLayout::GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Con
       }
       break;
     }
+    default:
+    {
+      break;
+    }
   }
   return itemID;
 }