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 /// The Slider is a widget that adds a draggable slider widget for selecting the value of something within a range.
24 public class Slider : Layout
26 double _minimum = 0.0;
27 double _maximum = 1.0;
30 SmartEvent _delayedChanged;
31 SmartEvent _dragStarted;
32 SmartEvent _dragStopped;
35 /// Creates and initializes a new instance of the Slider class.
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)
40 _changed = new SmartEvent(this, this.RealHandle, "changed");
41 _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
43 _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
44 _delayedChanged.On += (s, e) => DelayedValueChanged?.Invoke(this, EventArgs.Empty);
46 _dragStarted = new SmartEvent(this, this.RealHandle, "slider,drag,start");
47 _dragStarted.On += (s, e) => DragStarted?.Invoke(this, EventArgs.Empty);
49 _dragStopped = new SmartEvent(this, this.RealHandle, "slider,drag,stop");
50 _dragStopped.On += (s, e) => DragStopped?.Invoke(this, EventArgs.Empty);
54 /// ValueChanged will be triggered when the Slider value is changed by the user.
56 public event EventHandler ValueChanged;
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.
63 public event EventHandler DelayedValueChanged;
66 /// DragStarted will be triggered when dragging the Slider indicator around has started.
68 public event EventHandler DragStarted;
71 /// DragStopped will be triggered when dragging the Slider indicator around has stopped.
73 public event EventHandler DragStopped;
76 /// Sets or gets the (exact) length of the bar region of a given Slider widget.
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.
88 return Interop.Elementary.elm_slider_span_size_get(RealHandle);
92 Interop.Elementary.elm_slider_span_size_set(RealHandle, value);
97 /// Sets or gets the format string for the unit label.
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.
108 public string UnitFormat
112 return Interop.Elementary.elm_slider_unit_format_get(RealHandle);
116 Interop.Elementary.elm_slider_unit_format_set(RealHandle, value);
121 /// Sets or gets the format string for the indicator label.
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.
132 public string IndicatorFormat
136 return Interop.Elementary.elm_slider_indicator_format_get(RealHandle);
140 Interop.Elementary.elm_slider_indicator_format_set(RealHandle, value);
145 /// Sets or gets the orientation of a given slider widget.
148 /// The orientation may be vertically or horizontally.By default, it's displayed horizontally.
150 public bool IsHorizontal
154 return Interop.Elementary.elm_slider_horizontal_get(RealHandle);
158 Interop.Elementary.elm_slider_horizontal_set(RealHandle, value);
163 /// Sets or gets the minimum values for the slider.
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.
170 public double Minimum
179 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
184 /// Sets or gets the maximum values for the slider.
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.
192 public double Maximum
201 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
206 /// Gets or sets the value displayed by the slider.
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.
216 return Interop.Elementary.elm_slider_value_get(RealHandle);
220 Interop.Elementary.elm_slider_value_set(RealHandle, value);
225 /// Sets or gets the step by which the slider indicator moves.
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.
237 return Interop.Elementary.elm_slider_step_get(RealHandle);
241 Interop.Elementary.elm_slider_step_set(RealHandle, value);
246 /// Gets or sets whether a given slider widget's displaying values are inverted.
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.
254 public bool IsInverted
258 return Interop.Elementary.elm_slider_inverted_get(RealHandle);
262 Interop.Elementary.elm_slider_inverted_set(RealHandle, value);
267 /// Sets or gets whether to enlarge the slider indicator (augmented knob).
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.
273 public bool IsIndicatorVisible
277 return Interop.Elementary.elm_slider_indicator_show_get(RealHandle);
281 Interop.Elementary.elm_slider_indicator_show_set(RealHandle, value);
286 /// Sets or gets whether to Show the indicator of slider on focus.
288 public bool IsIndicatorFocusable
292 return Interop.Elementary.elm_slider_indicator_show_on_focus_get(RealHandle);
296 Interop.Elementary.elm_slider_indicator_show_on_focus_set(RealHandle, value);
300 protected override IntPtr CreateHandle(EvasObject parent)
302 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
303 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
305 RealHandle = Interop.Elementary.elm_slider_add(handle);
306 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);