2 * Copyright(c) 2020 Samsung Electronics Co., Ltd.
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 Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Binding;
20 using Tizen.NUI.Components;
21 using System.ComponentModel;
23 namespace Tizen.NUI.Wearable
26 /// Value Changed event data.
28 [Obsolete("This has been deprecated in API12")]
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public class CircularSliderValueChangedEventArgs : EventArgs
32 private float currentValue = 0.0f;
37 [Obsolete("This has been deprecated in API12")]
38 [EditorBrowsable(EditorBrowsableState.Never)]
39 public float CurrentValue
41 get { return currentValue; }
42 set { currentValue = value; }
47 /// The CircularSlider class of Wearable is used to let users select a value from a continuous or discrete range of values by moving the slider thumb.
48 /// CircularSlider shows the current value with the length of the line.
50 [Obsolete("This has been deprecated in API12")]
51 [EditorBrowsable(EditorBrowsableState.Never)]
52 public class CircularSlider : Control
56 /// <summary>Bindable property of Thickness</summary>
57 [EditorBrowsable(EditorBrowsableState.Never)]
58 public static readonly BindableProperty ThicknessProperty = BindableProperty.Create(nameof(Thickness), typeof(float), typeof(CircularSlider), default(float), propertyChanged: (bindable, oldValue, newValue) =>
60 var instance = ((CircularSlider)bindable);
61 instance.CurrentStyle.Thickness = (float)newValue;
62 instance.UpdateVisualThickness((float)newValue);
64 defaultValueCreator: (bindable) =>
66 return ((CircularSlider)bindable).CurrentStyle.Thickness;
69 /// <summary>Bindable property of MaxValue</summary>
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public static readonly BindableProperty MaxValueProperty = BindableProperty.Create(nameof(MaxValue), typeof(float), typeof(CircularSlider), default(float), propertyChanged: (bindable, oldValue, newValue) =>
73 var instance = (CircularSlider)bindable;
76 instance.maxValue = (float)newValue;
77 instance.UpdateValue();
80 defaultValueCreator: (bindable) =>
82 var instance = (CircularSlider)bindable;
83 return instance.maxValue;
86 /// <summary>Bindable property of MinValue</summary>
87 [EditorBrowsable(EditorBrowsableState.Never)]
88 public static readonly BindableProperty MinValueProperty = BindableProperty.Create(nameof(MinValue), typeof(float), typeof(CircularSlider), default(float), propertyChanged: (bindable, oldValue, newValue) =>
90 var instance = (CircularSlider)bindable;
93 instance.minValue = (float)newValue;
94 instance.UpdateValue();
97 defaultValueCreator: (bindable) =>
99 var instance = (CircularSlider)bindable;
100 return instance.minValue;
103 /// <summary>Bindable property of CurrentValue</summary>
104 [EditorBrowsable(EditorBrowsableState.Never)]
105 public static readonly BindableProperty CurrentValueProperty = BindableProperty.Create(nameof(CurrentValue), typeof(float), typeof(CircularSlider), default(float), propertyChanged: (bindable, oldValue, newValue) =>
107 var instance = (CircularSlider)bindable;
108 if (newValue != null)
110 if ((float)newValue > instance.maxValue || (float)newValue < instance.minValue)
114 instance.currentValue = (float)newValue;
115 instance.UpdateValue();
118 defaultValueCreator: (bindable) =>
120 var instance = (CircularSlider)bindable;
121 return instance.currentValue;
124 /// <summary>Bindable property of TrackColor</summary>
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public static readonly BindableProperty TrackColorProperty = BindableProperty.Create(nameof(TrackColor), typeof(Color), typeof(CircularSlider), null, propertyChanged: (bindable, oldValue, newValue) =>
128 var instance = (CircularSlider)bindable;
129 instance.CurrentStyle.TrackColor = (Color)newValue;
130 instance.UpdateTrackVisualColor((Color)newValue);
132 defaultValueCreator: (bindable) =>
134 return ((CircularSlider)bindable).CurrentStyle.TrackColor;
137 /// <summary>Bindable property of ProgressColor</summary>
138 [EditorBrowsable(EditorBrowsableState.Never)]
139 public static readonly BindableProperty ProgressColorProperty = BindableProperty.Create(nameof(ProgressColor), typeof(Color), typeof(CircularSlider), null, propertyChanged: (bindable, oldValue, newValue) =>
141 var instance = (CircularSlider)bindable;
142 instance.CurrentStyle.ProgressColor = (Color)newValue;
143 instance.UpdateProgressVisualColor((Color)newValue);
145 defaultValueCreator: (bindable) =>
147 return ((CircularSlider)bindable).CurrentStyle.ProgressColor;
150 /// <summary>Bindable property of ThumbSize</summary>
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public static readonly BindableProperty ThumbSizeProperty = BindableProperty.Create(nameof(ThumbSize), typeof(Size), typeof(CircularSlider), new Size(0, 0), propertyChanged: (bindable, oldValue, newValue) =>
154 var instance = (CircularSlider)bindable;
155 if (newValue != null)
157 instance.thumbSize = (Size)newValue;
158 instance.UpdateThumbVisualSize((Size)newValue);
161 defaultValueCreator: (bindable) =>
163 var instance = (CircularSlider)bindable;
164 return instance.thumbSize;
167 /// <summary>Bindable property of ThumbColor</summary>
168 [EditorBrowsable(EditorBrowsableState.Never)]
169 public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(CircularSlider), null, propertyChanged: (bindable, oldValue, newValue) =>
171 var instance = (CircularSlider)bindable;
172 instance.CurrentStyle.ThumbColor = (Color)newValue;
173 instance.UpdateThumbVisualColor((Color)newValue);
175 defaultValueCreator: (bindable) =>
177 return ((CircularSlider)bindable).CurrentStyle.ThumbColor;
180 /// <summary>Bindable property of IsEnabled</summary>
181 [EditorBrowsable(EditorBrowsableState.Never)]
182 public new static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(CircularSlider), true, propertyChanged: (bindable, oldValue, newValue) =>
184 var instance = (CircularSlider)bindable;
185 if (newValue != null)
187 instance.privateIsEnabled = (bool)newValue;
190 defaultValueCreator: (bindable) =>
192 var instance = (CircularSlider)bindable;
193 return instance.privateIsEnabled;
196 private const string TrackVisualName = "Track";
197 private const string ProgressVisualName = "Progress";
198 private const string ThumbVisualName = "Thumb";
199 private ArcVisual trackVisual;
200 private ArcVisual progressVisual;
201 private ArcVisual thumbVisual;
203 private float maxValue = 100;
204 private float minValue = 0;
205 private float currentValue = 0;
206 private Size thumbSize;
207 private bool isEnabled = true;
209 float sliderPadding = 6.0f;
211 private Animation sweepAngleAnimation;
212 private Animation thumbAnimation;
219 static CircularSlider()
221 ThemeManager.AddPackageTheme(DefaultThemeCreator.Instance);
225 /// The constructor of CircularSlider.
227 [Obsolete("This has been deprecated in API12")]
228 [EditorBrowsable(EditorBrowsableState.Never)]
229 public CircularSlider() : base()
235 /// The constructor of the CircularSlider class with specific style.
237 /// <param name="progressStyle">The style object to initialize the CircularSlider.</param>
238 [Obsolete("This has been deprecated in API12")]
239 [EditorBrowsable(EditorBrowsableState.Never)]
240 public CircularSlider(CircularSliderStyle progressStyle) : base(progressStyle)
245 #endregion Constructors
250 /// The value changed event handler.
252 [Obsolete("This has been deprecated in API12")]
253 [EditorBrowsable(EditorBrowsableState.Never)]
254 public event EventHandler<CircularSliderValueChangedEventArgs> ValueChanged;
261 /// The thickness of the track and progress.
263 [Obsolete("This has been deprecated in API12")]
264 [EditorBrowsable(EditorBrowsableState.Never)]
265 public float Thickness
269 return (float)GetValue(ThicknessProperty);
273 SetValue(ThicknessProperty, value);
278 /// The property to get/set the maximum value of the CircularSlider.
279 /// The default value is 100.
281 [Obsolete("This has been deprecated in API12")]
282 [EditorBrowsable(EditorBrowsableState.Never)]
283 public float MaxValue
287 return (float)GetValue(MaxValueProperty);
291 SetValue(MaxValueProperty, value);
296 /// The property to get/set the minimum value of the CircularSlider.
297 /// The default value is 0.
299 [Obsolete("This has been deprecated in API12")]
300 [EditorBrowsable(EditorBrowsableState.Never)]
301 public float MinValue
305 return (float)GetValue(MinValueProperty);
309 SetValue(MinValueProperty, value);
314 /// The property to get/set the current value of the CircularSlider.
315 /// The default value is 0.
317 [Obsolete("This has been deprecated in API12")]
318 [EditorBrowsable(EditorBrowsableState.Never)]
319 public float CurrentValue
323 return (float)GetValue(CurrentValueProperty);
327 if (sweepAngleAnimation)
329 sweepAngleAnimation.Stop();
331 // For the first Animation effect
332 sweepAngleAnimation = AnimateVisual(progressVisual, "sweepAngle", progressVisual.SweepAngle, 0, 100, AlphaFunction.BuiltinFunctions.EaseIn);
334 SetValue(CurrentValueProperty, value);
341 /// The property to get/set Track object color of the CircularSlider.
343 [Obsolete("This has been deprecated in API12")]
344 [EditorBrowsable(EditorBrowsableState.Never)]
345 public Color TrackColor
349 return (Color)GetValue(TrackColorProperty);
353 SetValue(TrackColorProperty, value);
358 /// The property to get/set Progress object color of the CircularSlider.
360 [Obsolete("This has been deprecated in API12")]
361 [EditorBrowsable(EditorBrowsableState.Never)]
362 public Color ProgressColor
366 return (Color)GetValue(ProgressColorProperty);
370 SetValue(ProgressColorProperty, value);
375 /// Gets or sets the size of the thumb of Slider.
377 [Obsolete("This has been deprecated in API12")]
378 [EditorBrowsable(EditorBrowsableState.Never)]
379 public Size ThumbSize
383 return (Size)GetValue(ThumbSizeProperty);
387 SetValue(ThumbSizeProperty, value);
392 /// The property to get/set Thumb object color of the CircularSlider.
394 [Obsolete("This has been deprecated in API12")]
395 [EditorBrowsable(EditorBrowsableState.Never)]
396 public Color ThumbColor
400 return (Color)GetValue(ThumbColorProperty);
404 SetValue(ThumbColorProperty, value);
409 /// Flag to be enabled or disabled in CircularSlider.
411 [Obsolete("This has been deprecated in API12")]
412 [EditorBrowsable(EditorBrowsableState.Never)]
413 public new bool IsEnabled
417 return (bool)GetValue(IsEnabledProperty);
421 SetValue(IsEnabledProperty, value);
424 private bool privateIsEnabled
435 UpdateTrackVisualColor(new Color(0.0f, 0.16f, 0.30f, 1.0f)); // #002A4D
439 UpdateTrackVisualColor(new Color(0.25f, 0.25f, 0.25f, 1.0f)); // #404040
444 private CircularSliderStyle CurrentStyle => ViewStyle as CircularSliderStyle;
446 #endregion Properties
452 /// Dispose Progress and all children on it.
454 /// <param name="type">Dispose type.</param>
455 [Obsolete("This has been deprecated in API12")]
456 [EditorBrowsable(EditorBrowsableState.Never)]
457 protected override void Dispose(DisposeTypes type)
464 if (type == DisposeTypes.Explicit)
467 progressVisual = null;
475 /// Update progress value
477 [Obsolete("This has been deprecated in API12")]
478 [EditorBrowsable(EditorBrowsableState.Never)]
479 protected virtual void UpdateValue()
481 if (null == trackVisual || null == progressVisual || null == thumbVisual)
486 if (minValue >= maxValue || currentValue < minValue || currentValue > maxValue)
491 HandleProgressVisualVisibility();
493 UpdateProgressVisualSweepAngle();
497 /// Get Progress style.
499 /// <returns>The default progress style.</returns>
500 [Obsolete("This has been deprecated in API12")]
501 [EditorBrowsable(EditorBrowsableState.Never)]
502 protected override ViewStyle CreateViewStyle()
504 return new CircularSliderStyle();
507 private void Initialize()
509 Size = new Size(360.0f, 360.0f);
511 sweepAngleAnimation?.Stop();
512 sweepAngleAnimation = null;
514 thumbAnimation?.Stop();
515 thumbAnimation = null;
517 trackVisual = new ArcVisual
519 SuppressUpdateVisual = true,
520 Size = new Size(this.Size.Width - sliderPadding, this.Size.Height - sliderPadding),
521 SizePolicy = VisualTransformPolicyType.Absolute,
522 Thickness = this.Thickness,
523 Cap = ArcVisual.CapType.Butt,
524 MixColor = TrackColor,
528 this.AddVisual(TrackVisualName, trackVisual);
530 progressVisual = new ArcVisual
532 SuppressUpdateVisual = true,
533 Size = new Size(this.Size.Width - sliderPadding, this.Size.Height - sliderPadding),
534 SizePolicy = VisualTransformPolicyType.Absolute,
535 Thickness = this.Thickness,
536 Cap = ArcVisual.CapType.Butt,
537 MixColor = ProgressColor,
541 this.AddVisual(ProgressVisualName, progressVisual);
543 thumbVisual = new ArcVisual
545 SuppressUpdateVisual = true,
546 Size = new Size(this.Size.Width + sliderPadding, this.Size.Height + sliderPadding),
547 SizePolicy = VisualTransformPolicyType.Absolute,
548 Thickness = this.ThumbSize.Width,
549 Cap = ArcVisual.CapType.Round,
550 MixColor = this.ThumbColor,
554 this.AddVisual(ThumbVisualName, thumbVisual);
556 HandleProgressVisualVisibility();
558 UpdateProgressVisualSweepAngle();
561 private void HandleProgressVisualVisibility()
565 progressVisual.Opacity = 1.0f;
569 progressVisual.Opacity = 0.6f;
573 private void UpdateVisualThickness(float thickness)
575 if (trackVisual == null)
580 trackVisual.Thickness = thickness;
581 progressVisual.Thickness = thickness;
583 trackVisual.UpdateVisual(true);
584 progressVisual.UpdateVisual(true);
587 private void UpdateProgressVisualSweepAngle()
589 float progressRatio = (float)(currentValue - minValue) / (float)(maxValue - minValue);
590 float progressWidth = 360.0f * progressRatio; // Circle
592 progressVisual.SweepAngle = progressWidth;
593 thumbVisual.StartAngle = progressWidth;
595 if (!sweepAngleAnimation)
597 progressVisual.UpdateVisual(true);
598 thumbVisual.UpdateVisual(true);
602 private void UpdateAnimation()
604 // TODO : Currently not sure which effect is needed.
605 AlphaFunction.BuiltinFunctions builtinAlphaFunction = AlphaFunction.BuiltinFunctions.EaseOut;
607 if (sweepAngleAnimation)
609 sweepAngleAnimation.Stop();
613 thumbAnimation.Stop();
616 sweepAngleAnimation = AnimateVisual(progressVisual, "sweepAngle", progressVisual.SweepAngle, 0, 500, builtinAlphaFunction);
617 thumbAnimation = AnimateVisual(thumbVisual, "startAngle", thumbVisual.StartAngle, 0, 500, builtinAlphaFunction);
619 if (sweepAngleAnimation)
621 sweepAngleAnimation.Play();
622 thumbAnimation.Play();
625 ValueChanged?.Invoke(this, new CircularSliderValueChangedEventArgs() { CurrentValue = currentValue });
628 private void UpdateTrackVisualColor(Color trackColor)
630 if (trackVisual == null)
635 trackVisual.MixColor = trackColor;
636 trackVisual.UpdateVisual(true);
639 private void UpdateProgressVisualColor(Color progressColor)
641 if (progressVisual == null)
646 progressVisual.MixColor = progressColor;
647 if (!isEnabled) // Dim state
649 progressVisual.Opacity = 0.6f;
652 progressVisual.UpdateVisual(true);
655 private void UpdateThumbVisualSize(Size thumbSize)
657 if (thumbVisual == null)
662 thumbVisual.Thickness = thumbSize.Width;
663 thumbVisual.UpdateVisual(true);
666 private void UpdateThumbVisualColor(Color thumbColor)
668 if (thumbVisual == null)
673 thumbVisual.MixColor = thumbColor;
674 thumbVisual.UpdateVisual(true);