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.
18 using System.Diagnostics;
20 namespace ElmSharp.Wearable
23 /// Circle slider is circular designed widget to select a value in a range by rotary event.
25 public class CircleSlider : Widget, IRotaryActionWidget
27 SmartEvent _changedEvent;
28 CircleSurface _surface;
31 /// Creates and initializes a new instance of the CircleSlider class.
33 /// <param name="parent">The EvasObject to which the new CircleSlider will be attached as a child.</param>
34 /// <param name="surface">The surface for drawing circle features for this widget.</param>
35 public CircleSlider(EvasObject parent, CircleSurface surface) : base()
37 Debug.Assert(parent == null || surface == null || parent.IsRealized);
43 /// Changed will be triggered when the circle slider value changes.
45 public event EventHandler ValueChanged;
48 /// Gets the handle for Circle Widget.
50 public virtual IntPtr CircleHandle => RealHandle;
53 /// Gets the handle for Circle Surface used in this widget
55 public virtual CircleSurface CircleSurface => _surface;
58 /// Sets or gets the step by which the circle slider bar moves.
61 /// This value is used when circle slider value is changed by an drag or rotary event
62 /// The value of the slider is increased/decreased by the step value.
68 return Interop.Eext.eext_circle_object_slider_step_get(CircleHandle);
72 Interop.Eext.eext_circle_object_slider_step_set(CircleHandle, (double)value);
77 /// Sets or gets the state of the widget, which might be enabled or disabled.
79 public override bool IsEnabled
83 return !Interop.Eext.eext_circle_object_disabled_get(CircleHandle);
87 Interop.Eext.eext_circle_object_disabled_set(CircleHandle, !value);
92 /// Sets or gets color of the circle slider bar.
102 Interop.Eext.eext_circle_object_color_get(CircleHandle, out r, out g, out b, out a);
103 return Color.FromRgba(r, g, b, a);
107 Interop.Eext.eext_circle_object_color_set(CircleHandle, value.R, value.G, value.B, value.A);
112 /// Sets or gets color of the circle slider background.
114 public override Color BackgroundColor
122 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "bg", out r, out g, out b, out a);
123 return Color.FromRgba(r, g, b, a);
127 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "bg", value.R, value.G, value.B, value.A);
132 /// Sets or gets the line with of the circle slider bar.
134 public int BarLineWidth
138 return Interop.Eext.eext_circle_object_line_width_get(CircleHandle);
142 Interop.Eext.eext_circle_object_line_width_set(CircleHandle, value);
147 /// Sets or gets the line with of the circle slider background.
149 public int BackgroundLineWidth
153 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "bg");
157 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "bg", value);
162 /// Sets or gets the angle in degree of the circle slider bar.
164 public double BarAngle
168 return Interop.Eext.eext_circle_object_angle_get(CircleHandle);
172 Interop.Eext.eext_circle_object_angle_set(CircleHandle, value);
177 /// Sets or gets the angle in degree of the circle slider background.
179 public double BackgroundAngle
183 return Interop.Eext.eext_circle_object_item_angle_get(CircleHandle, "bg");
187 Interop.Eext.eext_circle_object_item_angle_set(CircleHandle, "bg", value);
192 /// Sets or gets the angle offset for the slider bar.
193 /// offset value means start position of the slider bar.
195 public double BarAngleOffset
199 return Interop.Eext.eext_circle_object_angle_offset_get(CircleHandle);
203 Interop.Eext.eext_circle_object_angle_offset_set(CircleHandle, value);
208 /// Sets or gets the angle offset for the circle slider background.
209 /// offset value means start position of the slider background.
211 public double BackgroundAngleOffset
215 return Interop.Eext.eext_circle_object_item_angle_offset_get(CircleHandle, "bg");
219 Interop.Eext.eext_circle_object_item_angle_offset_set(CircleHandle, "bg", value);
224 /// Sets or gets the minimum angle of the circle slider bar.
226 public double BarAngleMinimum
232 Interop.Eext.eext_circle_object_angle_min_max_get(CircleHandle, out min, out max);
237 double max = BarAngleMaximum;
238 Interop.Eext.eext_circle_object_angle_min_max_set(CircleHandle, (double)value, max);
243 /// Sets or gets the maximum angle of the circle slider bar.
245 public double BarAngleMaximum
251 Interop.Eext.eext_circle_object_angle_min_max_get(CircleHandle, out min, out max);
256 double min = BarAngleMinimum;
257 Interop.Eext.eext_circle_object_angle_min_max_set(CircleHandle, min, (double)value);
262 /// Sets or gets the minimum values for the circle slider.
265 /// This defines the allowed minimum values to be selected by the user.
266 /// If the actual value is less than min, it is updated to min.
267 /// Actual value can be obtained with Value.By default, min is equal to 0.0.
269 public double Minimum
275 Interop.Eext.eext_circle_object_value_min_max_get(CircleHandle, out min, out max);
280 double max = Maximum;
281 Interop.Eext.eext_circle_object_value_min_max_set(CircleHandle, (double)value, max);
286 /// Sets or gets the maximum values for the circle slider.
289 /// This defines the allowed maximum values to be selected by the user.
290 /// If the actual value is bigger then max, it is updated to max.
291 /// Actual value can be obtained with Value.By default, min is equal to 0.0, and max is equal to 1.0.
292 /// Maximum must be greater than minimum, otherwise the behavior is undefined.
294 public double Maximum
300 Interop.Eext.eext_circle_object_value_min_max_get(CircleHandle, out min, out max);
305 double min = Minimum;
306 Interop.Eext.eext_circle_object_value_min_max_set(CircleHandle, min, (double)value);
311 /// Gets or sets the value displayed by the circle slider.
314 /// The value must to be between Minimum and Maximum values.
320 return Interop.Eext.eext_circle_object_value_get(CircleHandle);
324 Interop.Eext.eext_circle_object_value_set(CircleHandle, (double)value);
329 /// Gets or sets the radius value for the circle slider bar.
331 public double BarRadius
335 return Interop.Eext.eext_circle_object_radius_get(CircleHandle);
339 Interop.Eext.eext_circle_object_radius_set(CircleHandle, value);
344 /// Gets or sets the radius value for the circle slider background.
346 public double BackgroundRadius
350 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "bg");
354 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "bg", value);
359 /// The callback of Realized Event
361 protected override void OnRealized()
364 _changedEvent = new SmartEvent(this, "value,changed");
365 _changedEvent.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
369 /// Creates a widget handle.
371 /// <param name="parent">Parent EvasObject</param>
372 /// <returns>Handle IntPtr</returns>
373 protected override IntPtr CreateHandle(EvasObject parent)
375 return Interop.Eext.eext_circle_object_slider_add(parent, CircleSurface.Handle);