Release 4.0.0-preview1-00285
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / MoreOption.cs
1
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5
6 namespace ElmSharp.Wearable
7 {
8     /// <summary>
9     /// The MoreOption is a widget composed of the toggle(cue button) and more option view, and MoreOption can change a visibility through the toggle.
10     /// Inherits Layout
11     /// </summary>
12     public class MoreOption : Layout
13     {
14         /// <summary>
15         /// Sets or gets the list of more option item
16         /// </summary>
17         public IList<MoreOptionItem> Items { get; private set; }
18
19         /// <summary>
20         /// Selected will be triggered when the user selects an item.
21         /// </summary>
22         public event EventHandler<MoreOptionItemEventArgs> Selected;
23         /// <summary>
24         /// Clicked will be triggered when the user selects the already selected item again or selects a selector.
25         /// </summary>
26         public event EventHandler<MoreOptionItemEventArgs> Clicked;
27         /// <summary>
28         /// Opened will be triggered when more option view is shown.
29         /// </summary>
30         public event EventHandler Opened;
31         /// <summary>
32         /// Closed will be triggered when more option view is hidden.
33         /// </summary>
34         public event EventHandler Closed;
35
36         SmartEvent<PointerEventArgs> _selectedEvent;
37         SmartEvent<PointerEventArgs> _clickedEvent;
38         SmartEvent _openedEvent;
39         SmartEvent _closedEvent;
40
41         /// <summary>
42         /// Creates and initializes a new instance of MoreOption class.
43         /// </summary>
44         /// <param name="parent">The parent is a given container which will be attached by MoreOption as a child. It's <see cref="EvasObject"/> type.</param>
45         public MoreOption(EvasObject parent) : base(parent)
46         {
47             Items = new MoreOptionList(this);
48
49             _selectedEvent = new SmartEvent<PointerEventArgs>(this, "item,selected", (d, o, info) => new PointerEventArgs { Pointer = info });
50             _clickedEvent = new SmartEvent<PointerEventArgs>(this, "item,clicked", (d, o, info) => new PointerEventArgs { Pointer = info });
51             _openedEvent = new SmartEvent(this, "more,option,opened");
52             _closedEvent = new SmartEvent(this, "more,option,closed");
53
54             _selectedEvent.On += (s, e) =>
55             {
56                 MoreOptionItem selected = Items.FirstOrDefault(i => i.Handle == e.Pointer);
57                 Selected?.Invoke(this, new MoreOptionItemEventArgs() { Item = selected });
58             };
59
60             _clickedEvent.On += (s, e) =>
61             {
62                 MoreOptionItem selected = Items.FirstOrDefault(i => i.Handle == e.Pointer);
63                 Clicked?.Invoke(this, new MoreOptionItemEventArgs() { Item = selected });
64             };
65
66             _openedEvent.On += (s, e) => Opened?.Invoke(this, EventArgs.Empty);
67             _closedEvent.On += (s, e) => Closed?.Invoke(this, EventArgs.Empty);
68
69         }
70
71         /// <summary>
72         /// Creates a widget handle.
73         /// </summary>
74         /// <param name="parent">Parent EvasObject</param>
75         /// <returns>Handle IntPtr</returns>
76         protected override IntPtr CreateHandle(EvasObject parent)
77         {
78             return Interop.Eext.eext_more_option_add(parent);
79         }
80
81         /// <summary>
82         /// Sets or gets the direction of more option.
83         /// </summary>
84         public MoreOptionDirection Direction
85         {
86             get
87             {
88                 int dir = Interop.Eext.eext_more_option_direction_get(this);
89                 return (MoreOptionDirection)dir;
90             }
91
92             set
93             {
94                 Interop.Eext.eext_more_option_direction_set(this, (int)value);
95             }
96         }
97
98         /// <summary>
99         /// Sets or gets the visibility of more option view.
100         /// </summary>
101         public bool IsOpened
102         {
103             get
104             {
105                 return Interop.Eext.eext_more_option_opened_get(this);
106             }
107
108             set
109             {
110                 Interop.Eext.eext_more_option_opened_set(this, value);
111             }
112         }
113     }
114
115     /// <summary>
116     /// Enumeration for More Option Direction type.
117     /// </summary>
118     public enum MoreOptionDirection
119     {
120         /// <summary>
121         /// Top direction
122         /// </summary>
123         Top,
124         /// <summary>
125         /// Bottom direction
126         /// </summary>
127         Bottom,
128         /// <summary>
129         /// Left direction
130         /// </summary>
131         Left,
132         /// <summary>
133         /// Right direction
134         /// </summary>
135         Right
136     }
137 }