2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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;
23 /// The Index widget gives you an index for fast access to whichever group of the other UI items one might have.
26 /// <since_tizen> preview </since_tizen>
27 public class Index : Layout
29 HashSet<IndexItem> _children = new HashSet<IndexItem>();
30 SmartEvent _delayedChanged;
33 /// Creates and initializes a new instance of the Index class.
35 /// <param name="parent">The parent is a given container, which will be attached by Index as a child. It's <see cref="EvasObject"/> type.</param>
36 /// <since_tizen> preview </since_tizen>
37 public Index(EvasObject parent) : base(parent)
39 _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
40 _delayedChanged.On += _delayedChanged_On;
44 /// Changed will be triggered when the selected index item is changed.
46 /// <since_tizen> preview </since_tizen>
47 public event EventHandler Changed;
50 /// Sets or gets whether the auto hiding feature is enabled or not for a given index widget.
52 /// <since_tizen> preview </since_tizen>
57 return !Interop.Elementary.elm_index_autohide_disabled_get(RealHandle);
61 Interop.Elementary.elm_index_autohide_disabled_set(RealHandle, !value);
66 /// Sets or gets a value whether the horizontal mode is enabled or not.
68 /// <since_tizen> preview </since_tizen>
69 public bool IsHorizontal
73 return Interop.Elementary.elm_index_horizontal_get(RealHandle);
77 Interop.Elementary.elm_index_horizontal_set(RealHandle, value);
82 /// Sets or gets a value of the indicator's disabled status.
84 /// <since_tizen> preview </since_tizen>
85 public bool IndicatorVisible
89 return !Interop.Elementary.elm_index_indicator_disabled_get(RealHandle);
93 Interop.Elementary.elm_index_indicator_disabled_set(RealHandle, !value);
98 /// Sets or gets whether the omit feature is enabled or not for a given index widget.
100 /// <since_tizen> preview </since_tizen>
101 public bool OmitEnabled
105 return Interop.Elementary.elm_index_omit_enabled_get(RealHandle);
109 Interop.Elementary.elm_index_omit_enabled_set(RealHandle, value);
114 /// Sets a delay change time for the index object.
115 /// The delay time is 0.2 seconds by default.
117 /// <since_tizen> preview </since_tizen>
122 return Interop.Elementary.elm_index_delay_change_time_get(RealHandle);
126 Interop.Elementary.elm_index_delay_change_time_set(RealHandle, value);
131 /// Gets or sets the items level for a given index widget.
133 /// <since_tizen> preview </since_tizen>
138 return Interop.Elementary.elm_index_item_level_get(RealHandle);
142 Interop.Elementary.elm_index_item_level_set(RealHandle, value);
147 /// Controls the standard_priority group of the index.
148 /// Priority group will be shown as many items as it can, and other group will be shown for one character only.
150 /// <since_tizen> preview </since_tizen>
155 return Interop.Elementary.elm_index_standard_priority_get(RealHandle);
159 Interop.Elementary.elm_index_standard_priority_set(RealHandle, value);
164 /// Gets the last selected item for a given index widget.
166 /// <since_tizen> preview </since_tizen>
167 public IndexItem SelectedItem
171 IntPtr handle = Interop.Elementary.elm_index_selected_item_get(RealHandle, 0);
172 return ItemObject.GetItemByHandle(handle) as IndexItem;
177 /// Appends a new item on a given index widget.
179 /// <param name="label">The label for which the item should be indexed.</param>
180 /// <returns>An object to the IndexItem if added, or null on errors.</returns>
181 /// <since_tizen> preview </since_tizen>
182 public IndexItem Append(string label)
184 IndexItem item = new IndexItem(label, this);
185 item.Handle = Interop.Elementary.elm_index_item_append(RealHandle, label, null, (IntPtr)item.Id);
190 /// Prepends a new item on a given index widget.
192 /// <param name="label">The label for which the item should be indexed.</param>
193 /// <returns>A handle to the item if added, or null on errors.</returns>
194 /// <since_tizen> preview </since_tizen>
195 public IndexItem Prepend(string label)
197 IndexItem item = new IndexItem(label, this);
198 item.Handle = Interop.Elementary.elm_index_item_prepend(RealHandle, label, null, (IntPtr)item.Id);
203 /// Inserts a new item into the index object before the item before.
205 /// <param name="label">The label for which the item should be indexed.</param>
206 /// <param name="before">The index item to insert after.</param>
207 /// <returns>An object to the IndexItem if added, or null on errors.</returns>
208 /// <since_tizen> preview </since_tizen>
209 public IndexItem InsertBefore(string label, IndexItem before)
211 IndexItem item = new IndexItem(label, this);
212 item.Handle = Interop.Elementary.elm_index_item_insert_before(RealHandle, before, label, null, (IntPtr)item.Id);
217 /// Inserts a new item into the index object after the item after.
219 /// <param name="label">The label for which the item should be indexed.</param>
220 /// <param name="after">The index item to insert after.</param>
221 /// <returns>An object to the IndexItem if added, or null on errors.</returns>
222 /// <since_tizen> preview </since_tizen>
223 public IndexItem InsertAfter(string label, IndexItem after)
225 IndexItem item = new IndexItem(label, this);
226 item.Handle = Interop.Elementary.elm_index_item_insert_after(RealHandle, after, label, null, (IntPtr)item.Id);
231 /// Flushes the changes made to the index items so that they work correctly.
233 /// <param name="level">The index level (one of 0 or 1) where the changes were made.</param>
234 /// <since_tizen> preview </since_tizen>
235 public void Update(int level)
237 Interop.Elementary.elm_index_level_go(RealHandle, level);
241 /// Removes all the items from a given index widget.
243 /// <since_tizen> preview </since_tizen>
246 Interop.Elementary.elm_index_item_clear(RealHandle);
250 /// Creates a widget handle.
252 /// <param name="parent">Parent EvasObject.</param>
253 /// <returns>Handle IntPtr.</returns>
254 /// <since_tizen> preview </since_tizen>
255 protected override IntPtr CreateHandle(EvasObject parent)
257 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
258 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
260 RealHandle = Interop.Elementary.elm_index_add(handle);
261 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
266 void _delayedChanged_On(object sender, EventArgs e)
268 SelectedItem?.SendSelected();
269 Changed?.Invoke(this, e);