-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+// CLASS HEADER
#include <dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h>
+// EXTERNAL INCLUDES
+#include <dali/public-api/animation/animation.h>
+#include <dali/public-api/animation/constraint.h>
+#include <dali/public-api/animation/time-period.h>
+
+// INTERNAL INCLUDES
+#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.
+};
+
ItemLayout::ItemLayout()
-: mOrientation(ControlOrientation::Up)
+: mImpl( new Impl )
{
+ mImpl->mOrientation = ControlOrientation::Up;
}
ItemLayout::~ItemLayout()
{
+ delete mImpl;
}
void ItemLayout::SetOrientation(ControlOrientation::Type orientation)
{
- mOrientation = orientation;
+ mImpl->mOrientation = orientation;
}
ControlOrientation::Type ItemLayout::GetOrientation() const
{
- return mOrientation;
+ return mImpl->mOrientation;
}
-float ItemLayout::GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize)
+void ItemLayout::GetItemSize( unsigned int itemId, const Vector3& layoutSize, Vector3& itemSize ) const
{
- ItemLayout::Vector3Function positionConstraint;
- Vector3 itemPosition = Vector3::ZERO;
- if (GetPositionConstraint(itemID, positionConstraint))
+ // If item-size has not been set then get the default size
+ if ( mImpl->mItemSize == Vector3::ZERO )
{
- itemPosition = positionConstraint(Vector3::ZERO, currentLayoutPosition + itemID, 0.0f, layoutSize);
+ GetDefaultItemSize( itemId, layoutSize, itemSize );
}
+ else
+ {
+ itemSize = mImpl->mItemSize;
+ }
+}
+
+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 itemSize;
GetItemSize(itemID, layoutSize, itemSize);
Vector3 onScreenArea = (layoutSize - itemSize) * 0.5f;
return currentLayoutPosition;
}
-void ItemLayout::GetXAxisScrollHint(Vector2& scrollHint) const
-{
- scrollHint = Vector2::ZERO;
- Radian scrollAngle(GetScrollDirection());
- Vector2 scrollDirection(sinf(scrollAngle), cosf(scrollAngle));
- switch(mOrientation)
- {
- case ControlOrientation::Up:
- {
- if(fabsf(scrollDirection.y) < Math::MACHINE_EPSILON_1)
- {
- // we probably want x scrolling
- if(scrollDirection.x > 0.0f)
- {
- // normal positive scrolling
- scrollHint = Vector2::XAXIS;
- }
- else
- {
- scrollHint = -Vector2::XAXIS;
- }
- }
- break;
- }
- case ControlOrientation::Down:
- {
- if(fabsf(scrollDirection.y) < Math::MACHINE_EPSILON_1)
- {
- // we probably want x scrolling
- if(scrollDirection.x > 0.0f)
- {
- // normal positive scrolling
- scrollHint = -Vector2::XAXIS;
- }
- else
- {
- scrollHint = Vector2::XAXIS;
- }
- }
- break;
- }
- case ControlOrientation::Left:
- {
- // we probably want x scrolling
- if(scrollDirection.x > 0.0f)
- {
- // normal positive scrolling
- scrollHint = Vector2::XAXIS;
- }
- else
- {
- scrollHint = -Vector2::XAXIS;
- }
- break;
- }
- case ControlOrientation::Right:
- {
- // we probably want x scrolling
- if(scrollDirection.x > 0.0f)
- {
- // normal positive scrolling
- scrollHint = -Vector2::XAXIS;
- }
- else
- {
- scrollHint = Vector2::XAXIS;
- }
- break;
- }
- }
-}
-
-void ItemLayout::GetYAxisScrollHint(Vector2& scrollHint) const
-{
- scrollHint = Vector2::ZERO;
- Radian scrollAngle(GetScrollDirection());
- Vector2 scrollDirection(sinf(scrollAngle), cosf(scrollAngle));
- switch(mOrientation)
- {
- case ControlOrientation::Up:
- {
- // we probably want x scrolling
- if(scrollDirection.y > 0.0f)
- {
- // normal positive scrolling
- scrollHint = Vector2::YAXIS;
- }
- else
- {
- scrollHint = -Vector2::YAXIS;
- }
- break;
- }
- case ControlOrientation::Down:
- {
- // we probably want x scrolling
- if(scrollDirection.y > 0.0f)
- {
- // normal positive scrolling
- scrollHint = -Vector2::YAXIS;
- }
- else
- {
- scrollHint = Vector2::YAXIS;
- }
- break;
- }
- case ControlOrientation::Left:
- {
- if(fabsf(scrollDirection.x) < Math::MACHINE_EPSILON_1)
- {
- // we probably want x scrolling
- if(scrollDirection.y > 0.0f)
- {
- // normal positive scrolling
- scrollHint = -Vector2::YAXIS;
- }
- else
- {
- scrollHint = Vector2::YAXIS;
- }
- }
- break;
- }
- case ControlOrientation::Right:
- {
- if(fabsf(scrollDirection.x) < Math::MACHINE_EPSILON_1)
- {
- // we probably want x scrolling
- if(scrollDirection.y > 0.0f)
- {
- // normal positive scrolling
- scrollHint = Vector2::YAXIS;
- }
- else
- {
- scrollHint = -Vector2::YAXIS;
- }
- }
- break;
- }
- }
-}
-
-int ItemLayout::GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
+int ItemLayout::GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
{
switch( direction )
{
- case Control::Left:
- case Control::Up:
+ case Control::KeyboardFocus::LEFT:
+ case Control::KeyboardFocus::UP:
{
itemID--;
if( itemID < 0 )
}
break;
}
- case Control::Right:
- case Control::Down:
+ case Control::KeyboardFocus::RIGHT:
+ case Control::KeyboardFocus::DOWN:
{
itemID++;
if( itemID >= maxItems )
}
break;
}
+ default:
+ {
+ break;
+ }
}
return itemID;
}
+float ItemLayout::GetFlickSpeedFactor() const
+{
+ // By default, the speed factor while dragging and swiping is the same.
+ return GetScrollSpeedFactor();
+}
+
} // namespace Toolkit
} // namespace Dali