1 /* Copyright (c) 2020 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 using Tizen.NUI.BaseComponents;
18 using System.Collections.Generic;
19 using System.ComponentModel;
21 namespace Tizen.NUI.Components
24 /// [Draft] This class implements a linear box layout.
26 /// <since_tizen> 8 </since_tizen>
27 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class LinearRecycleLayoutManager : RecycleLayoutManager
31 private int firstVisibleItemIndex = -1;
32 private int lastVisibleItemIndex = -1;
34 private bool IsItemVisible(float scrollPosition, RecycleItem item)
37 View list = Container.GetParent() as View;
39 Vector2 visibleArea = new Vector2( Math.Abs(scrollPosition),
40 Math.Abs(scrollPosition) + (LayoutOrientation == Orientation.Horizontal?
41 list.Size.Width:list.Size.Height)
44 float firstCheckPoint = LayoutOrientation == Orientation.Horizontal? item.Position.X:item.Position.Y;
45 float secondCheckPoint = LayoutOrientation == Orientation.Horizontal?
46 firstCheckPoint + item.Size.Width:
47 firstCheckPoint + item.Size.Height;
49 // Tizen.Log.Error("NUI", "[1p] "+visibleArea.X+ " =< "+firstCheckPoint+" =< "+visibleArea.Y+" ==== \n");
50 // Tizen.Log.Error("NUI", "[2p] "+visibleArea.X+ " =< "+secondCheckPoint+" =< "+visibleArea.Y+" ==== \n");
52 result = (firstCheckPoint >= visibleArea.X && firstCheckPoint <= visibleArea.Y) || (secondCheckPoint >= visibleArea.X && secondCheckPoint <= visibleArea.Y);
58 /// This is called to find out where items are lain out according to current scroll position.
60 /// <param name="scrollPosition">Scroll position which is calculated by ScrollableBase</param>
61 /// <since_tizen> 8 </since_tizen>
62 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
63 public override void Layout(float scrollPosition)
65 firstVisibleItemIndex = -1;
66 lastVisibleItemIndex = -1;
68 RecycleItem previousItem = null;
70 for(int i = 0 ; i < Container.Children.Count ; i++)
72 RecycleItem item = Container.Children[i] as RecycleItem;
74 if(previousItem != null)
76 item.Position = LayoutOrientation == Orientation.Horizontal?
78 previousItem.Position.X + (previousItem.CurrentSize.Width != 0 ?
79 previousItem.CurrentSize.Width:
80 previousItem.Size.Width),
85 previousItem.Position.Y + (previousItem.CurrentSize.Height != 0 ?
86 previousItem.CurrentSize.Height:
87 previousItem.Size.Height)
91 bool isVisible = IsItemVisible(scrollPosition, item);
95 firstVisibleItemIndex = firstVisibleItemIndex == -1? i : firstVisibleItemIndex;
96 lastVisibleItemIndex = i;
101 // Tizen.Log.Error("NUI","["+item.DataIndex+"] "+item.Position.Y+" ==== \n");
106 StepSize = LayoutOrientation == Orientation.Horizontal?ItemSize.Width:ItemSize.Height;
111 /// This is called to find out how much container size can be.
113 /// <since_tizen> 8 </since_tizen>
114 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public override float CalculateLayoutOrientationSize()
118 return StepSize * DataCount;
122 /// This is called to find out which items should be recycled according to current scroll position.
124 /// <param name="scrollPosition">Scroll position which is calculated by ScrollableBase</param>
125 /// <returns>List of RecycleItems which should be recycled.</returns>
126 /// <since_tizen> 8 </since_tizen>
127 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
128 public override List<RecycleItem> Recycle(float scrollPosition)
130 List<RecycleItem> result = new List<RecycleItem>();
132 bool checkFront = (PrevScrollPosition - scrollPosition) > 0;
136 if(firstVisibleItemIndex > 3)
138 // Too many item is in front!!! move first item to back!!!!
139 RecycleItem target = Container.Children[0] as RecycleItem;
140 target.DataIndex = target.DataIndex + Container.Children.Count;
141 target.SiblingOrder = Container.Children.Count - 1;
148 if(lastVisibleItemIndex < Container.Children.Count - 3)
150 RecycleItem prevFirstItem = Container.Children[0] as RecycleItem;
152 RecycleItem target = Container.Children[Container.Children.Count - 1] as RecycleItem;
153 target.Position = new Position(
154 LayoutOrientation == Orientation.Horizontal ? (prevFirstItem.Position.X - target.Size.Width) : prevFirstItem.Position.X,
155 LayoutOrientation == Orientation.Horizontal ? prevFirstItem.Position.Y : (prevFirstItem.Position.Y - target.Size.Height)
157 target.DataIndex = target.DataIndex - Container.Children.Count;
158 target.SiblingOrder = 0;
164 PrevScrollPosition = scrollPosition;
170 /// Adjust scrolling position by own scrolling rules.
172 /// <param name="scrollPosition">Scroll position which is calculated by ScrollableBase</param>
173 /// <since_tizen> 8 </since_tizen>
174 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
175 public override float CalculateCandidateScrollPosition(float scrollPosition)
177 return scrollPosition;