2 * Copyright(c) 2021 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 Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
22 namespace Tizen.NUI.Components
25 /// TabContent is a class which contains a set of Views and has one of them selected.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class TabContent : Control
30 private IList<View> views;
33 /// Creates a new instance of TabContent.
35 [EditorBrowsable(EditorBrowsableState.Never)]
39 views = new List<View>();
43 /// The index of the selected view.
45 [EditorBrowsable(EditorBrowsableState.Never)]
46 protected int SelectedIndex { get; set; }
49 /// Gets the count of views.
51 [EditorBrowsable(EditorBrowsableState.Never)]
52 public int ViewCount => views.Count;
55 /// Adds a view to TabContent.
57 /// <param name="view">A view to be added to TabContent.</param>
58 /// <exception cref="ArgumentNullException">Thrown when the argument view is null.</exception>
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 protected internal void AddView(View view)
64 throw new ArgumentNullException(nameof(view), "view should not be null.");
69 if (SelectedIndex == -1)
76 /// Removes a view from TabContent.
78 /// <param name="view">A view to be removed from TabContent.</param>
79 /// <exception cref="ArgumentNullException">Thrown when the argument view is null.</exception>
80 /// <exception cref="ArgumentException">Thrown when the argument view does not exist in TabContent.</exception>
81 [EditorBrowsable(EditorBrowsableState.Never)]
82 protected internal void RemoveView(View view)
86 throw new ArgumentNullException(nameof(view), "view should not be null.");
89 if (views.Contains(view) == false)
91 throw new ArgumentException("view does not exist in TabContent.", nameof(view));
94 int index = views.IndexOf(view);
98 if (index == SelectedIndex)
100 if (views.Count == 0)
104 else if (SelectedIndex == views.Count)
106 Select(SelectedIndex - 1);
112 /// Selects a view at the specified index of TabContent.
114 /// <param name="index">The index of TabContent where a view will be selected.</param>
115 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than -1, or greater than or equal to the number of views.</exception>
116 [EditorBrowsable(EditorBrowsableState.Never)]
117 protected internal void Select(int index)
119 if ((index < -1) || (index >= views.Count))
121 throw new ArgumentOutOfRangeException(nameof(index), "index should not be greater than or equal to -1, and less than the number of views.");
124 if (SelectedIndex != -1)
126 Remove(views[SelectedIndex]);
134 SelectedIndex = index;
138 /// Gets the view at the specified index of TabContent.
140 /// <param name="index">The index of TabContent where the specified view exists.</param>
141 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than 0, or greater than or equal to the number of views.</exception>
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public View GetView(int index)
145 if ((index < 0) || (index >= views.Count))
147 throw new ArgumentOutOfRangeException(nameof(index), "index should not be greater than or equal to 0, and less than the number of views.");
154 /// Dispose TabContent and all children on it.
156 /// <param name="type">Dispose type.</param>
157 [EditorBrowsable(EditorBrowsableState.Never)]
158 protected override void Dispose(DisposeTypes type)
165 if (type == DisposeTypes.Explicit)
169 foreach (View view in views)
171 Utility.Dispose(view);