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