X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fpublic-api%2Fcontrols%2Fscrollable%2Fitem-view%2Fitem-layout.cpp;h=0dc2bb4788a14f45825c5726a3ec8179af185759;hp=177c1d8763c996c37e4ce5f74a54ca281bd67599;hb=a78bb823aebc305823855ac35b3413aaff7bc684;hpb=e2eda444afbe82e9591fe198eef339227f90a616 diff --git a/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.cpp b/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.cpp index 177c1d8..0dc2bb4 100644 --- a/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.cpp +++ b/dali-toolkit/public-api/controls/scrollable/item-view/item-layout.cpp @@ -1,54 +1,85 @@ -// -// 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 +// EXTERNAL INCLUDES +#include +#include +#include + +// INTERNAL INCLUDES +#include + 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; @@ -64,156 +95,12 @@ float ItemLayout::GetClosestOnScreenLayoutPosition(int itemID, float currentLayo 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 ) @@ -222,8 +109,8 @@ int ItemLayout::GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Cont } break; } - case Control::Right: - case Control::Down: + case Control::KeyboardFocus::RIGHT: + case Control::KeyboardFocus::DOWN: { itemID++; if( itemID >= maxItems ) @@ -236,6 +123,12 @@ int ItemLayout::GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Cont return itemID; } +float ItemLayout::GetFlickSpeedFactor() const +{ + // By default, the speed factor while dragging and swiping is the same. + return GetScrollSpeedFactor(); +} + } // namespace Toolkit } // namespace Dali