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.ComponentModel;
19 using System.Diagnostics;
21 namespace ElmSharp.Wearable
24 /// Circle slider is a circular designed widget used to select a value in a range by the Rotary event.
26 /// <since_tizen> preview </since_tizen>
27 public class CircleSlider : Widget, IRotaryActionWidget
29 SmartEvent _changedEvent;
30 CircleSurface _surface;
33 /// Creates and initializes a new instance of the CircleSlider class.
35 /// <param name="parent">The EvasObject to which the new CircleSlider will be attached as a child.</param>
36 /// <param name="surface">The surface for drawing the circle features for this widget.</param>
37 /// <since_tizen> preview </since_tizen>
38 public CircleSlider(EvasObject parent, CircleSurface surface) : base()
40 Debug.Assert(parent == null || surface == null || parent.IsRealized);
46 /// Creates and initializes a new instance of the Circle Slider class.
48 /// <param name="parent">The parent of the new Circle CircleSlider instance.</param>
49 /// <since_tizen> preview </since_tizen>
50 [Obsolete("It is not safe for guess circle surface from parent and create new surface by every new widget")]
51 [EditorBrowsable(EditorBrowsableState.Never)]
52 public CircleSlider(EvasObject parent) : this(parent, CircleSurface.CreateCircleSurface(parent))
54 ((IRotaryActionWidget)this).Activate();
58 /// Changed will be triggered when the circle slider value changes.
60 /// <since_tizen> preview </since_tizen>
61 public event EventHandler ValueChanged;
64 /// Gets the handle for the Circle widget.
66 /// <since_tizen> preview </since_tizen>
67 public virtual IntPtr CircleHandle => RealHandle;
70 /// Gets the handle for the circle surface used in this widget.
72 /// <since_tizen> preview </since_tizen>
73 public virtual CircleSurface CircleSurface => _surface;
76 /// Sets or gets the step by which the circle slider bar moves.
79 /// This value is used when the circle slider value is changed by a drag or the Rotary event.
80 /// The value of the slider is increased/decreased by the step value.
82 /// <since_tizen> preview </since_tizen>
87 return Interop.Eext.eext_circle_object_slider_step_get(CircleHandle);
91 Interop.Eext.eext_circle_object_slider_step_set(CircleHandle, (double)value);
96 /// Sets or gets the disabled state of this widget.
98 /// <since_tizen> preview </since_tizen>
99 [Obsolete("Use IsEnabled")]
100 [EditorBrowsable(EditorBrowsableState.Never)]
104 set => IsEnabled = !value;
108 /// Sets or gets the state of the widget, which might be enabled or disabled.
110 /// <since_tizen> preview </since_tizen>
111 public override bool IsEnabled
115 return !Interop.Eext.eext_circle_object_disabled_get(CircleHandle);
119 Interop.Eext.eext_circle_object_disabled_set(CircleHandle, !value);
124 /// Sets or gets the color of the circle slider bar.
126 /// <since_tizen> preview </since_tizen>
127 public Color BarColor
135 Interop.Eext.eext_circle_object_color_get(CircleHandle, out r, out g, out b, out a);
136 return Color.FromRgba(r, g, b, a);
140 Interop.Eext.eext_circle_object_color_set(CircleHandle, value.R, value.G, value.B, value.A);
145 /// Sets or gets the color of the circle slider background.
147 /// <since_tizen> preview </since_tizen>
148 public override Color BackgroundColor
156 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "bg", out r, out g, out b, out a);
157 return Color.FromRgba(r, g, b, a);
161 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "bg", value.R, value.G, value.B, value.A);
166 /// Sets or gets the line width of the circle slider bar.
168 /// <since_tizen> preview </since_tizen>
169 public int BarLineWidth
173 return Interop.Eext.eext_circle_object_line_width_get(CircleHandle);
177 Interop.Eext.eext_circle_object_line_width_set(CircleHandle, value);
182 /// Sets or gets the line width of the circle slider background.
184 /// <since_tizen> preview </since_tizen>
185 public int BackgroundLineWidth
189 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "bg");
193 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "bg", value);
198 /// Sets or gets the angle in degree of the circle slider bar.
200 /// <since_tizen> preview </since_tizen>
201 public double BarAngle
205 return Interop.Eext.eext_circle_object_angle_get(CircleHandle);
209 Interop.Eext.eext_circle_object_angle_set(CircleHandle, value);
214 /// Sets or gets the angle in degree of the circle slider background.
216 /// <since_tizen> preview </since_tizen>
217 public double BackgroundAngle
221 return Interop.Eext.eext_circle_object_item_angle_get(CircleHandle, "bg");
225 Interop.Eext.eext_circle_object_item_angle_set(CircleHandle, "bg", value);
230 /// Sets or gets the angle offset for the slider bar.
231 /// Offset value means start position of the slider bar.
233 /// <since_tizen> preview </since_tizen>
234 public double BarAngleOffset
238 return Interop.Eext.eext_circle_object_angle_offset_get(CircleHandle);
242 Interop.Eext.eext_circle_object_angle_offset_set(CircleHandle, value);
247 /// Sets or gets the angle offset for the circle slider background.
248 /// Offset value means start position of the slider background.
250 /// <since_tizen> preview </since_tizen>
251 public double BackgroundAngleOffset
255 return Interop.Eext.eext_circle_object_item_angle_offset_get(CircleHandle, "bg");
259 Interop.Eext.eext_circle_object_item_angle_offset_set(CircleHandle, "bg", value);
264 /// Sets or gets the minimum angle of the circle slider bar.
266 /// <since_tizen> preview </since_tizen>
267 public double BarAngleMinimum
273 Interop.Eext.eext_circle_object_angle_min_max_get(CircleHandle, out min, out max);
278 double max = BarAngleMaximum;
279 Interop.Eext.eext_circle_object_angle_min_max_set(CircleHandle, (double)value, max);
284 /// Sets or gets the maximum angle of the circle slider bar.
286 /// <since_tizen> preview </since_tizen>
287 public double BarAngleMaximum
293 Interop.Eext.eext_circle_object_angle_min_max_get(CircleHandle, out min, out max);
298 double min = BarAngleMinimum;
299 Interop.Eext.eext_circle_object_angle_min_max_set(CircleHandle, min, (double)value);
304 /// Sets or gets the minimum values for the circle slider.
307 /// This defines the allowed minimum values to be selected by the user.
308 /// If the actual value is less than the minimum value, it is updated to the minimum value.
309 /// Actual value can be obtained with Value. By default, minimum value is equal to 0.0.
311 /// <since_tizen> preview </since_tizen>
312 public double Minimum
318 Interop.Eext.eext_circle_object_value_min_max_get(CircleHandle, out min, out max);
323 double max = Maximum;
324 Interop.Eext.eext_circle_object_value_min_max_set(CircleHandle, (double)value, max);
329 /// Sets or gets the maximum values for the circle slider.
332 /// This defines the allowed maximum values to be selected by the user.
333 /// If the actual value is bigger than the maximum value, it is updated to the maximum value.
334 /// Actual value can be obtained with Value. By default, the minimum value is equal to 0.0, and the maximum value is equal to 1.0.
335 /// Maximum must be greater than minimum, otherwise the behavior is undefined.
337 /// <since_tizen> preview </since_tizen>
338 public double Maximum
344 Interop.Eext.eext_circle_object_value_min_max_get(CircleHandle, out min, out max);
349 double min = Minimum;
350 Interop.Eext.eext_circle_object_value_min_max_set(CircleHandle, min, (double)value);
355 /// Gets or sets the value displayed by the circle slider.
358 /// The value must be between minimum and maximum.
360 /// <since_tizen> preview </since_tizen>
365 return Interop.Eext.eext_circle_object_value_get(CircleHandle);
369 Interop.Eext.eext_circle_object_value_set(CircleHandle, (double)value);
374 /// Gets or sets the radius value for the circle slider bar.
376 /// <since_tizen> preview </since_tizen>
377 public double BarRadius
381 return Interop.Eext.eext_circle_object_radius_get(CircleHandle);
385 Interop.Eext.eext_circle_object_radius_set(CircleHandle, value);
390 /// Gets or sets the radius value for the circle slider background.
392 /// <since_tizen> preview </since_tizen>
393 public double BackgroundRadius
397 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "bg");
401 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "bg", value);
406 /// The callback of the Realized event.
408 /// <since_tizen> preview </since_tizen>
409 protected override void OnRealized()
412 _changedEvent = new SmartEvent(this, "value,changed");
413 _changedEvent.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
417 /// Creates a widget handle.
419 /// <param name="parent">Parent EvasObject</param>
420 /// <returns>Handle IntPtr.</returns>
421 /// <since_tizen> preview </since_tizen>
422 protected override IntPtr CreateHandle(EvasObject parent)
424 return Interop.Eext.eext_circle_object_slider_add(parent, CircleSurface.Handle);