2 * Copyright(c) 2021 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 System.ComponentModel;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.Components
25 /// Slider value changed event data.
27 /// <since_tizen> 8 </since_tizen>
28 public class SliderValueChangedEventArgs : EventArgs
31 /// Current Slider value
33 /// <since_tizen> 8 </since_tizen>
34 public float CurrentValue { get; set; }
38 /// Slider sliding started event data.
40 /// <since_tizen> 8 </since_tizen>
41 public class SliderSlidingStartedEventArgs : EventArgs
44 /// Current Slider value
46 /// <since_tizen> 8 </since_tizen>
47 public float CurrentValue { get; set; }
51 /// Slider sliding finished event data.
53 /// <since_tizen> 8 </since_tizen>
54 public class SliderSlidingFinishedEventArgs : EventArgs
57 /// Current Slider value
59 /// <since_tizen> 8 </since_tizen>
60 public float CurrentValue { get; set; }
64 /// A slider lets users select a value from a continuous or discrete range of values by moving the slider thumb.
66 /// <since_tizen> 6 </since_tizen>
67 public partial class Slider : Control
70 /// IndicatorTypeProperty
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 public static readonly BindableProperty IndicatorTypeProperty = BindableProperty.Create("IndicatorType", typeof(IndicatorType), typeof(Slider), IndicatorType.None, propertyChanged: (bindable, oldValue, newValue) =>
75 var instance = (Slider)bindable;
78 instance.privateIndicatorType = (IndicatorType)newValue;
81 defaultValueCreator: (bindable) =>
83 var instance = (Slider)bindable;
84 return instance.privateIndicatorType;
88 /// SpaceBetweenTrackAndIndicatorProperty
90 [EditorBrowsable(EditorBrowsableState.Never)]
91 public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create(nameof(SpaceBetweenTrackAndIndicator), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
93 var instance = (Slider)bindable;
96 instance.privateSpaceBetweenTrackAndIndicator = (uint)newValue;
99 defaultValueCreator: (bindable) =>
101 var instance = (Slider)bindable;
102 return instance.privateSpaceBetweenTrackAndIndicator;
106 /// TrackThicknessProperty
108 [EditorBrowsable(EditorBrowsableState.Never)]
109 public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
111 var instance = (Slider)bindable;
112 if (newValue != null)
114 instance.privateTrackThickness = (uint)newValue;
117 defaultValueCreator: (bindable) =>
119 var instance = (Slider)bindable;
120 return instance.privateTrackThickness;
124 /// IsValueShownProperty
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public static readonly BindableProperty IsValueShownProperty = BindableProperty.Create(nameof(IsValueShown), typeof(bool), typeof(Slider), true, propertyChanged: (bindable, oldValue, newValue) =>
129 var instance = (Slider)bindable;
130 if (newValue != null)
132 bool newValueShown = (bool)newValue;
133 if (instance.isValueShown != newValueShown)
135 instance.isValueShown = newValueShown;
139 defaultValueCreator: (bindable) =>
141 var instance = (Slider)bindable;
142 return instance.isValueShown;
146 /// ValueIndicatorTextProperty
148 [EditorBrowsable(EditorBrowsableState.Never)]
149 public static readonly BindableProperty ValueIndicatorTextProperty = BindableProperty.Create(nameof(ValueIndicatorText), typeof(string), typeof(Slider), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
151 var instance = (Slider)bindable;
152 if (newValue != null)
154 string newText = (string)newValue;
155 instance.valueIndicatorText.Text = newText;
156 if (instance.sliderStyle != null)
158 instance.sliderStyle.ValueIndicatorText.Text = newText;
162 defaultValueCreator: (bindable) =>
164 var instance = (Slider)bindable;
165 return instance.valueIndicatorText.Text;
171 /// The constructor of the Slider class.
173 /// <since_tizen> 6 </since_tizen>
180 /// The constructor of the Slider class with specific style.
182 /// <param name="style">The string to initialize the Slider</param>
183 /// <since_tizen> 8 </since_tizen>
184 public Slider(string style) : base(style)
190 /// The constructor of the Slider class with specific style.
192 /// <param name="sliderStyle">The style object to initialize the Slider</param>
193 /// <since_tizen> 8 </since_tizen>
194 public Slider(SliderStyle sliderStyle) : base(sliderStyle)
200 /// The value changed event handler.
202 /// <since_tizen> 6 </since_tizen>
203 [Obsolete("Deprecated in API8; Will be removed in API10. Please use ValueChanged event instead.")]
204 public event EventHandler<ValueChangedArgs> ValueChangedEvent
208 valueChangedHandler += value;
212 valueChangedHandler -= value;
217 /// The sliding finished event handler.
219 /// <since_tizen> 6 </since_tizen>
220 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SlidingFinished event instead.")]
221 public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
225 slidingFinishedHandler += value;
229 slidingFinishedHandler -= value;
234 /// The value changed event handler.
236 /// <since_tizen> 8 </since_tizen>
237 public event EventHandler<SliderValueChangedEventArgs> ValueChanged
241 sliderValueChangedHandler += value;
245 sliderValueChangedHandler -= value;
250 /// The sliding started event handler.
252 /// <since_tizen> 8 </since_tizen>
253 public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
257 sliderSlidingStartedHandler += value;
261 sliderSlidingStartedHandler -= value;
266 /// The sliding finished event handler.
268 /// <since_tizen> 8 </since_tizen>
269 public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
273 sliderSlidingFinishedHandler += value;
277 sliderSlidingFinishedHandler -= value;
282 /// The state changed event handler.
284 /// <since_tizen> 6 </since_tizen>
285 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
286 public event EventHandler<StateChangedArgs> StateChangedEvent
290 stateChangedHandler += value;
294 stateChangedHandler -= value;
299 /// The direction type of slider.
301 /// <since_tizen> 6 </since_tizen>
302 public enum DirectionType
305 /// The Horizontal type.
307 /// <since_tizen> 6 </since_tizen>
311 /// The Vertical type.
313 /// <since_tizen> 6 </since_tizen>
318 /// The indicator type of slider.
320 /// <since_tizen> 6 </since_tizen>
321 public enum IndicatorType
323 /// <summary> Only contains slider bar.</summary>
324 /// <since_tizen> 6 </since_tizen>
327 /// <summary> Contains slider bar, IndicatorImage.</summary>
328 /// <since_tizen> 6 </since_tizen>
331 /// <summary> Contains slider bar, IndicatorText.</summary>
332 /// <since_tizen> 6 </since_tizen>
337 /// Return a copied Style instance of Slider
340 /// It returns copied Style instance and changing it does not effect to the Slider.
341 /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
343 /// <since_tizen> 8 </since_tizen>
344 public new SliderStyle Style
348 var result = new SliderStyle(sliderStyle);
349 result.CopyPropertiesFromView(this);
350 result.Track.CopyPropertiesFromView(bgTrackImage);
351 result.Progress.CopyPropertiesFromView(slidedTrackImage);
352 result.Thumb.CopyPropertiesFromView(thumbImage);
353 result.LowIndicatorImage.CopyPropertiesFromView(lowIndicatorImage);
354 result.HighIndicatorImage.CopyPropertiesFromView(highIndicatorImage);
355 result.LowIndicator.CopyPropertiesFromView(lowIndicatorText);
356 result.HighIndicator.CopyPropertiesFromView(highIndicatorText);
357 result.ValueIndicatorText.CopyPropertiesFromView(valueIndicatorText);
358 result.ValueIndicatorImage.CopyPropertiesFromView(valueIndicatorImage);
364 /// Return a copied Style instance of Slider
366 private SliderStyle sliderStyle => ViewStyle as SliderStyle;
369 /// Gets or sets the direction type of slider.
371 /// <since_tizen> 6 </since_tizen>
372 public DirectionType Direction
380 if (direction == value)
385 RelayoutBaseComponent(false);
387 UpdateBgTrackPosition();
388 UpdateWarningTrackSize();
394 /// Gets or sets the indicator type, arrow or sign.
396 /// <since_tizen> 6 </since_tizen>
397 public IndicatorType Indicator
401 return (IndicatorType)GetValue(IndicatorTypeProperty);
405 SetValue(IndicatorTypeProperty, value);
410 /// Gets or sets the minimum value of slider.
412 /// <since_tizen> 6 </since_tizen>
413 public float MinValue
427 /// Gets or sets the maximum value of slider.
429 /// <since_tizen> 6 </since_tizen>
430 public float MaxValue
444 /// Gets or sets the current value of slider.
446 /// <since_tizen> 6 </since_tizen>
447 public float CurrentValue
458 EmitAccessibilityEvent(ObjectPropertyChangeEvent.Value);
465 /// Gets or sets the size of the thumb image object.
467 /// <since_tizen> 6 </since_tizen>
468 public Size ThumbSize
472 return thumbImage?.Size;
476 if (null != thumbImage)
478 thumbImage.Size = value;
480 sliderStyle.Thumb.Size = value;
486 /// Gets or sets the resource url of the thumb image object.
488 /// Please use ThumbImageUri property.
490 /// <since_tizen> 6 </since_tizen>
491 public string ThumbImageURL
495 return thumbImage?.ResourceUrl;
499 if (null != thumbImage)
501 thumbImage.ResourceUrl = value;
502 thumbImageUrl = value;
503 sliderStyle.Thumb.ResourceUrl = value;
509 /// Gets or sets the resource url selector of the thumb image object.
510 /// Getter returns copied selector value if exist, null otherwise.
512 /// Please use ThumbImageUri property.
514 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
515 /// <since_tizen> 6 </since_tizen>
516 public StringSelector ThumbImageURLSelector
518 get => thumbImage == null ? null : new StringSelector((Selector<string>)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty));
521 if (value == null || thumbImage == null)
523 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
527 thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, value);
528 thumbImageUrlSelector = value;
534 /// Gets or sets the Uri of the thumb image.
536 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
537 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
538 [EditorBrowsable(EditorBrowsableState.Never)]
539 public Selector<Uri> ThumbImageUri
543 if (thumbImage == null)
549 return ((Selector<string>)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty)).Clone<Uri>(str => { return new Uri(str); });
554 if (value == null || thumbImage == null)
556 throw new NullReferenceException("Slider.ThumbImageUri is null");
560 Selector<string> stringValue = value.Clone<string>(m => m?.AbsoluteUri);
561 thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, stringValue);
562 thumbImageUrlSelector = stringValue;
568 /// Gets or sets the color of the thumb image object.
570 /// <since_tizen> 8 </since_tizen>
571 public Color ThumbColor
575 return thumbImage?.Color;
579 if (null != thumbImage)
581 thumbImage.BackgroundColor = value;
583 sliderStyle.Thumb.BackgroundColor = value;
589 /// Gets or sets the color of the background track image object.
591 /// <since_tizen> 6 </since_tizen>
592 public Color BgTrackColor
596 return bgTrackImage?.BackgroundColor;
600 if (null != bgTrackImage)
602 bgTrackImage.BackgroundColor = value;
603 sliderStyle.Track.BackgroundColor = value;
609 /// Gets or sets the color of the slided track image object.
611 /// <since_tizen> 6 </since_tizen>
612 public Color SlidedTrackColor
616 return slidedTrackImage?.BackgroundColor;
620 if (null != slidedTrackImage)
622 slidedTrackImage.BackgroundColor = value;
623 sliderStyle.Progress.BackgroundColor = value;
629 /// Gets or sets the thickness value of the track.
631 /// <since_tizen> 6 </since_tizen>
632 public uint TrackThickness
636 return (uint)GetValue(TrackThicknessProperty);
640 SetValue(TrackThicknessProperty, value);
645 /// Gets or sets the warning start value between minimum value and maximum value of slider.
647 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
648 [EditorBrowsable(EditorBrowsableState.Never)]
649 public float WarningStartValue
653 return warningStartValue;
657 warningStartValue = value;
663 /// Gets or sets the color of the warning track image object.
665 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
666 [EditorBrowsable(EditorBrowsableState.Never)]
667 public Color WarningTrackColor
671 return warningTrackImage?.BackgroundColor;
675 if (null != warningTrackImage)
677 warningTrackImage.BackgroundColor = value;
678 sliderStyle.WarningTrack.BackgroundColor = value;
684 /// Gets or sets the color of the warning slided track image object.
686 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
687 [EditorBrowsable(EditorBrowsableState.Never)]
688 public Color WarningSlidedTrackColor
692 return warningSlidedTrackImage?.BackgroundColor;
696 if (null != warningSlidedTrackImage)
698 warningSlidedTrackImage.BackgroundColor = value;
699 sliderStyle.WarningProgress.BackgroundColor = value;
705 /// Gets or sets the resource url of the warning thumb image object.
707 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
708 [EditorBrowsable(EditorBrowsableState.Never)]
709 public string WarningThumbImageUrl
713 return warningThumbImageUrl;
717 warningThumbImageUrl = value;
722 /// Gets or sets the Uri of the warning thumb image.
724 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
725 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
726 [EditorBrowsable(EditorBrowsableState.Never)]
727 public Selector<Uri> WarningThumbImageUri
731 return warningThumbImageUrlSelector?.Clone<Uri>(str => { return new Uri(str); });
735 if (value == null || thumbImage == null)
737 throw new NullReferenceException("Slider.WarningThumbImageUri is null");
741 warningThumbImageUrlSelector = value.Clone<string>(m => m?.AbsoluteUri);
747 /// Gets or sets the color of the warning thumb image object.
749 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
750 [EditorBrowsable(EditorBrowsableState.Never)]
751 public Color WarningThumbColor
755 return warningThumbColor;
759 warningThumbColor = value;
764 /// Gets or sets the resource url of the low indicator image object.
766 /// <since_tizen> 6 </since_tizen>
767 public string LowIndicatorImageURL
771 return lowIndicatorImage?.ResourceUrl;
775 if (null == lowIndicatorImage) lowIndicatorImage = new ImageView();
776 lowIndicatorImage.ResourceUrl = value;
777 sliderStyle.LowIndicatorImage.ResourceUrl = value;
782 /// Gets or sets the resource url of the high indicator image object.
784 /// <since_tizen> 6 </since_tizen>
785 public string HighIndicatorImageURL
789 return highIndicatorImage?.ResourceUrl;
793 if (null == highIndicatorImage) highIndicatorImage = new ImageView();
794 highIndicatorImage.ResourceUrl = value;
795 sliderStyle.HighIndicatorImage.ResourceUrl = value;
800 /// Gets or sets the text content of the low indicator text object.
802 /// <since_tizen> 6 </since_tizen>
803 public string LowIndicatorTextContent
807 return lowIndicatorText?.Text;
811 if (null != lowIndicatorText)
813 lowIndicatorText.Text = value;
814 sliderStyle.LowIndicator.Text = value;
820 /// Gets or sets the text content of the high indicator text object.
822 /// <since_tizen> 6 </since_tizen>
823 public string HighIndicatorTextContent
827 return highIndicatorText?.Text;
831 if (null != highIndicatorText)
833 highIndicatorText.Text = value;
834 sliderStyle.HighIndicator.Text = value;
840 /// Gets or sets the size of the low indicator object(image or text).
842 /// <since_tizen> 6 </since_tizen>
843 public Size LowIndicatorSize
847 return lowIndicatorSize;
851 lowIndicatorSize = value;
852 UpdateLowIndicatorSize();
854 UpdateBgTrackPosition();
860 /// Gets or sets the size of the high indicator object(image or text).
862 /// <since_tizen> 6 </since_tizen>
863 public Size HighIndicatorSize
867 return highIndicatorText?.Size;
871 if (null != highIndicatorText)
873 highIndicatorText.Size = value;
874 sliderStyle.HighIndicator.Size = value;
880 /// Gets or sets the value of the space between track and indicator.
882 /// <since_tizen> 6 </since_tizen>
883 public uint SpaceBetweenTrackAndIndicator
887 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
891 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
896 /// Flag to decide whether the value indicator is shown
898 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
899 [EditorBrowsable(EditorBrowsableState.Never)]
900 public bool IsValueShown
904 return (bool)GetValue(IsValueShownProperty);
908 SetValue(IsValueShownProperty, value);
913 /// Gets or sets the text of value indicator.
915 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
916 [EditorBrowsable(EditorBrowsableState.Never)]
917 public string ValueIndicatorText
921 return (string)GetValue(ValueIndicatorTextProperty);
925 SetValue(ValueIndicatorTextProperty, value);
930 /// Gets or sets the size of the value indicator image object.
932 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
933 [EditorBrowsable(EditorBrowsableState.Never)]
934 public Size ValueIndicatorSize
938 return valueIndicatorImage?.Size;
942 if (null != valueIndicatorImage)
944 valueIndicatorImage.Size = value;
945 sliderStyle.ValueIndicatorImage.Size = value;
951 /// Gets or sets the resource url of the value indicator image object.
953 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
954 [EditorBrowsable(EditorBrowsableState.Never)]
955 public string ValueIndicatorUrl
959 return valueIndicatorImage?.ResourceUrl;
963 if (null != valueIndicatorImage)
965 valueIndicatorImage.ResourceUrl = value;
966 sliderStyle.ValueIndicatorImage.ResourceUrl = value;
971 private Extents spaceBetweenTrackAndIndicator
975 if (null == _spaceBetweenTrackAndIndicator)
977 _spaceBetweenTrackAndIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
979 Extents extents = new Extents(start, end, top, bottom);
980 _spaceBetweenTrackAndIndicator.CopyFrom(extents);
984 return _spaceBetweenTrackAndIndicator;
988 private IndicatorType privateIndicatorType
992 return indicatorType;
996 if (indicatorType == value)
1000 indicatorType = value;
1001 RelayoutBaseComponent(false);
1002 UpdateBgTrackSize();
1003 UpdateBgTrackPosition();
1008 private uint privateTrackThickness
1012 return trackThickness ?? 0;
1016 trackThickness = value;
1017 if (bgTrackImage != null)
1019 if (direction == DirectionType.Horizontal)
1021 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1023 else if (direction == DirectionType.Vertical)
1025 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1028 if (slidedTrackImage != null)
1030 if (direction == DirectionType.Horizontal)
1032 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1034 else if (direction == DirectionType.Vertical)
1036 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1039 if (warningTrackImage != null)
1041 if (direction == DirectionType.Horizontal)
1043 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1045 else if (direction == DirectionType.Vertical)
1047 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1050 if (warningSlidedTrackImage != null)
1052 if (direction == DirectionType.Horizontal)
1054 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1056 else if (direction == DirectionType.Vertical)
1058 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1064 private uint privateSpaceBetweenTrackAndIndicator
1068 return privateTrackPadding.Start;
1072 ushort val = (ushort)value;
1073 privateTrackPadding = new Extents(val, val, val, val);
1077 private Extents privateTrackPadding
1081 return spaceBetweenTrackAndIndicator;
1085 spaceBetweenTrackAndIndicator.CopyFrom(value);
1086 UpdateComponentByIndicatorTypeChanged();
1087 UpdateBgTrackSize();
1088 UpdateBgTrackPosition();
1094 /// Focus gained callback.
1096 /// <since_tizen> 8 </since_tizen>
1097 public override void OnFocusGained()
1099 //State = ControlStates.Focused;
1100 UpdateState(true, isPressed);
1101 base.OnFocusGained();
1105 /// Focus Lost callback.
1107 /// <since_tizen> 8 </since_tizen>
1108 public override void OnFocusLost()
1110 //State = ControlStates.Normal;
1111 UpdateState(false, isPressed);
1116 /// Apply style to scrollbar.
1118 /// <param name="viewStyle">The style to apply.</param>
1119 /// <since_tizen> 8 </since_tizen>
1120 public override void ApplyStyle(ViewStyle viewStyle)
1122 base.ApplyStyle(viewStyle);
1124 SliderStyle sliderStyle = viewStyle as SliderStyle;
1126 if (null != sliderStyle?.Progress)
1128 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1131 if (null != sliderStyle?.LowIndicator)
1133 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1136 if (null != sliderStyle?.HighIndicator)
1138 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1141 if (null != sliderStyle?.Track)
1143 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1146 if (null != sliderStyle?.Thumb)
1148 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1151 if (null != sliderStyle?.ValueIndicatorText)
1153 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1156 if (null != sliderStyle?.ValueIndicatorImage)
1158 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1161 if (null != sliderStyle?.WarningTrack)
1163 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1166 if (null != sliderStyle?.WarningProgress)
1168 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1171 EnableControlStatePropagation = true;
1175 /// Prevents from showing child widgets in AT-SPI tree.
1177 [EditorBrowsable(EditorBrowsableState.Never)]
1178 protected override bool AccessibilityShouldReportZeroChildren()
1186 [EditorBrowsable(EditorBrowsableState.Never)]
1187 protected override double AccessibilityGetMinimum()
1189 return (double)MinValue;
1195 [EditorBrowsable(EditorBrowsableState.Never)]
1196 protected override double AccessibilityGetCurrent()
1198 return (double)CurrentValue;
1204 [EditorBrowsable(EditorBrowsableState.Never)]
1205 protected override double AccessibilityGetMaximum()
1207 return (double)MaxValue;
1213 [EditorBrowsable(EditorBrowsableState.Never)]
1214 protected override bool AccessibilitySetCurrent(double value)
1216 var f = (float)value;
1218 if (f >= MinValue && f <= MaxValue)
1221 if (sliderValueChangedHandler != null)
1223 sliderValueChangedHandler(this, new SliderValueChangedEventArgs { CurrentValue = f });
1232 /// Minimum increment.
1234 [EditorBrowsable(EditorBrowsableState.Never)]
1235 protected override double AccessibilityGetMinimumIncrement()
1238 return (MaxValue - MinValue) / 20.0;
1242 /// Initliaze AT-SPI object.
1244 [EditorBrowsable(EditorBrowsableState.Never)]
1245 public override void OnInitialize()
1247 base.OnInitialize();
1248 SetAccessibilityConstructor(Role.Slider, AccessibilityInterface.Value);
1252 /// Get Slider style.
1254 /// <returns>The default slider style.</returns>
1255 /// <since_tizen> 8 </since_tizen>
1256 protected override ViewStyle CreateViewStyle()
1258 return new SliderStyle();
1264 /// <param name="type">Dispose type.</param>
1265 /// <since_tizen> 6 </since_tizen>
1266 protected override void Dispose(DisposeTypes type)
1273 if (type == DisposeTypes.Explicit)
1275 if (null != panGestureDetector)
1277 panGestureDetector.Detach(this);
1278 panGestureDetector.Detected -= OnPanGestureDetected;
1279 panGestureDetector.Dispose();
1280 panGestureDetector = null;
1283 if (null != thumbImage)
1285 thumbImage.TouchEvent -= OnTouchEventForThumb;
1286 Utility.Dispose(thumbImage);
1288 Utility.Dispose(warningSlidedTrackImage);
1289 Utility.Dispose(warningTrackImage);
1290 Utility.Dispose(slidedTrackImage);
1291 if (null != bgTrackImage)
1293 bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
1294 Utility.Dispose(bgTrackImage);
1296 Utility.Dispose(lowIndicatorImage);
1297 Utility.Dispose(highIndicatorImage);
1298 Utility.Dispose(lowIndicatorText);
1299 Utility.Dispose(highIndicatorText);
1300 Utility.Dispose(valueIndicatorImage);
1301 Utility.Dispose(valueIndicatorText);
1308 /// Update Slider by style.
1310 /// <since_tizen> 6 </since_tizen>
1311 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1312 [EditorBrowsable(EditorBrowsableState.Never)]
1313 protected override void OnUpdate()
1315 RelayoutBaseComponent();
1317 UpdateComponentByIndicatorTypeChanged();
1318 UpdateBgTrackSize();
1319 UpdateBgTrackPosition();
1320 UpdateWarningTrackSize();
1321 UpdateLowIndicatorSize();
1325 private void CalculateCurrentValueByGesture(float offset)
1327 currentSlidedOffset += offset;
1329 if (currentSlidedOffset <= 0)
1331 curValue = minValue;
1333 else if (currentSlidedOffset >= BgTrackLength())
1335 curValue = maxValue;
1339 int bgTrackLength = BgTrackLength();
1340 if (bgTrackLength != 0)
1342 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1345 if (valueChangedHandler != null)
1347 ValueChangedArgs args = new ValueChangedArgs();
1348 args.CurrentValue = curValue;
1349 valueChangedHandler(this, args);
1352 if (sliderValueChangedHandler != null)
1354 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1355 args.CurrentValue = curValue;
1356 sliderValueChangedHandler(this, args);
1360 private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
1362 PointStateType state = e.Touch.GetState(0);
1363 if (state == PointStateType.Down)
1367 valueIndicatorImage.Show();
1370 Vector2 pos = e.Touch.GetLocalPosition(0);
1371 CalculateCurrentValueByTouch(pos);
1373 if (null != slidingFinishedHandler)
1375 SlidingFinishedArgs args = new SlidingFinishedArgs();
1376 args.CurrentValue = curValue;
1377 slidingFinishedHandler(this, args);
1380 if (null != sliderSlidingFinishedHandler)
1382 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
1383 args.CurrentValue = curValue;
1384 sliderSlidingFinishedHandler(this, args);
1387 else if (state == PointStateType.Up)
1391 valueIndicatorImage.Hide();
1397 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1399 PointStateType state = e.Touch.GetState(0);
1400 if (state == PointStateType.Down)
1402 UpdateState(isFocused, true);
1404 else if (state == PointStateType.Up)
1406 UpdateState(isFocused, false);
1411 private void CalculateCurrentValueByTouch(Vector2 pos)
1413 int bgTrackLength = BgTrackLength();
1414 if (direction == DirectionType.Horizontal)
1416 currentSlidedOffset = pos.X;
1418 else if (direction == DirectionType.Vertical)
1420 currentSlidedOffset = bgTrackLength - pos.Y;
1423 if (bgTrackLength != 0)
1425 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1426 if (null != valueChangedHandler)
1428 ValueChangedArgs args = new ValueChangedArgs();
1429 args.CurrentValue = curValue;
1430 valueChangedHandler(this, args);
1433 if (null != sliderValueChangedHandler)
1435 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1436 args.CurrentValue = curValue;
1437 sliderValueChangedHandler(this, args);
1442 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1444 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1448 if (thumbImage == null || Style == null)
1452 isFocused = isFocusedNew;
1453 isPressed = isPressedNew;
1455 if (!isFocused && !isPressed)
1457 ControlState = ControlState.Normal;
1458 thumbImage.ResourceUrl = thumbImageUrlSelector?.Normal;
1460 if (stateChangedHandler != null)
1462 StateChangedArgs args = new StateChangedArgs();
1463 args.CurrentState = (ControlStates)ControlStates.Normal;
1464 stateChangedHandler(this, args);
1469 ControlState = ControlState.Pressed;
1470 thumbImage.ResourceUrl = thumbImageUrlSelector?.Pressed;
1472 if (stateChangedHandler != null)
1474 StateChangedArgs args = new StateChangedArgs();
1475 args.CurrentState = (ControlStates)ControlStates.Pressed;
1476 stateChangedHandler(this, args);
1479 else if (!isPressed && isFocused)
1481 ControlState = ControlState.Focused;
1482 thumbImage.ResourceUrl = thumbImageUrlSelector?.Focused;
1484 if (stateChangedHandler != null)
1486 StateChangedArgs args = new StateChangedArgs();
1487 args.CurrentState = (ControlStates)ControlStates.Focused;
1488 stateChangedHandler(this, args);
1493 private void UpdateComponentByIndicatorTypeChanged()
1495 IndicatorType type = CurrentIndicatorType();
1496 if (type == IndicatorType.None)
1498 if (lowIndicatorImage != null)
1500 lowIndicatorImage.Hide();
1502 if (highIndicatorImage != null)
1504 highIndicatorImage.Hide();
1506 if (lowIndicatorText != null)
1508 lowIndicatorText.Hide();
1510 if (highIndicatorText != null)
1512 highIndicatorText.Hide();
1515 else if (type == IndicatorType.Image)
1517 if (lowIndicatorImage != null)
1519 lowIndicatorImage.Show();
1521 if (highIndicatorImage != null)
1523 highIndicatorImage.Show();
1525 if (lowIndicatorText != null)
1527 lowIndicatorText.Hide();
1529 if (highIndicatorText != null)
1531 highIndicatorText.Hide();
1534 else if (type == IndicatorType.Text)
1536 if (lowIndicatorText != null)
1538 lowIndicatorText.Show();
1540 if (highIndicatorText != null)
1542 highIndicatorText.Show();
1544 if (lowIndicatorImage != null)
1546 lowIndicatorImage.Hide();
1548 if (highIndicatorImage != null)
1550 highIndicatorImage.Hide();
1556 /// Value Changed event data.
1558 /// <since_tizen> 6 </since_tizen>
1559 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
1560 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1561 public class ValueChangedArgs : EventArgs
1566 /// <since_tizen> 6 </since_tizen>
1567 /// It will be removed in API10
1568 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1569 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
1570 public float CurrentValue;
1574 /// Value Changed event data.
1576 /// <since_tizen> 6 </since_tizen>
1577 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
1578 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1579 public class SlidingFinishedArgs : EventArgs
1584 /// <since_tizen> 6 </since_tizen>
1585 /// It will be removed in API10
1586 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1587 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
1588 public float CurrentValue;
1592 /// State Changed event data.
1594 /// <since_tizen> 6 </since_tizen>
1595 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
1596 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1597 public class StateChangedArgs : EventArgs
1602 /// <since_tizen> 6 </since_tizen>
1603 /// It will be removed in API10
1604 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1605 [Obsolete("Deprecated in API8; Will be removed in API10")]
1606 public ControlStates CurrentState;