2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 /// Enumeration for the Slider's indicator visiblity mode.
24 /// <since_tizen> preview </since_tizen>
25 public enum SliderIndicatorVisibleMode
28 /// Shows the indicator on mouse down or change in the slider value.
33 /// Always show the indicator.
38 /// Show the indicator on focus.
43 /// Never show the indicator.
49 /// The Slider is a widget that adds a draggable slider widget for selecting the value of something within a range.
51 /// <since_tizen> preview </since_tizen>
52 public class Slider : Layout
54 double _minimum = 0.0;
55 double _maximum = 1.0;
58 SmartEvent _delayedChanged;
59 SmartEvent _dragStarted;
60 SmartEvent _dragStopped;
63 /// Creates and initializes a new instance of the Slider class.
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)
69 _changed = new SmartEvent(this, this.RealHandle, "changed");
70 _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
72 _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
73 _delayedChanged.On += (s, e) => DelayedValueChanged?.Invoke(this, EventArgs.Empty);
75 _dragStarted = new SmartEvent(this, this.RealHandle, "slider,drag,start");
76 _dragStarted.On += (s, e) => DragStarted?.Invoke(this, EventArgs.Empty);
78 _dragStopped = new SmartEvent(this, this.RealHandle, "slider,drag,stop");
79 _dragStopped.On += (s, e) => DragStopped?.Invoke(this, EventArgs.Empty);
83 /// ValueChanged will be triggered when the Slider value is changed by the user.
85 /// <since_tizen> preview </since_tizen>
86 public event EventHandler ValueChanged;
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.
93 /// <since_tizen> preview </since_tizen>
94 public event EventHandler DelayedValueChanged;
97 /// DragStarted will be triggered when dragging the Slider indicator around has started.
99 /// <since_tizen> preview </since_tizen>
100 public event EventHandler DragStarted;
103 /// DragStopped will be triggered when dragging the Slider indicator around has stopped.
105 /// <since_tizen> preview </since_tizen>
106 public event EventHandler DragStopped;
109 /// Sets or gets the (exact) length of the bar region of a given Slider widget.
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.
117 /// <since_tizen> preview </since_tizen>
122 return Interop.Elementary.elm_slider_span_size_get(RealHandle);
126 Interop.Elementary.elm_slider_span_size_set(RealHandle, value);
131 /// Sets or gets the format string for the indicator label.
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.
142 /// <since_tizen> preview </since_tizen>
143 public string IndicatorFormat
147 return Interop.Elementary.elm_slider_indicator_format_get(RealHandle);
151 Interop.Elementary.elm_slider_indicator_format_set(RealHandle, value);
156 /// Sets or gets the orientation of a given slider widget.
159 /// The orientation may be vertical or horizontal. By default, it's displayed horizontally.
161 /// <since_tizen> preview </since_tizen>
162 public bool IsHorizontal
166 return Interop.Elementary.elm_slider_horizontal_get(RealHandle);
170 Interop.Elementary.elm_slider_horizontal_set(RealHandle, value);
175 /// Sets or gets the minimum values for the slider.
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.
182 /// <since_tizen> preview </since_tizen>
183 public double Minimum
192 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
197 /// Sets or gets the maximum values for the slider.
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.
205 /// <since_tizen> preview </since_tizen>
206 public double Maximum
215 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
220 /// Gets or sets the value displayed by the slider.
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.
226 /// <since_tizen> preview </since_tizen>
231 return Interop.Elementary.elm_slider_value_get(RealHandle);
235 Interop.Elementary.elm_slider_value_set(RealHandle, value);
240 /// Sets or gets the step by which the slider indicator moves.
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.
248 /// <since_tizen> preview </since_tizen>
253 return Interop.Elementary.elm_slider_step_get(RealHandle);
257 Interop.Elementary.elm_slider_step_set(RealHandle, value);
262 /// Gets or sets whether a given slider widget's displaying values are inverted.
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.
270 /// <since_tizen> preview </since_tizen>
271 public bool IsInverted
275 return Interop.Elementary.elm_slider_inverted_get(RealHandle);
279 Interop.Elementary.elm_slider_inverted_set(RealHandle, value);
284 /// Sets or gets whether to enlarge the slider indicator (augmented knob).
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.
290 /// <since_tizen> preview </since_tizen>
291 public bool IsIndicatorVisible
295 return Interop.Elementary.elm_slider_indicator_show_get(RealHandle);
299 Interop.Elementary.elm_slider_indicator_show_set(RealHandle, value);
304 /// Sets or gets the visible mode of the slider indicator.
306 /// <since_tizen> preview </since_tizen>
307 public SliderIndicatorVisibleMode IndicatorVisibleMode
311 return (SliderIndicatorVisibleMode)Interop.Elementary.elm_slider_indicator_visible_mode_get(RealHandle);
315 Interop.Elementary.elm_slider_indicator_visible_mode_set(RealHandle, (int)value);
320 /// Sets or gets whether to show the indicator of a slider on focus.
322 /// <since_tizen> preview </since_tizen>
323 public bool IsIndicatorFocusable
327 return Interop.Elementary.elm_slider_indicator_show_on_focus_get(RealHandle);
331 Interop.Elementary.elm_slider_indicator_show_on_focus_set(RealHandle, value);
336 /// Creates a widget handle.
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)
343 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
344 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
346 RealHandle = Interop.Elementary.elm_slider_add(handle);
347 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);