/* * 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 increases or decreases the numeric values using arrow buttons, or edit values directly. /// Inherits . /// /// preview 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 /// preview public Spinner(EvasObject parent) : base(parent) { if (Elementary.GetProfile() == "tv") { Style = "vertical"; } } /// /// Creates and initializes a new instance of the Layout class. /// /// preview protected Spinner() : base() { } /// /// ValueChanged will be triggered whenever the spinner value is changed. /// /// preview public event EventHandler ValueChanged; /// /// DelayedValueChanged will be triggered after a short time when the value is changed. /// /// preview public event EventHandler DelayedValueChanged; /// /// Sets or gets the label format of the spinner. /// /// preview 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. /// /// preview 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. /// /// preview 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 is used to increment or decrement the spinner value. /// /// preview 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. /// /// preview 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 a user mouse button to hold on the spinner widgets' arrows. /// /// preview 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. /// /// preview 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. /// /// preview 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 the displayed value plus step value is bigger than the maximum value, then the new value will be the maximum value. /// If wrap is enabled when the user tries to increment the value, but the displayed value plus step value is bigger than the maximum value, then the new value will be the minimum value. /// By default, it's disabled. /// /// preview 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. /// preview public bool IsEditable { get { return Interop.Elementary.elm_spinner_editable_get(RealHandle); } set { Interop.Elementary.elm_spinner_editable_set(RealHandle, value); } } /// /// Sets a special string to display in the place of the numerical value. /// /// The numerical value to be replaced /// The label to be used /// preview public void AddSpecialValue(double value, string label) { Interop.Elementary.elm_spinner_special_value_add(RealHandle, value, label); } /// /// Removes a previously added special value. After this, the spinner will display the value itself instead of a label. /// /// The replaced numerical value. /// preview public void RemoveSpecialValue(double value) { Interop.Elementary.elm_spinner_special_value_del(RealHandle, value); } /// /// Gets the special string display in the place of the numerical value. /// /// The replaced numerical value. /// The value of the spinner, which replaced the numerical value with a special string. /// preview public string GetSpecialValue(double value) { return Interop.Elementary.elm_spinner_special_value_get(RealHandle, value); } /// /// The callback of the Realized event. /// /// preview 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. /// preview 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; } } }