2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
22 namespace Tizen.NUI.Components
25 /// Pagination shows the number of pages available and the currently active page.
27 /// <since_tizen> 6 </since_tizen>
28 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public class Pagination: Control
32 private PaginationAttributes paginationAttributes;
34 private VisualView container;
36 private List<ImageVisual> indicatorList = new List<ImageVisual>();
37 private ImageVisual selectIndicator;
39 private int indicatorCount = 0;
40 private int selectedIndex = -1;
43 /// Creates a new instance of a Pagination.
45 /// <since_tizen> 6 </since_tizen>
46 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
47 [EditorBrowsable(EditorBrowsableState.Never)]
48 public Pagination() : base()
54 /// Creates a new instance of a Pagination using style.
56 /// <since_tizen> 6 </since_tizen>
57 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
58 [EditorBrowsable(EditorBrowsableState.Never)]
59 public Pagination(string style) : base(style)
65 /// Creates a new instance of a Pagination using attributes.
67 /// <since_tizen> 6 </since_tizen>
68 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
69 [EditorBrowsable(EditorBrowsableState.Never)]
70 public Pagination(PaginationAttributes attributes) : base(attributes)
76 /// Gets or sets the size of the indicator.
78 /// <since_tizen> 6 </since_tizen>
79 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public Size2D IndicatorSize
85 return paginationAttributes?.IndicatorSize;
89 if (value == null || paginationAttributes == null)
93 paginationAttributes.IndicatorSize = value;
99 /// Gets or sets the background resource of indicator.
101 /// <since_tizen> 6 </since_tizen>
102 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
103 [EditorBrowsable(EditorBrowsableState.Never)]
104 public string IndicatorBackgroundURL
108 return paginationAttributes?.IndicatorBackgroundURL;
112 if (value == null || paginationAttributes == null)
116 paginationAttributes.IndicatorBackgroundURL = value;
122 /// Gets or sets the resource of the select indicator.
124 /// <since_tizen> 6 </since_tizen>
125 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public string IndicatorSelectURL
131 return paginationAttributes?.IndicatorSelectURL;
135 if (value == null || paginationAttributes == null)
139 paginationAttributes.IndicatorSelectURL = value;
145 /// Gets or sets the space of the indicator.
147 /// <since_tizen> 6 </since_tizen>
148 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
149 [EditorBrowsable(EditorBrowsableState.Never)]
150 public int IndicatorSpacing
154 return (int)paginationAttributes?.IndicatorSpacing;
158 if (paginationAttributes == null)
162 paginationAttributes.IndicatorSpacing = value;
169 /// Gets or sets the count of the pages/indicators.
171 /// <since_tizen> 6 </since_tizen>
172 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public int IndicatorCount
178 return indicatorCount;
182 if (indicatorCount == value || indicatorCount < 0)
186 if (indicatorCount < value)
188 for (int i = indicatorCount; i < value; i++)
195 for (int i = value; i < indicatorCount; i++)
197 ImageVisual indicator = indicatorList[i];
198 container.RemoveVisual("Indicator" + i);
200 indicatorList.RemoveRange(value, indicatorCount - value);
203 container.RemoveVisual("SelectIndicator");
205 else if(selectedIndex >= value)
208 SelectIn(indicatorList[selectedIndex]);
211 indicatorCount = value;
218 /// Gets or sets the index of the select indicator.
220 /// <since_tizen> 6 </since_tizen>
221 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
222 [EditorBrowsable(EditorBrowsableState.Never)]
223 public int SelectedIndex
227 return selectedIndex;
231 if (selectedIndex == value)
235 if (selectedIndex >= 0 && selectedIndex < indicatorCount)
237 SelectOut(indicatorList[selectedIndex]);
239 selectedIndex = value;
240 if (selectedIndex >= 0 && selectedIndex < indicatorCount)
242 SelectIn(indicatorList[selectedIndex]);
248 /// Retrieves the position of a indicator by index.
250 /// <param name="index">Indicator index</param>
251 /// <since_tizen> 6 </since_tizen>
252 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
253 [EditorBrowsable(EditorBrowsableState.Never)]
254 public Position2D GetIndicatorPosition(int index)
256 if (index < 0 || index >= indicatorList.Count)
260 return new Vector2(indicatorList[index].Position.X + container.PositionX, indicatorList[index].Position.Y + container.PositionY);
264 /// You can override it to do your select out operation.
266 /// <param name="selectOutIndicator">The indicator will be selected out</param>
267 /// <since_tizen> 6 </since_tizen>
268 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
269 [EditorBrowsable(EditorBrowsableState.Never)]
270 protected virtual void SelectOut(VisualMap selectOutIndicator)
276 /// You can override it to do your select in operation.
278 /// <param name="selectInIndicator">The indicator will be selected in</param>
279 /// <since_tizen> 6 </since_tizen>
280 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
281 [EditorBrowsable(EditorBrowsableState.Never)]
282 protected virtual void SelectIn(VisualMap selectInIndicator)
284 selectIndicator.Position = selectInIndicator.Position;
288 /// you can override it to create your own default attributes.
290 /// <since_tizen> 6 </since_tizen>
291 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
292 [EditorBrowsable(EditorBrowsableState.Never)]
293 protected override Attributes GetAttributes()
295 return new PaginationAttributes();
299 /// you can override it to clean-up your own resources.
301 /// <param name="type">DisposeTypes</param>
302 /// <since_tizen> 6 </since_tizen>
303 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
304 [EditorBrowsable(EditorBrowsableState.Never)]
305 protected override void Dispose(DisposeTypes type)
312 if (type == DisposeTypes.Explicit)
314 container.RemoveAll();
315 indicatorList.Clear();
317 this.Remove(container);
326 /// you can override it to update your own resources.
328 /// <since_tizen> 6 </since_tizen>
329 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
330 [EditorBrowsable(EditorBrowsableState.Never)]
331 protected override void OnUpdate()
334 for (int i = 0; i < indicatorList.Count; i++)
336 ImageVisual indicator = indicatorList[i];
337 indicator.URL = paginationAttributes.IndicatorBackgroundURL;
338 indicator.Size = paginationAttributes.IndicatorSize;
339 indicator.Position = new Position2D((int)(paginationAttributes.IndicatorSize.Width + paginationAttributes.IndicatorSpacing) * i, 0);
342 selectIndicator.URL = paginationAttributes.IndicatorSelectURL;
343 selectIndicator.Size = paginationAttributes.IndicatorSize;
348 private void Initialize()
350 paginationAttributes = attributes as PaginationAttributes;
351 if (paginationAttributes == null)
353 throw new Exception("Pagination attributes is null.");
356 container = new VisualView()
359 ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft,
360 PivotPoint = Tizen.NUI.PivotPoint.CenterLeft,
361 PositionUsesPivotPoint = true,
362 //BackgroundColor = Color.Yellow
366 selectIndicator = new ImageVisual()
370 container.AddVisual("SelectIndicator", selectIndicator);
373 private void CreateIndicator()
375 if (paginationAttributes == null)
379 ImageVisual indicator = new ImageVisual
381 URL = paginationAttributes.IndicatorBackgroundURL,
382 Size = paginationAttributes.IndicatorSize
384 indicator.Position = new Position2D((int)(paginationAttributes.IndicatorSize.Width + paginationAttributes.IndicatorSpacing) * indicatorList.Count, 0);
385 container.AddVisual("Indicator" + indicatorList.Count, indicator);
386 indicatorList.Add(indicator);
389 private void UpdateContainer()
391 if (paginationAttributes == null)
395 if (indicatorList.Count > 0)
397 container.SizeWidth = (paginationAttributes.IndicatorSize.Width + paginationAttributes.IndicatorSpacing) * indicatorList.Count - paginationAttributes.IndicatorSpacing;
401 container.SizeWidth = 0;
403 container.SizeHeight = paginationAttributes.IndicatorSize.Height;
404 container.PositionX = (int)((this.SizeWidth - container.SizeWidth) / 2);