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.
21 public enum SliderIndicatorVisibleMode
24 /// show indicator on mouse down or change in slider value.
29 /// Always show the indicator.
34 /// Show the indicator on focus.
39 /// Never show the indicator.
45 /// The Slider is a widget that adds a draggable slider widget for selecting the value of something within a range.
47 public class Slider : Layout
49 double _minimum = 0.0;
50 double _maximum = 1.0;
53 SmartEvent _delayedChanged;
54 SmartEvent _dragStarted;
55 SmartEvent _dragStopped;
58 /// Creates and initializes a new instance of the Slider class.
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)
63 _changed = new SmartEvent(this, this.RealHandle, "changed");
64 _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
66 _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
67 _delayedChanged.On += (s, e) => DelayedValueChanged?.Invoke(this, EventArgs.Empty);
69 _dragStarted = new SmartEvent(this, this.RealHandle, "slider,drag,start");
70 _dragStarted.On += (s, e) => DragStarted?.Invoke(this, EventArgs.Empty);
72 _dragStopped = new SmartEvent(this, this.RealHandle, "slider,drag,stop");
73 _dragStopped.On += (s, e) => DragStopped?.Invoke(this, EventArgs.Empty);
77 /// ValueChanged will be triggered when the Slider value is changed by the user.
79 public event EventHandler ValueChanged;
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.
86 public event EventHandler DelayedValueChanged;
89 /// DragStarted will be triggered when dragging the Slider indicator around has started.
91 public event EventHandler DragStarted;
94 /// DragStopped will be triggered when dragging the Slider indicator around has stopped.
96 public event EventHandler DragStopped;
99 /// Sets or gets the (exact) length of the bar region of a given Slider widget.
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.
111 return Interop.Elementary.elm_slider_span_size_get(RealHandle);
115 Interop.Elementary.elm_slider_span_size_set(RealHandle, value);
120 /// Sets or gets the format string for the unit label.
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.
131 public string UnitFormat
135 return Interop.Elementary.elm_slider_unit_format_get(RealHandle);
139 Interop.Elementary.elm_slider_unit_format_set(RealHandle, value);
144 /// Sets or gets the format string for the indicator label.
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.
155 public string IndicatorFormat
159 return Interop.Elementary.elm_slider_indicator_format_get(RealHandle);
163 Interop.Elementary.elm_slider_indicator_format_set(RealHandle, value);
168 /// Sets or gets the orientation of a given slider widget.
171 /// The orientation may be vertically or horizontally.By default, it's displayed horizontally.
173 public bool IsHorizontal
177 return Interop.Elementary.elm_slider_horizontal_get(RealHandle);
181 Interop.Elementary.elm_slider_horizontal_set(RealHandle, value);
186 /// Sets or gets the minimum values for the slider.
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.
193 public double Minimum
202 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
207 /// Sets or gets the maximum values for the slider.
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.
215 public double Maximum
224 Interop.Elementary.elm_slider_min_max_set(RealHandle, _minimum, _maximum);
229 /// Gets or sets the value displayed by the slider.
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.
239 return Interop.Elementary.elm_slider_value_get(RealHandle);
243 Interop.Elementary.elm_slider_value_set(RealHandle, value);
248 /// Sets or gets the step by which the slider indicator moves.
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.
260 return Interop.Elementary.elm_slider_step_get(RealHandle);
264 Interop.Elementary.elm_slider_step_set(RealHandle, value);
269 /// Gets or sets whether a given slider widget's displaying values are inverted.
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.
277 public bool IsInverted
281 return Interop.Elementary.elm_slider_inverted_get(RealHandle);
285 Interop.Elementary.elm_slider_inverted_set(RealHandle, value);
290 /// Sets or gets whether to enlarge the slider indicator (augmented knob).
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.
296 public bool IsIndicatorVisible
300 return Interop.Elementary.elm_slider_indicator_show_get(RealHandle);
304 Interop.Elementary.elm_slider_indicator_show_set(RealHandle, value);
309 /// Sets or gets the visible mode of indicator.
311 public SliderIndicatorVisibleMode IndicatorVisibleMode
315 return (SliderIndicatorVisibleMode)Interop.Elementary.elm_slider_indicator_visible_mode_get(RealHandle);
319 Interop.Elementary.elm_slider_indicator_visible_mode_set(RealHandle, (Interop.Elementary.Elm_Slider_Indicator_Visible_Mode)value);
324 /// Sets or gets whether to Show the indicator of slider on focus.
326 public bool IsIndicatorFocusable
330 return Interop.Elementary.elm_slider_indicator_show_on_focus_get(RealHandle);
334 Interop.Elementary.elm_slider_indicator_show_on_focus_set(RealHandle, value);
338 protected override IntPtr CreateHandle(EvasObject parent)
340 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
341 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
343 RealHandle = Interop.Elementary.elm_slider_add(handle);
344 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);