/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
#include <dali/public-api/animation/time-period.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/scrollable/item-view/default-item-layout-property.h>
#include <dali-toolkit/public-api/controls/scrollable/item-view/item-view.h>
namespace Dali
{
-
namespace Toolkit
{
-
struct ItemLayout::Impl
{
- Vector3 mItemSize; ///< The size of an item in the layout
- ControlOrientation::Type mOrientation; ///< the orientation of the layout.
+ Vector3 mItemSize; ///< The size of an item in the layout
+ ControlOrientation::Type mOrientation; ///< the orientation of the layout.
+ Property::Map mProperties;
};
ItemLayout::ItemLayout()
-: mImpl( new Impl )
+: mImpl(new Impl)
{
mImpl->mOrientation = ControlOrientation::Up;
}
return mImpl->mOrientation;
}
-void ItemLayout::GetItemSize( unsigned int itemId, const Vector3& layoutSize, Vector3& itemSize ) const
+void ItemLayout::GetItemSize(unsigned int itemId, const Vector3& layoutSize, Vector3& itemSize) const
{
// If item-size has not been set then get the default size
- if ( mImpl->mItemSize == Vector3::ZERO )
+ if(mImpl->mItemSize == Vector3::ZERO)
{
- GetDefaultItemSize( itemId, layoutSize, itemSize );
+ GetDefaultItemSize(itemId, layoutSize, itemSize);
}
else
{
}
}
-void ItemLayout::SetItemSize( const Vector3& itemSize )
+void ItemLayout::SetItemSize(const Vector3& itemSize)
{
mImpl->mItemSize = itemSize;
}
float ItemLayout::GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize)
{
- Vector3 itemPosition = GetItemPosition( itemID, currentLayoutPosition, layoutSize );
+ Vector3 itemPosition = GetItemPosition(itemID, currentLayoutPosition, layoutSize);
Vector3 itemSize;
GetItemSize(itemID, layoutSize, itemSize);
Vector3 onScreenArea = (layoutSize - itemSize) * 0.5f;
- if (itemPosition.x < -onScreenArea.x
- || itemPosition.x > onScreenArea.x
- || itemPosition.y < -onScreenArea.y
- || itemPosition.y > onScreenArea.y)
+ if(itemPosition.x < -onScreenArea.x || itemPosition.x > onScreenArea.x || itemPosition.y < -onScreenArea.y || itemPosition.y > onScreenArea.y)
{
// item not within viewable area
// safest thing to do here since we have no idea how the implementation will work is to return the scroll to position
int ItemLayout::GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
{
- switch( direction )
+ switch(direction)
{
case Control::KeyboardFocus::LEFT:
case Control::KeyboardFocus::UP:
{
itemID--;
- if( itemID < 0 )
+ if(itemID < 0)
{
itemID = loopEnabled ? maxItems - 1 : 0;
}
case Control::KeyboardFocus::DOWN:
{
itemID++;
- if( itemID >= maxItems )
+ if(itemID >= maxItems)
{
itemID = loopEnabled ? 0 : maxItems - 1;
}
break;
}
+ default:
+ {
+ break;
+ }
}
return itemID;
}
return GetScrollSpeedFactor();
}
+void ItemLayout::SetLayoutProperties(const Property::Map& properties)
+{
+ for(unsigned int idx = 0, mapCount = properties.Count(); idx < mapCount; ++idx)
+ {
+ KeyValuePair propertyPair(properties.GetKeyValue(idx));
+
+ if(propertyPair.first == DefaultItemLayoutProperty::ITEM_SIZE)
+ {
+ SetItemSize(propertyPair.second.Get<Vector3>());
+ }
+ else if(propertyPair.first == DefaultItemLayoutProperty::ORIENTATION)
+ {
+ //Up, Left, Down, Right
+ int orientationType = propertyPair.second.Get<int>();
+ if(orientationType <= ControlOrientation::Right && orientationType >= ControlOrientation::Up)
+ {
+ SetOrientation(ControlOrientation::Type(orientationType));
+ }
+ }
+ }
+ mImpl->mProperties = properties;
+}
+
+Property::Map ItemLayout::GetLayoutProperties()
+{
+ return mImpl->mProperties;
+}
+
} // namespace Toolkit
} // namespace Dali