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.
22 /// Enumeration for the selection mode of Toolbar.
24 public enum ToolbarSelectionMode
27 /// Default select mode.
32 /// Always select mode.
42 /// No select mode with no finger size rule.
48 /// Enumeration that sets the toolbar items display behavior, it can be scrollable, can show a menu with exceeding items, or simply hide them.
50 public enum ToolbarShrinkMode
53 /// Sets minimum toolbar size to fit all the items.
58 /// Hides exceeding items.
63 /// Allows accessing exceeding items through a scroller.
68 /// Inserts a button to pop up a menu with exceeding items.
73 /// Expands all items according to the size of the toolbar.
79 /// Event arguments for events of <see cref="ToolbarItem"/>.
82 /// Inherits EventArgs.
84 public class ToolbarItemEventArgs : EventArgs
87 /// Gets the ToolbarItem.
89 public ToolbarItem Item { get; private set; }
91 internal static ToolbarItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
93 ToolbarItem item = ItemObject.GetItemByHandle(info) as ToolbarItem;
94 return new ToolbarItemEventArgs() { Item = item };
99 /// The Toolbar is a widget that displays a list of items inside a box.
101 public class Toolbar : Widget
103 SmartEvent<ToolbarItemEventArgs> _clicked;
104 SmartEvent<ToolbarItemEventArgs> _selected;
105 SmartEvent<ToolbarItemEventArgs> _longpressed;
108 /// Creates and initializes a new instance of the Toolbar class.
110 /// <param name="parent">
111 /// A EvasObject to which the new Table instance will be attached.
113 public Toolbar(EvasObject parent) : base(parent)
115 _selected = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "selected", ToolbarItemEventArgs.CreateFromSmartEvent);
116 _selected.On += (s, e) =>
120 Selected?.Invoke(this, e);
121 e.Item.SendSelected();
124 _longpressed = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "longpressed", ToolbarItemEventArgs.CreateFromSmartEvent);
125 _longpressed.On += (s, e) =>
127 e.Item?.SendLongPressed();
129 _clicked = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "clicked", ToolbarItemEventArgs.CreateFromSmartEvent);
130 _clicked.On += (s, e) =>
132 e.Item?.SendClicked();
137 /// Selected will be triggered when toolbar have been selected.
139 public event EventHandler<ToolbarItemEventArgs> Selected;
142 /// Sets or gets whether the layout of this toolbar is homogeneous.
144 /// <remarks>True for homogeneous, False for no homogeneous</remarks>
145 public bool Homogeneous
149 return Interop.Elementary.elm_toolbar_homogeneous_get(RealHandle);
153 Interop.Elementary.elm_toolbar_homogeneous_set(RealHandle, value);
158 /// Sets or gets the slection mode of a given Toolbar widget.
160 public ToolbarSelectionMode SelectionMode
164 return (ToolbarSelectionMode)Interop.Elementary.elm_toolbar_select_mode_get(RealHandle);
168 Interop.Elementary.elm_toolbar_select_mode_set(RealHandle, (int)value);
173 /// Sets or gets the shrink mode of a given Toolbar widget.
175 public ToolbarShrinkMode ShrinkMode
179 return (ToolbarShrinkMode)Interop.Elementary.elm_toolbar_shrink_mode_get(RealHandle);
183 Interop.Elementary.elm_toolbar_shrink_mode_set(RealHandle, (int)value);
188 /// Sets or gets the alignment of the items.
190 /// <remarks>The toolbar items alignment, a float between 0.0 and 1.0</remarks>
191 public double ItemAlignment
195 return Interop.Elementary.elm_toolbar_align_get(RealHandle);
199 Interop.Elementary.elm_toolbar_align_set(RealHandle, value);
204 /// Sets or gets the item's transverse expansion of a given toolbar widget.
207 /// The transverse expansion of the item, true for on and false for off.
208 /// By default it's false.
210 public bool TransverseExpansion
214 return Interop.Elementary.elm_toolbar_transverse_expanded_get(RealHandle);
218 Interop.Elementary.elm_toolbar_transverse_expanded_set(RealHandle, value);
223 /// Appends ToolbarItem which just contains label to the toolbar.
225 /// <param name="label">The label of the item</param>
226 /// <returns>The new ToolbarItem which appended to the toolbar</returns>
227 /// <seealso cref="Append(string, string)"/>
228 /// <seealso cref="Prepend(string)"/>
229 public ToolbarItem Append(string label)
231 return Append(label, null);
235 /// Appends ToolbarItem which contains label and icon to the toolbar.
237 /// <param name="label">The label of the item</param>
238 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
239 /// <returns>The new ToolbarItem which appended to the toolbar</returns>
240 /// <seealso cref="Append(string)"/>
241 /// <seealso cref="Prepend(string)"/>
242 /// <seealso cref="Prepend(string, string)"/>
243 public ToolbarItem Append(string label, string icon)
245 ToolbarItem item = new ToolbarItem(label, icon);
246 item.Handle = Interop.Elementary.elm_toolbar_item_append(RealHandle, icon, label, null, (IntPtr)item.Id);
251 /// Prepends ToolbarItem which just contains label to the toolbar.
253 /// <param name="label">The label of the item</param>
254 /// <returns>The new ToolbarItem which prepended to the toolbar</returns>
255 /// <seealso cref="Append(string)"/>
256 /// <seealso cref="Append(string, string)"/>
257 /// <seealso cref="Prepend(string, string)"/>
258 public ToolbarItem Prepend(string label)
260 return Prepend(label, null);
264 /// Prepends ToolbarItem which contains label and icon to the toolbar.
266 /// <param name="label">The label of the item</param>
267 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
268 /// <returns>The new <see cref="ToolbarItem"/> which prepended to the toolbar</returns>
269 /// <seealso cref="Append(string)"/>
270 /// <seealso cref="Append(string, string)"/>
271 /// <seealso cref="Prepend(string)"/>
272 public ToolbarItem Prepend(string label, string icon)
274 ToolbarItem item = new ToolbarItem(label, icon);
275 item.Handle = Interop.Elementary.elm_toolbar_item_prepend(RealHandle, icon, label, null, (IntPtr)item.Id);
280 /// Inserts a new item which just contains label into the toolbar object before item <paramref name="before"/>.
282 /// <param name="before">The toolbar item to insert before</param>
283 /// <param name="label">The label of the item</param>
284 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
285 /// <seealso cref="InsertBefore(ToolbarItem, string, string)"/>
286 public ToolbarItem InsertBefore(ToolbarItem before, string label)
288 return InsertBefore(before, label);
292 /// Inserts a new item which contains label and icon into the toolbar object before item <paramref name="before"/>.
294 /// <param name="before">The toolbar item to insert before</param>
295 /// <param name="label">The label of the item</param>
296 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
297 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
298 /// <seealso cref="InsertBefore(ToolbarItem, string)"/>
299 public ToolbarItem InsertBefore(ToolbarItem before, string label, string icon)
301 ToolbarItem item = new ToolbarItem(label, icon);
302 item.Handle = Interop.Elementary.elm_toolbar_item_insert_before(RealHandle, before, icon, label, null, (IntPtr)item.Id);
307 /// Gets the selected ToolbarItemItem of the toolbar.
309 public ToolbarItem SelectedItem
313 IntPtr handle = Interop.Elementary.elm_toolbar_selected_item_get(RealHandle);
314 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
318 protected override IntPtr CreateHandle(EvasObject parent)
320 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
321 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
323 RealHandle = Interop.Elementary.elm_toolbar_add(handle);
324 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);