2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h>
25 ItemLayout::ItemLayout()
26 : mOrientation(ControlOrientation::Up)
30 ItemLayout::~ItemLayout()
34 void ItemLayout::SetOrientation(ControlOrientation::Type orientation)
36 mOrientation = orientation;
39 ControlOrientation::Type ItemLayout::GetOrientation() const
44 float ItemLayout::GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize)
46 ItemLayout::Vector3Function positionConstraint;
47 Vector3 itemPosition = Vector3::ZERO;
48 if (GetPositionConstraint(itemID, positionConstraint))
50 itemPosition = positionConstraint(Vector3::ZERO, currentLayoutPosition + itemID, 0.0f, layoutSize);
53 GetItemSize(itemID, layoutSize, itemSize);
54 Vector3 onScreenArea = (layoutSize - itemSize) * 0.5f;
55 if (itemPosition.x < -onScreenArea.x
56 || itemPosition.x > onScreenArea.x
57 || itemPosition.y < -onScreenArea.y
58 || itemPosition.y > onScreenArea.y)
60 // item not within viewable area
61 // safest thing to do here since we have no idea how the implementation will work is to return the scroll to position
62 return GetItemScrollToPosition(itemID);
64 return currentLayoutPosition;
67 void ItemLayout::GetXAxisScrollHint(Vector2& scrollHint) const
69 scrollHint = Vector2::ZERO;
70 Radian scrollAngle(GetScrollDirection());
71 Vector2 scrollDirection(sinf(scrollAngle), cosf(scrollAngle));
74 case ControlOrientation::Up:
76 if(fabsf(scrollDirection.y) < Math::MACHINE_EPSILON_1)
78 // we probably want x scrolling
79 if(scrollDirection.x > 0.0f)
81 // normal positive scrolling
82 scrollHint = Vector2::XAXIS;
86 scrollHint = -Vector2::XAXIS;
91 case ControlOrientation::Down:
93 if(fabsf(scrollDirection.y) < Math::MACHINE_EPSILON_1)
95 // we probably want x scrolling
96 if(scrollDirection.x > 0.0f)
98 // normal positive scrolling
99 scrollHint = -Vector2::XAXIS;
103 scrollHint = Vector2::XAXIS;
108 case ControlOrientation::Left:
110 // we probably want x scrolling
111 if(scrollDirection.x > 0.0f)
113 // normal positive scrolling
114 scrollHint = Vector2::XAXIS;
118 scrollHint = -Vector2::XAXIS;
122 case ControlOrientation::Right:
124 // we probably want x scrolling
125 if(scrollDirection.x > 0.0f)
127 // normal positive scrolling
128 scrollHint = -Vector2::XAXIS;
132 scrollHint = Vector2::XAXIS;
139 void ItemLayout::GetYAxisScrollHint(Vector2& scrollHint) const
141 scrollHint = Vector2::ZERO;
142 Radian scrollAngle(GetScrollDirection());
143 Vector2 scrollDirection(sinf(scrollAngle), cosf(scrollAngle));
146 case ControlOrientation::Up:
148 // we probably want x scrolling
149 if(scrollDirection.y > 0.0f)
151 // normal positive scrolling
152 scrollHint = Vector2::YAXIS;
156 scrollHint = -Vector2::YAXIS;
160 case ControlOrientation::Down:
162 // we probably want x scrolling
163 if(scrollDirection.y > 0.0f)
165 // normal positive scrolling
166 scrollHint = -Vector2::YAXIS;
170 scrollHint = Vector2::YAXIS;
174 case ControlOrientation::Left:
176 if(fabsf(scrollDirection.x) < Math::MACHINE_EPSILON_1)
178 // we probably want x scrolling
179 if(scrollDirection.y > 0.0f)
181 // normal positive scrolling
182 scrollHint = -Vector2::YAXIS;
186 scrollHint = Vector2::YAXIS;
191 case ControlOrientation::Right:
193 if(fabsf(scrollDirection.x) < Math::MACHINE_EPSILON_1)
195 // we probably want x scrolling
196 if(scrollDirection.y > 0.0f)
198 // normal positive scrolling
199 scrollHint = Vector2::YAXIS;
203 scrollHint = -Vector2::YAXIS;
211 int ItemLayout::GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
221 itemID = loopEnabled ? maxItems - 1 : 0;
229 if( itemID >= maxItems )
231 itemID = loopEnabled ? 0 : maxItems - 1;
239 } // namespace Toolkit