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 public enum SliderIndicatorVisibleMode
27 /// Show indicator on mouse down or change in slider value.
32 /// Always show the indicator.
37 /// Show the indicator on focus.
42 /// Never show the indicator.
48 /// The Slider is a widget that adds a draggable slider widget for selecting the value of something within a range.
50 public class Slider : Layout
52 double _minimum = 0.0;
53 double _maximum = 1.0;
56 SmartEvent _delayedChanged;
57 SmartEvent _dragStarted;
58 SmartEvent _dragStopped;
61 /// Creates and initializes a new instance of the Slider class.
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)
66 _changed = new SmartEvent(this, this.RealHandle, "changed");
67 _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
69 _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
70 _delayedChanged.On += (s, e) => DelayedValueChanged?.Invoke(this, EventArgs.Empty);
72 _dragStarted = new SmartEvent(this, this.RealHandle, "slider,drag,start");
73 _dragStarted.On += (s, e) => DragStarted?.Invoke(this, EventArgs.Empty);
75 _dragStopped = new SmartEvent(this, this.RealHandle, "slider,drag,stop");
76 _dragStopped.On += (s, e) => DragStopped?.Invoke(this, EventArgs.Empty);
80 /// ValueChanged will be triggered when the Slider value is changed by the user.
82 public event EventHandler ValueChanged;
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.
89 public event EventHandler DelayedValueChanged;
92 /// DragStarted will be triggered when dragging the Slider indicator around has started.
94 public event EventHandler DragStarted;
97 /// DragStopped will be triggered when dragging the Slider indicator around has stopped.
99 public event EventHandler DragStopped;
102 /// Sets or gets the (exact) length of the bar region of a given Slider widget.
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.
114 return Interop.Elementary.elm_slider_span_size_get(RealHandle);
118 Interop.Elementary.elm_slider_span_size_set(RealHandle, value);
123 /// Sets or gets the format string for the indicator label.
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.
134 public string IndicatorFormat
138 return Interop.Elementary.elm_slider_indicator_format_get(RealHandle);
142 Interop.Elementary.elm_slider_indicator_format_set(RealHandle, value);
147 /// Sets or gets the orientation of a given slider widget.
150 /// The orientation may be vertically or horizontally.By default, it's displayed horizontally.
152 public bool IsHorizontal
156 return Interop.Elementary.elm_slider_horizontal_get(RealHandle);
160 Interop.Elementary.elm_slider_horizontal_set(RealHandle, value);
165 /// Sets or gets the minimum values for the slider.
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.
172 public double Minimum
181 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
186 /// Sets or gets the maximum values for the slider.
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.
194 public double Maximum
203 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
208 /// Gets or sets the value displayed by the slider.
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.
218 return Interop.Elementary.elm_slider_value_get(RealHandle);
222 Interop.Elementary.elm_slider_value_set(RealHandle, value);
227 /// Sets or gets the step by which the slider indicator moves.
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.
239 return Interop.Elementary.elm_slider_step_get(RealHandle);
243 Interop.Elementary.elm_slider_step_set(RealHandle, value);
248 /// Gets or sets whether a given slider widget's displaying values are inverted.
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.
256 public bool IsInverted
260 return Interop.Elementary.elm_slider_inverted_get(RealHandle);
264 Interop.Elementary.elm_slider_inverted_set(RealHandle, value);
269 /// Sets or gets whether to enlarge the slider indicator (augmented knob).
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.
275 public bool IsIndicatorVisible
279 return Interop.Elementary.elm_slider_indicator_show_get(RealHandle);
283 Interop.Elementary.elm_slider_indicator_show_set(RealHandle, value);
288 /// Sets or gets the visible mode of slider indicator.
290 public SliderIndicatorVisibleMode IndicatorVisibleMode
294 return (SliderIndicatorVisibleMode)Interop.Elementary.elm_slider_indicator_visible_mode_get(RealHandle);
298 Interop.Elementary.elm_slider_indicator_visible_mode_set(RealHandle, (int)value);
303 /// Sets or gets whether to Show the indicator of slider on focus.
305 public bool IsIndicatorFocusable
309 return Interop.Elementary.elm_slider_indicator_show_on_focus_get(RealHandle);
313 Interop.Elementary.elm_slider_indicator_show_on_focus_set(RealHandle, value);
318 /// Creates a widget handle.
320 /// <param name="parent">Parent EvasObject</param>
321 /// <returns>Handle IntPtr</returns>
322 protected override IntPtr CreateHandle(EvasObject parent)
324 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
325 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
327 RealHandle = Interop.Elementary.elm_slider_add(handle);
328 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);