[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Slider.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     /// Enumeration for the Slider's indicator visiblity mode.
23     /// </summary>
24     /// <since_tizen> preview </since_tizen>
25     public enum SliderIndicatorVisibleMode
26     {
27         /// <summary>
28         /// Shows the indicator on mouse down or change in the slider value.
29         /// </summary>
30         Default,
31
32         /// <summary>
33         /// Always show the indicator.
34         /// </summary>
35         Always,
36
37         /// <summary>
38         /// Show the indicator on focus.
39         /// </summary>
40         OnFocus,
41
42         /// <summary>
43         /// Never show the indicator.
44         /// </summary>
45         None,
46     }
47
48     /// <summary>
49     /// The Slider is a widget that adds a draggable slider widget for selecting the value of something within a range.
50     /// </summary>
51     /// <since_tizen> preview </since_tizen>
52     public class Slider : Layout
53     {
54         double _minimum = 0.0;
55         double _maximum = 1.0;
56
57         SmartEvent _changed;
58         SmartEvent _delayedChanged;
59         SmartEvent _dragStarted;
60         SmartEvent _dragStopped;
61
62         /// <summary>
63         /// Creates and initializes a new instance of the Slider class.
64         /// </summary>
65         /// <param name="parent">The <see cref="EvasObject"/> to which the new slider will be attached as a child.</param>
66         /// <since_tizen> preview </since_tizen>
67         public Slider(EvasObject parent) : base(parent)
68         {
69             _changed = new SmartEvent(this, this.RealHandle, "changed");
70             _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
71
72             _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
73             _delayedChanged.On += (s, e) => DelayedValueChanged?.Invoke(this, EventArgs.Empty);
74
75             _dragStarted = new SmartEvent(this, this.RealHandle, "slider,drag,start");
76             _dragStarted.On += (s, e) => DragStarted?.Invoke(this, EventArgs.Empty);
77
78             _dragStopped = new SmartEvent(this, this.RealHandle, "slider,drag,stop");
79             _dragStopped.On += (s, e) => DragStopped?.Invoke(this, EventArgs.Empty);
80         }
81
82         /// <summary>
83         /// ValueChanged will be triggered when the Slider value is changed by the user.
84         /// </summary>
85         /// <since_tizen> preview </since_tizen>
86         public event EventHandler ValueChanged;
87
88         /// <summary>
89         /// DelayedValueChanged will be triggered when a short time after the value is changed by the user.
90         /// This will be called only when the user stops dragging for a very short period or when they release their finger/mouse,
91         /// so it avoids possibly expensive reactions to the value change.
92         /// </summary>
93         /// <since_tizen> preview </since_tizen>
94         public event EventHandler DelayedValueChanged;
95
96         /// <summary>
97         /// DragStarted will be triggered when dragging the Slider indicator around has started.
98         /// </summary>
99         /// <since_tizen> preview </since_tizen>
100         public event EventHandler DragStarted;
101
102         /// <summary>
103         /// DragStopped will be triggered when dragging the Slider indicator around has stopped.
104         /// </summary>
105         /// <since_tizen> preview </since_tizen>
106         public event EventHandler DragStopped;
107
108         /// <summary>
109         /// Sets or gets the (exact) length of the bar region of a given Slider widget.
110         /// </summary>
111         /// <remarks>
112         /// This sets the minimum width (when in the horizontal mode) or height (when in the vertical mode)
113         /// of the actual bar area of the slider object. This in turn affects the object's minimum size.
114         /// Use this when you're not setting other size hints expanding on the given direction
115         /// (like weight and alignment hints), and you would like it to have a specific size.
116         /// </remarks>
117         /// <since_tizen> preview </since_tizen>
118         public int SpanSize
119         {
120             get
121             {
122                 return Interop.Elementary.elm_slider_span_size_get(RealHandle);
123             }
124             set
125             {
126                 Interop.Elementary.elm_slider_span_size_set(RealHandle, value);
127             }
128         }
129
130         /// <summary>
131         /// Sets or gets the format string for the indicator label.
132         /// </summary>
133         /// <remarks>
134         /// The slider may display its value somewhere other than the unit label,
135         /// for example, above the slider knob that is dragged around. This function sets the format string
136         /// used for this. If null, the indicator label won't be visible. If not, it sets the format string
137         /// for the label text. For the label text floating point value is provided, so the label text can
138         /// display up to 1 floating point value. Note that this is optional. Use a format string
139         /// such as "%1.2f meters" for example, and it displays values like: "3.14 meters" for a value
140         /// equal to 3.14159. By default, the indicator label is disabled.
141         /// </remarks>
142         /// <since_tizen> preview </since_tizen>
143         public string IndicatorFormat
144         {
145             get
146             {
147                 return Interop.Elementary.elm_slider_indicator_format_get(RealHandle);
148             }
149             set
150             {
151                 Interop.Elementary.elm_slider_indicator_format_set(RealHandle, value);
152             }
153         }
154
155         /// <summary>
156         /// Sets or gets the orientation of a given slider widget.
157         /// </summary>
158         /// <remarks>
159         /// The orientation may be vertical or horizontal. By default, it's displayed horizontally.
160         /// </remarks>
161         /// <since_tizen> preview </since_tizen>
162         public bool IsHorizontal
163         {
164             get
165             {
166                 return Interop.Elementary.elm_slider_horizontal_get(RealHandle);
167             }
168             set
169             {
170                 Interop.Elementary.elm_slider_horizontal_set(RealHandle, value);
171             }
172         }
173
174         /// <summary>
175         /// Sets or gets the minimum values for the slider.
176         /// </summary>
177         /// <remarks>
178         /// This defines the allowed minimum values to be selected by the user.
179         /// If the actual value is less than min, it is updated to min.
180         /// Actual value can be obtained with value. By default, the minimum is equal to 0.0.
181         /// </remarks>
182         /// <since_tizen> preview </since_tizen>
183         public double Minimum
184         {
185             get
186             {
187                 return _minimum;
188             }
189             set
190             {
191                 _minimum = value;
192                 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
193             }
194         }
195
196         /// <summary>
197         /// Sets or gets the maximum values for the slider.
198         /// </summary>
199         /// <remarks>
200         /// This defines the allowed maximum values to be selected by the user.
201         /// If the actual value is bigger then max, it is updated to max.
202         /// Actual value can be obtained with value. By default, minimum is equal to 0.0 and maximum is equal to 1.0.
203         /// Maximum must be greater than minimum, otherwise the behavior is undefined.
204         /// </remarks>
205         /// <since_tizen> preview </since_tizen>
206         public double Maximum
207         {
208             get
209             {
210                 return _maximum;
211             }
212             set
213             {
214                 _maximum = value;
215                 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
216             }
217         }
218
219         /// <summary>
220         /// Gets or sets the value displayed by the slider.
221         /// </summary>
222         /// <remarks>
223         /// Value will be presented on the unit label following format specified with UnitFormat and
224         /// on indicator with IndicatorFormat. The value must be between minimum and maximum values.
225         /// </remarks>
226         /// <since_tizen> preview </since_tizen>
227         public double Value
228         {
229             get
230             {
231                 return Interop.Elementary.elm_slider_value_get(RealHandle);
232             }
233             set
234             {
235                 Interop.Elementary.elm_slider_value_set(RealHandle, value);
236             }
237         }
238
239         /// <summary>
240         /// Sets or gets the step by which the slider indicator moves.
241         /// </summary>
242         /// <remarks>
243         /// This value is used when the draggable object is moved automatically i.e.,
244         /// in case of a key event when up/down/left/right key is pressed or in case accessibility
245         /// is set and the flick event is used to increase or decrease the slider values.
246         /// By default, the step value is equal to 0.05.
247         /// </remarks>
248         /// <since_tizen> preview </since_tizen>
249         public double Step
250         {
251             get
252             {
253                 return Interop.Elementary.elm_slider_step_get(RealHandle);
254             }
255             set
256             {
257                 Interop.Elementary.elm_slider_step_set(RealHandle, value);
258             }
259         }
260
261         /// <summary>
262         /// Gets or sets whether a given slider widget's displaying values are inverted.
263         /// </summary>
264         /// <remarks>
265         /// A slider may be inverted, in which case it gets its values inverted,
266         /// with high values being on the left or top, and low values on the right or bottom,
267         /// as opposed to normally have the low values on the former and high values on the latter,
268         /// respectively, for the horizontal and vertical modes.
269         /// </remarks>
270         /// <since_tizen> preview </since_tizen>
271         public bool IsInverted
272         {
273             get
274             {
275                 return Interop.Elementary.elm_slider_inverted_get(RealHandle);
276             }
277             set
278             {
279                 Interop.Elementary.elm_slider_inverted_set(RealHandle, value);
280             }
281         }
282
283         /// <summary>
284         /// Sets or gets whether to enlarge the slider indicator (augmented knob).
285         /// </summary>
286         /// <remarks>
287         /// By default, the indicator is bigger when dragged by the user.
288         /// It won't display the values set with IndicatorFormat if you disable the indicator.
289         /// </remarks>
290         /// <since_tizen> preview </since_tizen>
291         public bool IsIndicatorVisible
292         {
293             get
294             {
295                 return Interop.Elementary.elm_slider_indicator_show_get(RealHandle);
296             }
297             set
298             {
299                 Interop.Elementary.elm_slider_indicator_show_set(RealHandle, value);
300             }
301         }
302
303         /// <summary>
304         /// Sets or gets the visible mode of the slider indicator.
305         /// </summary>
306         /// <since_tizen> preview </since_tizen>
307         public SliderIndicatorVisibleMode IndicatorVisibleMode
308         {
309             get
310             {
311                 return (SliderIndicatorVisibleMode)Interop.Elementary.elm_slider_indicator_visible_mode_get(RealHandle);
312             }
313             set
314             {
315                 Interop.Elementary.elm_slider_indicator_visible_mode_set(RealHandle, (int)value);
316             }
317         }
318
319         /// <summary>
320         /// Sets or gets whether to show the indicator of a slider on focus.
321         /// </summary>
322         /// <since_tizen> preview </since_tizen>
323         public bool IsIndicatorFocusable
324         {
325             get
326             {
327                 return Interop.Elementary.elm_slider_indicator_show_on_focus_get(RealHandle);
328             }
329             set
330             {
331                 Interop.Elementary.elm_slider_indicator_show_on_focus_set(RealHandle, value);
332             }
333         }
334
335         /// <summary>
336         /// Creates a widget handle.
337         /// </summary>
338         /// <param name="parent">Parent EvasObject.</param>
339         /// <returns>Handle IntPtr.</returns>
340         /// <since_tizen> preview </since_tizen>
341         protected override IntPtr CreateHandle(EvasObject parent)
342         {
343             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
344             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
345
346             RealHandle = Interop.Elementary.elm_slider_add(handle);
347             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
348
349             return handle;
350         }
351     }
352 }