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 /// An index widget gives you an index for fast access to whichever group of other UI items one might have.
26 public class Index : Layout
28 HashSet<IndexItem> _children = new HashSet<IndexItem>();
29 SmartEvent _delayedChanged;
32 /// Creates and initializes a new instance of Index class.
34 /// <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>
35 public Index(EvasObject parent) : base(parent)
37 _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
38 _delayedChanged.On += _delayedChanged_On;
42 /// Changed will be triggered when the selected index item is changed.
44 public event EventHandler Changed;
47 /// Sets or gets the auto hiding feature is enabled or not for a given index widget.
53 return !Interop.Elementary.elm_index_autohide_disabled_get(RealHandle);
57 Interop.Elementary.elm_index_autohide_disabled_set(RealHandle, !value);
62 /// Sets or gets a value whether horizontal mode is enabled or not.
64 public bool IsHorizontal
68 return Interop.Elementary.elm_index_horizontal_get(RealHandle);
72 Interop.Elementary.elm_index_horizontal_set(RealHandle, value);
77 /// Sets or gets the value of indicator's disabled status.
79 public bool IndicatorVisible
83 return !Interop.Elementary.elm_index_indicator_disabled_get(RealHandle);
87 Interop.Elementary.elm_index_indicator_disabled_set(RealHandle, !value);
92 /// Sets or gets the omit feature is enabled or not for a given index widget.
94 public bool OmitEnabled
98 return Interop.Elementary.elm_index_omit_enabled_get(RealHandle);
102 Interop.Elementary.elm_index_omit_enabled_set(RealHandle, value);
107 /// Set a delay change time for index object.
108 /// delay time is 0.2 sec by default.
114 return Interop.Elementary.elm_index_delay_change_time_get(RealHandle);
118 Interop.Elementary.elm_index_delay_change_time_set(RealHandle, value);
123 /// Gets or sets the items level for a given index widget.
129 return Interop.Elementary.elm_index_item_level_get(RealHandle);
133 Interop.Elementary.elm_index_item_level_set(RealHandle, value);
138 /// Control standard_priority group of index.
139 /// Priority group will be shown as many items as it can, and other group will be shown one character only.
145 return Interop.Elementary.elm_index_standard_priority_get(RealHandle);
149 Interop.Elementary.elm_index_standard_priority_set(RealHandle, value);
154 /// Gets the last selected item, for a given index widget.
156 public IndexItem SelectedItem
160 IntPtr handle = Interop.Elementary.elm_index_selected_item_get(RealHandle, 0);
161 return ItemObject.GetItemByHandle(handle) as IndexItem;
166 /// Append a new item on a given index widget.
168 /// <param name="label">the label which the item should be indexed</param>
169 /// <returns>A object to the IndexItem added or null, on errors</returns>
170 public IndexItem Append(string label)
172 IndexItem item = new IndexItem(label);
173 item.Handle = Interop.Elementary.elm_index_item_append(RealHandle, label, null, (IntPtr)item.Id);
178 /// Prepend a new item on a given index widget.
180 /// <param name="label">the label which the item should be indexed</param>
181 /// <returns>A handle to the item added or NULL, on errors</returns>
182 public IndexItem Prepend(string label)
184 IndexItem item = new IndexItem(label);
185 item.Handle = Interop.Elementary.elm_index_item_prepend(RealHandle, label, null, (IntPtr)item.Id);
190 /// Insert a new item into the index object before item before.
192 /// <param name="label">the label which the item should be indexed</param>
193 /// <param name="before">The index item to insert after.</param>
194 /// <returns>A object to the IndexItem added or null, on errors</returns>
195 public IndexItem InsertBefore(string label, IndexItem before)
197 IndexItem item = new IndexItem(label);
198 item.Handle = Interop.Elementary.elm_index_item_insert_before(RealHandle, before, label, null, (IntPtr)item.Id);
203 /// Insert a new item into the index object after item after.
205 /// <param name="label">the label which the item should be indexed</param>
206 /// <param name="after">The index item to insert after.</param>
207 /// <returns>A object to the IndexItem added or null, on errors</returns>
208 public IndexItem InsertAfter(string label, IndexItem after)
210 IndexItem item = new IndexItem(label);
211 item.Handle = Interop.Elementary.elm_index_item_insert_after(RealHandle, after, label, null, (IntPtr)item.Id);
216 /// Flush the changes made to the index items so they work correctly.
218 /// <param name="level">The index level (one of 0 or 1) where changes were made</param>
219 public void Update(int level)
221 Interop.Elementary.elm_index_level_go(RealHandle, level);
225 /// Removes all items from a given index widget.
229 Interop.Elementary.elm_index_item_clear(RealHandle);
232 protected override IntPtr CreateHandle(EvasObject parent)
234 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
235 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
237 RealHandle = Interop.Elementary.elm_index_add(handle);
238 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
243 void _delayedChanged_On(object sender, EventArgs e)
245 SelectedItem?.SendSelected();
246 Changed?.Invoke(this, e);
249 void AddInternal(IndexItem item)
252 item.Deleted += Item_Deleted;
255 void Item_Deleted(object sender, EventArgs e)
257 _children.Remove((IndexItem)sender);