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 PaginationStyle paginationStyle;
34 private VisualView container;
36 private List<ImageVisual> indicatorList = new List<ImageVisual>();
38 private int indicatorCount = 0;
39 private int selectedIndex = -1;
41 static Pagination() { }
44 /// Creates a new instance of a Pagination.
46 /// <since_tizen> 6 </since_tizen>
47 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 public Pagination() : base()
55 /// Creates a new instance of a Pagination using style.
57 /// <since_tizen> 6 </since_tizen>
58 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public Pagination(string style) : base(style)
66 /// Creates a new instance of a Pagination using style.
68 /// <since_tizen> 6 </since_tizen>
69 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public Pagination(PaginationStyle paginationStyle) : base(paginationStyle)
77 /// Gets or sets the size of the indicator.
79 /// <since_tizen> 6 </since_tizen>
80 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
81 [EditorBrowsable(EditorBrowsableState.Never)]
82 public Size IndicatorSize
86 return paginationStyle?.IndicatorSize;
90 if (value == null || paginationStyle == null)
94 paginationStyle.IndicatorSize = value;
100 /// Gets or sets the background resource of indicator.
102 /// <since_tizen> 6 </since_tizen>
103 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
104 [EditorBrowsable(EditorBrowsableState.Never)]
105 public Selector<string> IndicatorImageURL
109 return paginationStyle?.IndicatorImageURL;
113 if (value == null || paginationStyle == null)
117 paginationStyle.IndicatorImageURL = value;
123 /// Gets or sets the space of the indicator.
125 /// <since_tizen> 6 </since_tizen>
126 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
127 [EditorBrowsable(EditorBrowsableState.Never)]
128 public int IndicatorSpacing
132 return (int)paginationStyle?.IndicatorSpacing;
136 if (paginationStyle == null)
140 paginationStyle.IndicatorSpacing = value;
147 /// Gets or sets the count of the pages/indicators.
149 /// <since_tizen> 6 </since_tizen>
150 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public int IndicatorCount
156 return indicatorCount;
160 if (indicatorCount == value || indicatorCount < 0)
164 if (indicatorCount < value)
166 for (int i = indicatorCount; i < value; i++)
173 for (int i = value; i < indicatorCount; i++)
175 ImageVisual indicator = indicatorList[i];
176 container.RemoveVisual("Indicator" + i);
178 indicatorList.RemoveRange(value, indicatorCount - value);
181 // container.RemoveVisual("SelectIndicator");
184 if (selectedIndex >= value)
187 SelectIn(indicatorList[selectedIndex]);
190 indicatorCount = value;
197 /// Gets or sets the index of the select indicator.
199 /// <since_tizen> 6 </since_tizen>
200 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
201 [EditorBrowsable(EditorBrowsableState.Never)]
202 public int SelectedIndex
206 return selectedIndex;
210 if (selectedIndex == value)
214 if (selectedIndex >= 0 && selectedIndex < indicatorCount)
216 SelectOut(indicatorList[selectedIndex]);
218 selectedIndex = value;
219 if (selectedIndex >= 0 && selectedIndex < indicatorCount)
221 SelectIn(indicatorList[selectedIndex]);
227 /// Retrieves the position of a indicator by index.
229 /// <param name="index">Indicator index</param>
230 /// <since_tizen> 6 </since_tizen>
231 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
232 [EditorBrowsable(EditorBrowsableState.Never)]
233 public Position GetIndicatorPosition(int index)
235 if (index < 0 || index >= indicatorList.Count)
239 return new Position(indicatorList[index].Position.X + container.PositionX, indicatorList[index].Position.Y + container.PositionY);
243 /// You can override it to do your select out operation.
245 /// <param name="selectOutIndicator">The indicator will be selected out</param>
246 /// <since_tizen> 6 </since_tizen>
247 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
248 [EditorBrowsable(EditorBrowsableState.Never)]
249 protected virtual void SelectOut(VisualMap selectOutIndicator)
251 if (!(selectOutIndicator is ImageVisual visual)) return;
252 visual.URL = paginationStyle.IndicatorImageURL.Normal;
256 /// You can override it to do your select in operation.
258 /// <param name="selectInIndicator">The indicator will be selected in</param>
259 /// <since_tizen> 6 </since_tizen>
260 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
261 [EditorBrowsable(EditorBrowsableState.Never)]
262 protected virtual void SelectIn(VisualMap selectInIndicator)
264 if (!(selectInIndicator is ImageVisual visual)) return;
265 visual.URL = paginationStyle.IndicatorImageURL.Selected;
269 /// you can override it to create your own default style.
271 /// <since_tizen> 6 </since_tizen>
272 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 protected override ViewStyle GetViewStyle()
276 return new PaginationStyle();
280 /// you can override it to clean-up your own resources.
282 /// <param name="type">DisposeTypes</param>
283 /// <since_tizen> 6 </since_tizen>
284 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
285 [EditorBrowsable(EditorBrowsableState.Never)]
286 protected override void Dispose(DisposeTypes type)
293 if (type == DisposeTypes.Explicit)
295 container.RemoveAll();
296 indicatorList.Clear();
298 this.Remove(container);
306 private void Initialize()
308 paginationStyle = Style as PaginationStyle;
309 if (paginationStyle == null)
311 throw new Exception("Pagination style is null.");
314 container = new VisualView()
317 ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft,
318 PivotPoint = Tizen.NUI.PivotPoint.CenterLeft,
319 PositionUsesPivotPoint = true,
324 private void CreateIndicator()
326 if (paginationStyle == null)
330 ImageVisual indicator = new ImageVisual
332 URL = paginationStyle.IndicatorImageURL.Normal,
333 Size = new Size2D((int)paginationStyle.IndicatorSize.Width, (int)paginationStyle.IndicatorSize.Height)
335 indicator.Position = new Position2D((int)(paginationStyle.IndicatorSize.Width + paginationStyle.IndicatorSpacing) * indicatorList.Count, 0);
336 container.AddVisual("Indicator" + indicatorList.Count, indicator);
337 indicatorList.Add(indicator);
340 private void UpdateContainer()
342 if (paginationStyle == null)
346 if (indicatorList.Count > 0)
348 container.SizeWidth = (paginationStyle.IndicatorSize.Width + paginationStyle.IndicatorSpacing) * indicatorList.Count - paginationStyle.IndicatorSpacing;
352 container.SizeWidth = 0;
354 container.SizeHeight = paginationStyle.IndicatorSize.Height;
355 container.PositionX = (int)((this.SizeWidth - container.SizeWidth) / 2);
358 private void UpdateVisual()
360 if (null == paginationStyle.IndicatorSize) return;
361 if (null == paginationStyle.IndicatorImageURL) return;
362 if (indicatorCount < 0) return;
364 for (int i = 0; i < indicatorList.Count; i++)
366 ImageVisual indicator = indicatorList[i];
367 indicator.URL = paginationStyle.IndicatorImageURL.Normal;
368 indicator.Size = new Size2D((int)paginationStyle.IndicatorSize.Width, (int)paginationStyle.IndicatorSize.Height);
369 indicator.Position = new Position2D((int)(paginationStyle.IndicatorSize.Width + paginationStyle.IndicatorSpacing) * i, 0);