Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Spinner.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// The Spinner is a widget that increase or decrease numeric values using arrow buttons, or edit values directly.
23     /// Inherits <see cref="Layout"/>.
24     /// </summary>
25     public class Spinner : Layout
26     {
27         double _minimum = 0.0;
28         double _maximum = 100.0;
29
30         SmartEvent _changed;
31         SmartEvent _delayedChanged;
32
33         /// <summary>
34         /// Creates and initializes a new instance of the Spinner class.
35         /// </summary>
36         /// <param name="parent">The parent of new Spinner instance</param>
37         public Spinner(EvasObject parent) : base(parent)
38         {
39             _changed = new SmartEvent(this, this.RealHandle, "changed");
40             _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
41
42             _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
43             _delayedChanged.On += (s, e) => DelayedValueChanged?.Invoke(this, EventArgs.Empty);
44         }
45
46         /// <summary>
47         /// ValueChanged will be triggered whenever the spinner value is changed.
48         /// </summary>
49         public event EventHandler ValueChanged;
50
51         /// <summary>
52         ///  DelayedValueChanged will be triggered after a short time when the value is changed.
53         /// </summary>
54         public event EventHandler DelayedValueChanged;
55
56         /// <summary>
57         /// Sets or gets the label format of the spinner.
58         /// </summary>
59         public string LabelFormat
60         {
61             get
62             {
63                 return Interop.Elementary.elm_spinner_label_format_get(RealHandle);
64             }
65             set
66             {
67                 Interop.Elementary.elm_spinner_label_format_set(RealHandle, value);
68             }
69         }
70
71         /// <summary>
72         /// Sets or gets the minimum value for the spinner.
73         /// </summary>
74         public double Minimum
75         {
76             get
77             {
78                 return _minimum;
79             }
80             set
81             {
82                 _minimum = value;
83                 Interop.Elementary.elm_spinner_min_max_set(RealHandle, _minimum, _maximum);
84             }
85         }
86
87         /// <summary>
88         /// Sets or gets the maximum value for the spinner.
89         /// </summary>
90         public double Maximum
91         {
92             get
93             {
94                 return _maximum;
95             }
96             set
97             {
98                 _maximum = value;
99                 Interop.Elementary.elm_spinner_min_max_set(RealHandle, _minimum, _maximum);
100             }
101         }
102
103         /// <summary>
104         /// Sets or gets the step that used to increment or decrement the spinner value.
105         /// </summary>
106         public double Step
107         {
108             get
109             {
110                 return Interop.Elementary.elm_spinner_step_get(RealHandle);
111             }
112             set
113             {
114                 Interop.Elementary.elm_spinner_step_set(RealHandle, value);
115             }
116         }
117
118         /// <summary>
119         /// Sets or gets the value displayed by the spinner.
120         /// </summary>
121         public double Value
122         {
123             get
124             {
125                 return Interop.Elementary.elm_spinner_value_get(RealHandle);
126             }
127             set
128             {
129                 Interop.Elementary.elm_spinner_value_set(RealHandle, value);
130             }
131         }
132
133         /// <summary>
134         /// Sets or gets the interval on time updates for an user mouse button hold on spinner widgets' arrows.
135         /// </summary>
136         public double Interval
137         {
138             get
139             {
140                 return Interop.Elementary.elm_spinner_interval_get(RealHandle);
141             }
142             set
143             {
144                 Interop.Elementary.elm_spinner_interval_set(RealHandle, value);
145             }
146         }
147
148         /// <summary>
149         /// Sets or gets the base for rounding.
150         /// </summary>
151         public double RoundBase
152         {
153             get
154             {
155                 return Interop.Elementary.elm_spinner_base_get(RealHandle);
156             }
157             set
158             {
159                 Interop.Elementary.elm_spinner_base_set(RealHandle, value);
160             }
161         }
162
163         /// <summary>
164         /// Sets or gets the round value for rounding.
165         /// </summary>
166         public int RoundValue
167         {
168             get
169             {
170                 return Interop.Elementary.elm_spinner_round_get(RealHandle);
171             }
172             set
173             {
174                 Interop.Elementary.elm_spinner_round_set(RealHandle, value);
175             }
176         }
177
178         /// <summary>
179         /// Sets or gets the wrap of a given spinner widget.
180         /// </summary>
181         /// <remarks>
182         /// If wrap is disabled, when the user tries to increment the value, but displayed value plus step value is bigger than maximum value, the new value will be the maximum value.
183         /// If wrap is enabled, when the user tries to increment the value, but displayed value plus step value is bigger than maximum value, the new value will be the minimum value.
184         /// By default it's disabled.
185         /// </remarks>
186         public bool IsWrapEnabled
187         {
188             get
189             {
190                 return Interop.Elementary.elm_spinner_wrap_get(RealHandle);
191             }
192             set
193             {
194                 Interop.Elementary.elm_spinner_wrap_set(RealHandle, value);
195             }
196         }
197
198         /// <summary>
199         /// Sets or gets whether the spinner can be directly edited by the user or not.
200         /// </summary>
201         /// <remarks>By default it is enabled</remarks>
202         public bool IsEditable
203         {
204             get
205             {
206                 return Interop.Elementary.elm_spinner_editable_get(RealHandle);
207             }
208             set
209             {
210                 Interop.Elementary.elm_spinner_editable_set(RealHandle, value);
211             }
212         }
213
214         /// <summary>
215         /// Set a special string to display in the place of the numerical value.
216         /// </summary>
217         /// <param name="value">The numerical value to be replaced</param>
218         /// <param name="label">The label to be used</param>
219         public void AddSpecialValue(double value, string label)
220         {
221             Interop.Elementary.elm_spinner_special_value_add(RealHandle, value, label);
222         }
223
224         /// <summary>
225         /// Remove a previously added special value, After this, the spinner will display the value itself instead of a label.
226         /// </summary>
227         /// <param name="value">The replaced numerical value</param>
228         public void RemoveSpecialValue(double value)
229         {
230             Interop.Elementary.elm_spinner_special_value_del(RealHandle, value);
231         }
232
233         /// <summary>
234         /// Get the special string display in the place of the numerical value.
235         /// </summary>
236         /// <param name="value">The replaced numerical value.</param>
237         /// <returns>The value of the spinner which replaced numerical value with special string</returns>
238         public string GetSpecialValue(double value)
239         {
240             return Interop.Elementary.elm_spinner_special_value_get(RealHandle, value);
241         }
242
243         protected override IntPtr CreateHandle(EvasObject parent)
244         {
245             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
246             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
247
248             RealHandle = Interop.Elementary.elm_spinner_add(handle);
249             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
250
251             return handle;
252         }
253     }
254 }