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 VisualView container;
34 private List<ImageVisual> indicatorList = new List<ImageVisual>();
36 private int indicatorCount = 0;
37 private int selectedIndex = -1;
39 static Pagination() { }
42 /// Creates a new instance of a Pagination.
44 /// <since_tizen> 6 </since_tizen>
45 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
46 [EditorBrowsable(EditorBrowsableState.Never)]
47 public Pagination() : base()
53 /// Creates a new instance of a Pagination using style.
55 /// <since_tizen> 6 </since_tizen>
56 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
57 [EditorBrowsable(EditorBrowsableState.Never)]
58 public Pagination(string style) : base(style)
64 /// Creates a new instance of a Pagination using style.
66 /// <since_tizen> 6 </since_tizen>
67 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
68 [EditorBrowsable(EditorBrowsableState.Never)]
69 public Pagination(PaginationStyle paginationStyle) : base(paginationStyle)
75 /// Get style of pagination.
77 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
78 [EditorBrowsable(EditorBrowsableState.Never)]
79 public new PaginationStyle Style => ViewStyle as PaginationStyle;
82 /// Gets or sets the size of the indicator.
84 /// <since_tizen> 6 </since_tizen>
85 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public Size IndicatorSize
91 return Style?.IndicatorSize;
95 if (value == null || Style == null)
99 Style.IndicatorSize = value;
105 /// Gets or sets the background resource of indicator.
107 /// <since_tizen> 6 </since_tizen>
108 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
109 [EditorBrowsable(EditorBrowsableState.Never)]
110 public Selector<string> IndicatorImageURL
114 return Style?.IndicatorImageURL;
118 if (value == null || Style == null)
122 Style.IndicatorImageURL = value;
128 /// Gets or sets the space of the indicator.
130 /// <since_tizen> 6 </since_tizen>
131 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
132 [EditorBrowsable(EditorBrowsableState.Never)]
133 public int IndicatorSpacing
137 return (int)Style?.IndicatorSpacing;
141 Style.IndicatorSpacing = value;
148 /// Gets or sets the count of the pages/indicators.
150 /// <since_tizen> 6 </since_tizen>
151 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
152 [EditorBrowsable(EditorBrowsableState.Never)]
153 public int IndicatorCount
157 return indicatorCount;
161 if (indicatorCount == value || indicatorCount < 0)
165 if (indicatorCount < value)
167 for (int i = indicatorCount; i < value; i++)
174 for (int i = value; i < indicatorCount; i++)
176 ImageVisual indicator = indicatorList[i];
177 container.RemoveVisual("Indicator" + i);
179 indicatorList.RemoveRange(value, indicatorCount - value);
182 // container.RemoveVisual("SelectIndicator");
185 if (selectedIndex >= value)
188 SelectIn(indicatorList[selectedIndex]);
191 indicatorCount = value;
198 /// Gets or sets the index of the select indicator.
200 /// <since_tizen> 6 </since_tizen>
201 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
202 [EditorBrowsable(EditorBrowsableState.Never)]
203 public int SelectedIndex
207 return selectedIndex;
211 if (selectedIndex == value)
215 if (selectedIndex >= 0 && selectedIndex < indicatorCount)
217 SelectOut(indicatorList[selectedIndex]);
219 selectedIndex = value;
220 if (selectedIndex >= 0 && selectedIndex < indicatorCount)
222 SelectIn(indicatorList[selectedIndex]);
228 /// Retrieves the position of a indicator by index.
230 /// <param name="index">Indicator index</param>
231 /// <since_tizen> 6 </since_tizen>
232 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
233 [EditorBrowsable(EditorBrowsableState.Never)]
234 public Position GetIndicatorPosition(int index)
236 if (index < 0 || index >= indicatorList.Count)
240 return new Position(indicatorList[index].Position.X + container.PositionX, indicatorList[index].Position.Y + container.PositionY);
244 /// You can override it to do your select out operation.
246 /// <param name="selectOutIndicator">The indicator will be selected out</param>
247 /// <since_tizen> 6 </since_tizen>
248 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
249 [EditorBrowsable(EditorBrowsableState.Never)]
250 protected virtual void SelectOut(VisualMap selectOutIndicator)
252 if (!(selectOutIndicator is ImageVisual visual)) return;
253 visual.URL = Style?.IndicatorImageURL.Normal;
254 visual.Opacity = 0.5f;
258 /// You can override it to do your select in operation.
260 /// <param name="selectInIndicator">The indicator will be selected in</param>
261 /// <since_tizen> 6 </since_tizen>
262 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
263 [EditorBrowsable(EditorBrowsableState.Never)]
264 protected virtual void SelectIn(VisualMap selectInIndicator)
266 if (!(selectInIndicator is ImageVisual visual)) return;
267 visual.URL = Style?.IndicatorImageURL.Selected;
268 visual.Opacity = 1.0f;
272 /// you can override it to create your own default style.
274 /// <since_tizen> 6 </since_tizen>
275 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
276 [EditorBrowsable(EditorBrowsableState.Never)]
277 protected override ViewStyle CreateViewStyle()
279 return new PaginationStyle();
283 /// you can override it to clean-up your own resources.
285 /// <param name="type">DisposeTypes</param>
286 /// <since_tizen> 6 </since_tizen>
287 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
288 [EditorBrowsable(EditorBrowsableState.Never)]
289 protected override void Dispose(DisposeTypes type)
296 if (type == DisposeTypes.Explicit)
298 container.RemoveAll();
299 indicatorList.Clear();
301 this.Remove(container);
309 private void Initialize()
311 container = new VisualView()
314 ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft,
315 PivotPoint = Tizen.NUI.PivotPoint.CenterLeft,
316 PositionUsesPivotPoint = true,
321 private void CreateIndicator()
327 ImageVisual indicator = new ImageVisual
329 URL = Style.IndicatorImageURL.Normal,
330 Size = new Size2D((int)Style.IndicatorSize.Width, (int)Style.IndicatorSize.Height),
333 indicator.Position = new Position2D((int)(Style.IndicatorSize.Width + Style.IndicatorSpacing) * indicatorList.Count, 0);
334 container.AddVisual("Indicator" + indicatorList.Count, indicator);
335 indicatorList.Add(indicator);
338 private void UpdateContainer()
344 if (indicatorList.Count > 0)
346 container.SizeWidth = (Style.IndicatorSize.Width + Style.IndicatorSpacing) * indicatorList.Count - Style.IndicatorSpacing;
350 container.SizeWidth = 0;
352 container.SizeHeight = Style.IndicatorSize.Height;
353 container.PositionX = (int)((this.SizeWidth - container.SizeWidth) / 2);
356 private void UpdateVisual()
358 if (null == Style.IndicatorSize) return;
359 if (null == Style.IndicatorImageURL) return;
360 if (indicatorCount < 0) return;
362 for (int i = 0; i < indicatorList.Count; i++)
364 ImageVisual indicator = indicatorList[i];
365 indicator.URL = Style.IndicatorImageURL.Normal;
366 indicator.Size = new Size2D((int)Style.IndicatorSize.Width, (int)Style.IndicatorSize.Height);
367 indicator.Position = new Position2D((int)(Style.IndicatorSize.Width + Style.IndicatorSpacing) * i, 0);