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