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 Spinner is a widget that increase or decrease numeric values using arrow buttons, or edit values directly.
23 /// Inherits <see cref="Layout"/>.
25 public class Spinner : Layout
27 double _minimum = 0.0;
28 double _maximum = 100.0;
31 SmartEvent _delayedChanged;
34 /// Creates and initializes a new instance of the Spinner class.
36 /// <param name="parent">The parent of new Spinner instance</param>
37 public Spinner(EvasObject parent) : base(parent)
39 _changed = new SmartEvent(this, this.RealHandle, "changed");
40 _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
42 _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
43 _delayedChanged.On += (s, e) => DelayedValueChanged?.Invoke(this, EventArgs.Empty);
47 /// ValueChanged will be triggered whenever the spinner value is changed.
49 public event EventHandler ValueChanged;
52 /// DelayedValueChanged will be triggered after a short time when the value is changed.
54 public event EventHandler DelayedValueChanged;
57 /// Sets or gets the label format of the spinner.
59 public string LabelFormat
63 return Interop.Elementary.elm_spinner_label_format_get(RealHandle);
67 Interop.Elementary.elm_spinner_label_format_set(RealHandle, value);
72 /// Sets or gets the minimum value for the spinner.
83 Interop.Elementary.elm_spinner_min_max_set(RealHandle, _minimum, _maximum);
88 /// Sets or gets the maximum value for the spinner.
99 Interop.Elementary.elm_spinner_min_max_set(RealHandle, _minimum, _maximum);
104 /// Sets or gets the step that used to increment or decrement the spinner value.
110 return Interop.Elementary.elm_spinner_step_get(RealHandle);
114 Interop.Elementary.elm_spinner_step_set(RealHandle, value);
119 /// Sets or gets the value displayed by the spinner.
125 return Interop.Elementary.elm_spinner_value_get(RealHandle);
129 Interop.Elementary.elm_spinner_value_set(RealHandle, value);
134 /// Sets or gets the interval on time updates for an user mouse button hold on spinner widgets' arrows.
136 public double Interval
140 return Interop.Elementary.elm_spinner_interval_get(RealHandle);
144 Interop.Elementary.elm_spinner_interval_set(RealHandle, value);
149 /// Sets or gets the base for rounding.
151 public double RoundBase
155 return Interop.Elementary.elm_spinner_base_get(RealHandle);
159 Interop.Elementary.elm_spinner_base_set(RealHandle, value);
164 /// Sets or gets the round value for rounding.
166 public int RoundValue
170 return Interop.Elementary.elm_spinner_round_get(RealHandle);
174 Interop.Elementary.elm_spinner_round_set(RealHandle, value);
179 /// Sets or gets the wrap of a given spinner widget.
182 /// If wrap is disabled, when the user tries to increment the value, but displayed value plus step value is bigger than maximum value, the new value will be the maximum value.
183 /// If wrap is enabled, when the user tries to increment the value, but displayed value plus step value is bigger than maximum value, the new value will be the minimum value.
184 /// By default it's disabled.
186 public bool IsWrapEnabled
190 return Interop.Elementary.elm_spinner_wrap_get(RealHandle);
194 Interop.Elementary.elm_spinner_wrap_set(RealHandle, value);
199 /// Sets or gets whether the spinner can be directly edited by the user or not.
201 /// <remarks>By default it is enabled</remarks>
202 public bool IsEditable
206 return Interop.Elementary.elm_spinner_editable_get(RealHandle);
210 Interop.Elementary.elm_spinner_editable_set(RealHandle, value);
215 /// Set a special string to display in the place of the numerical value.
217 /// <param name="value">The numerical value to be replaced</param>
218 /// <param name="label">The label to be used</param>
219 public void AddSpecialValue(double value, string label)
221 Interop.Elementary.elm_spinner_special_value_add(RealHandle, value, label);
225 /// Remove a previously added special value, After this, the spinner will display the value itself instead of a label.
227 /// <param name="value">The replaced numerical value</param>
228 public void RemoveSpecialValue(double value)
230 Interop.Elementary.elm_spinner_special_value_del(RealHandle, value);
234 /// Get the special string display in the place of the numerical value.
236 /// <param name="value">The replaced numerical value.</param>
237 /// <returns>The value of the spinner which replaced numerical value with special string</returns>
238 public string GetSpecialValue(double value)
240 return Interop.Elementary.elm_spinner_special_value_get(RealHandle, value);
244 /// Creates a widget handle.
246 /// <param name="parent">Parent EvasObject</param>
247 /// <returns>Handle IntPtr</returns>
248 protected override IntPtr CreateHandle(EvasObject parent)
250 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
251 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
253 RealHandle = Interop.Elementary.elm_spinner_add(handle);
254 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);