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