/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace ElmSharp { /// /// The Spinner is a widget that increase or decrease numeric values using arrow buttons, or edit values directly. /// Inherits . /// public class Spinner : Layout { double _minimum = 0.0; double _maximum = 100.0; SmartEvent _changed; SmartEvent _delayedChanged; /// /// Creates and initializes a new instance of the Spinner class. /// /// The parent of new Spinner instance public Spinner(EvasObject parent) : base(parent) { } /// /// Creates and initializes a new instance of Layout class. /// protected Spinner() : base() { } /// /// ValueChanged will be triggered whenever the spinner value is changed. /// public event EventHandler ValueChanged; /// /// DelayedValueChanged will be triggered after a short time when the value is changed. /// public event EventHandler DelayedValueChanged; /// /// Sets or gets the label format of the spinner. /// public string LabelFormat { get { return Interop.Elementary.elm_spinner_label_format_get(RealHandle); } set { Interop.Elementary.elm_spinner_label_format_set(RealHandle, value); } } /// /// Sets or gets the minimum value for the spinner. /// public double Minimum { get { return _minimum; } set { _minimum = value; Interop.Elementary.elm_spinner_min_max_set(RealHandle, _minimum, _maximum); } } /// /// Sets or gets the maximum value for the spinner. /// public double Maximum { get { return _maximum; } set { _maximum = value; Interop.Elementary.elm_spinner_min_max_set(RealHandle, _minimum, _maximum); } } /// /// Sets or gets the step that used to increment or decrement the spinner value. /// public double Step { get { return Interop.Elementary.elm_spinner_step_get(RealHandle); } set { Interop.Elementary.elm_spinner_step_set(RealHandle, value); } } /// /// Sets or gets the value displayed by the spinner. /// public double Value { get { return Interop.Elementary.elm_spinner_value_get(RealHandle); } set { Interop.Elementary.elm_spinner_value_set(RealHandle, value); } } /// /// Sets or gets the interval on time updates for an user mouse button hold on spinner widgets' arrows. /// public double Interval { get { return Interop.Elementary.elm_spinner_interval_get(RealHandle); } set { Interop.Elementary.elm_spinner_interval_set(RealHandle, value); } } /// /// Sets or gets the base for rounding. /// public double RoundBase { get { return Interop.Elementary.elm_spinner_base_get(RealHandle); } set { Interop.Elementary.elm_spinner_base_set(RealHandle, value); } } /// /// Sets or gets the round value for rounding. /// public int RoundValue { get { return Interop.Elementary.elm_spinner_round_get(RealHandle); } set { Interop.Elementary.elm_spinner_round_set(RealHandle, value); } } /// /// Sets or gets the wrap of a given spinner widget. /// /// /// 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. /// 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. /// By default it's disabled. /// public bool IsWrapEnabled { get { return Interop.Elementary.elm_spinner_wrap_get(RealHandle); } set { Interop.Elementary.elm_spinner_wrap_set(RealHandle, value); } } /// /// Sets or gets whether the spinner can be directly edited by the user or not. /// /// By default it is enabled public bool IsEditable { get { return Interop.Elementary.elm_spinner_editable_get(RealHandle); } set { Interop.Elementary.elm_spinner_editable_set(RealHandle, value); } } /// /// Set a special string to display in the place of the numerical value. /// /// The numerical value to be replaced /// The label to be used public void AddSpecialValue(double value, string label) { Interop.Elementary.elm_spinner_special_value_add(RealHandle, value, label); } /// /// Remove a previously added special value, After this, the spinner will display the value itself instead of a label. /// /// The replaced numerical value public void RemoveSpecialValue(double value) { Interop.Elementary.elm_spinner_special_value_del(RealHandle, value); } /// /// Get the special string display in the place of the numerical value. /// /// The replaced numerical value. /// The value of the spinner which replaced numerical value with special string public string GetSpecialValue(double value) { return Interop.Elementary.elm_spinner_special_value_get(RealHandle, value); } /// /// The callback of Realized Event /// protected override void OnRealized() { base.OnRealized(); _changed = new SmartEvent(this, this.RealHandle, "changed"); _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty); _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed"); _delayedChanged.On += (s, e) => DelayedValueChanged?.Invoke(this, EventArgs.Empty); } /// /// Creates a widget handle. /// /// Parent EvasObject /// Handle IntPtr protected override IntPtr CreateHandle(EvasObject parent) { IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle); Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default"); RealHandle = Interop.Elementary.elm_spinner_add(handle); Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle); return handle; } } }