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;
158 defaultValueCreator: (bindable) =>
160 var instance = (Slider)bindable;
161 return instance.valueIndicatorText.Text;
165 /// Bindable property of CurrentValue
167 /// Hidden API, used for NUI XAML data binding
170 [EditorBrowsable(EditorBrowsableState.Never)]
171 public static readonly BindableProperty CurrentValueProperty = BindableProperty.Create(nameof(CurrentValue), typeof(float), typeof(Slider), 0.0f, BindingMode.TwoWay,
172 propertyChanged: (bindable, oldValue, newValue) =>
174 var instance = (Slider)bindable;
176 if (newValue != null)
178 instance.curValue = (float)newValue;
179 if (instance.IsHighlighted)
181 instance.EmitAccessibilityEvent(ObjectPropertyChangeEvent.Value);
183 instance.UpdateValue();
186 defaultValueCreator: (bindable) =>
188 var instance = (Slider)bindable;
189 return instance.curValue;
196 /// The constructor of the Slider class.
198 /// <since_tizen> 6 </since_tizen>
205 /// The constructor of the Slider class with specific style.
207 /// <param name="style">The string to initialize the Slider</param>
208 /// <since_tizen> 8 </since_tizen>
209 public Slider(string style) : base(style)
215 /// The constructor of the Slider class with specific style.
217 /// <param name="sliderStyle">The style object to initialize the Slider</param>
218 /// <since_tizen> 8 </since_tizen>
219 public Slider(SliderStyle sliderStyle) : base(sliderStyle)
225 /// The value changed event handler.
227 /// <since_tizen> 6 </since_tizen>
228 [Obsolete("Deprecated in API8; Will be removed in API10. Please use ValueChanged event instead.")]
229 public event EventHandler<ValueChangedArgs> ValueChangedEvent
233 valueChangedHandler += value;
237 valueChangedHandler -= value;
242 /// The sliding finished event handler.
244 /// <since_tizen> 6 </since_tizen>
245 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SlidingFinished event instead.")]
246 public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
250 slidingFinishedHandler += value;
254 slidingFinishedHandler -= value;
259 /// The value changed event handler.
261 /// <since_tizen> 8 </since_tizen>
262 public event EventHandler<SliderValueChangedEventArgs> ValueChanged
266 sliderValueChangedHandler += value;
270 sliderValueChangedHandler -= value;
275 /// The sliding started event handler.
277 /// <since_tizen> 8 </since_tizen>
278 public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
282 sliderSlidingStartedHandler += value;
286 sliderSlidingStartedHandler -= value;
291 /// The sliding finished event handler.
293 /// <since_tizen> 8 </since_tizen>
294 public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
298 sliderSlidingFinishedHandler += value;
302 sliderSlidingFinishedHandler -= value;
307 /// The state changed event handler.
309 /// <since_tizen> 6 </since_tizen>
310 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
311 public event EventHandler<StateChangedArgs> StateChangedEvent
315 stateChangedHandler += value;
319 stateChangedHandler -= value;
324 /// The direction type of slider.
326 /// <since_tizen> 6 </since_tizen>
327 public enum DirectionType
330 /// The Horizontal type.
332 /// <since_tizen> 6 </since_tizen>
336 /// The Vertical type.
338 /// <since_tizen> 6 </since_tizen>
343 /// The indicator type of slider.
345 /// <since_tizen> 6 </since_tizen>
346 public enum IndicatorType
348 /// <summary> Only contains slider bar.</summary>
349 /// <since_tizen> 6 </since_tizen>
352 /// <summary> Contains slider bar, IndicatorImage.</summary>
353 /// <since_tizen> 6 </since_tizen>
356 /// <summary> Contains slider bar, IndicatorText.</summary>
357 /// <since_tizen> 6 </since_tizen>
362 /// Return currently applied style.
365 /// Modifying contents in style may cause unexpected behaviour.
367 /// <since_tizen> 8 </since_tizen>
368 public SliderStyle Style => (SliderStyle)(ViewStyle as SliderStyle)?.Clone();
371 /// Gets or sets the direction type of slider.
373 /// <since_tizen> 6 </since_tizen>
374 public DirectionType Direction
382 if (direction == value)
387 RelayoutBaseComponent(false);
389 UpdateBgTrackPosition();
390 UpdateWarningTrackSize();
396 /// Gets or sets the indicator type, arrow or sign.
398 /// <since_tizen> 6 </since_tizen>
399 public IndicatorType Indicator
403 return (IndicatorType)GetValue(IndicatorTypeProperty);
407 SetValue(IndicatorTypeProperty, value);
412 /// Gets or sets the minimum value of slider.
414 /// <since_tizen> 6 </since_tizen>
415 public float MinValue
429 /// Gets or sets the maximum value of slider.
431 /// <since_tizen> 6 </since_tizen>
432 public float MaxValue
446 /// Gets or sets the current value of slider.
448 /// <since_tizen> 6 </since_tizen>
449 public float CurrentValue
453 return (float)GetValue(CurrentValueProperty);
457 SetValue(CurrentValueProperty, value);
462 /// Gets or sets the size of the thumb image object.
464 /// <since_tizen> 6 </since_tizen>
465 public Size ThumbSize
469 return thumbImage?.Size;
473 if (null != thumbImage)
475 thumbImage.Size = value;
482 /// Gets or sets the resource url of the thumb image object.
484 /// Please use ThumbImageUrl property.
486 /// <since_tizen> 6 </since_tizen>
487 public string ThumbImageURL
491 return thumbImage?.ResourceUrl;
495 if (null != thumbImage)
497 thumbImage.ResourceUrl = value;
498 thumbImageUrl = value;
504 /// Gets or sets the resource url selector of the thumb image object.
505 /// Getter returns copied selector value if exist, null otherwise.
507 /// Please use ThumbImageUrl property.
509 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
510 /// <since_tizen> 6 </since_tizen>
511 public StringSelector ThumbImageURLSelector
513 get => thumbImage == null ? null : new StringSelector(thumbImage.ResourceUrlSelector);
516 if (value == null || thumbImage == null)
518 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
522 thumbImage.ResourceUrlSelector = value;
523 thumbImageUrlSelector = value;
529 /// Gets or sets the Url of the thumb image.
531 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
532 /// <since_tizen> 9 </since_tizen>
533 public Selector<string> ThumbImageUrl
537 if (thumbImage == null)
543 return thumbImage.ResourceUrlSelector;
548 if (value == null || thumbImage == null)
550 throw new NullReferenceException("Slider.ThumbImageUrl is null");
554 thumbImage.ResourceUrlSelector = value;
555 thumbImageUrlSelector = value;
561 /// Gets or sets the color of the thumb image object.
563 /// <since_tizen> 8 </since_tizen>
564 public Color ThumbColor
568 return thumbImage?.Color;
572 if (null != thumbImage)
574 thumbImage.BackgroundColor = value;
581 /// Gets or sets the color of the background track image object.
583 /// <since_tizen> 6 </since_tizen>
584 public Color BgTrackColor
588 return bgTrackImage?.BackgroundColor;
592 if (null != bgTrackImage)
594 bgTrackImage.BackgroundColor = value;
600 /// Gets or sets the color of the slided track image object.
602 /// <since_tizen> 6 </since_tizen>
603 public Color SlidedTrackColor
607 return slidedTrackImage?.BackgroundColor;
611 if (null != slidedTrackImage)
613 slidedTrackImage.BackgroundColor = value;
619 /// Gets or sets the thickness value of the track.
621 /// <since_tizen> 6 </since_tizen>
622 public uint TrackThickness
626 return (uint)GetValue(TrackThicknessProperty);
630 SetValue(TrackThicknessProperty, value);
635 /// Gets or sets the warning start value between minimum value and maximum value of slider.
637 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
638 [EditorBrowsable(EditorBrowsableState.Never)]
639 public float WarningStartValue
643 return warningStartValue;
647 warningStartValue = value;
653 /// Gets or sets the color of the warning track image object.
655 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
656 [EditorBrowsable(EditorBrowsableState.Never)]
657 public Color WarningTrackColor
661 return warningTrackImage?.BackgroundColor;
665 if (null != warningTrackImage)
667 warningTrackImage.BackgroundColor = value;
673 /// Gets or sets the color of the warning slided track image object.
675 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
676 [EditorBrowsable(EditorBrowsableState.Never)]
677 public Color WarningSlidedTrackColor
681 return warningSlidedTrackImage?.BackgroundColor;
685 if (null != warningSlidedTrackImage)
687 warningSlidedTrackImage.BackgroundColor = value;
693 /// Gets or sets the Url of the warning thumb image.
695 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
696 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
697 [EditorBrowsable(EditorBrowsableState.Never)]
698 public Selector<string> WarningThumbImageUrl
702 return warningThumbImageUrlSelector;
706 if (value == null || thumbImage == null)
708 throw new NullReferenceException("Slider.WarningThumbImageUrl is null");
712 warningThumbImageUrlSelector = value;
718 /// Gets or sets the color of the warning thumb image object.
720 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
721 [EditorBrowsable(EditorBrowsableState.Never)]
722 public Color WarningThumbColor
726 return warningThumbColor;
730 warningThumbColor = value;
735 /// Gets or sets the resource url of the low indicator image object.
737 /// <since_tizen> 6 </since_tizen>
738 public string LowIndicatorImageURL
742 return lowIndicatorImage?.ResourceUrl;
746 if (null == lowIndicatorImage) lowIndicatorImage = new ImageView();
747 lowIndicatorImage.ResourceUrl = value;
752 /// Gets or sets the resource url of the high indicator image object.
754 /// <since_tizen> 6 </since_tizen>
755 public string HighIndicatorImageURL
759 return highIndicatorImage?.ResourceUrl;
763 if (null == highIndicatorImage) highIndicatorImage = new ImageView();
764 highIndicatorImage.ResourceUrl = value;
769 /// Gets or sets the text content of the low indicator text object.
771 /// <since_tizen> 6 </since_tizen>
772 public string LowIndicatorTextContent
776 return lowIndicatorText?.Text;
780 if (null != lowIndicatorText)
782 lowIndicatorText.Text = value;
788 /// Gets or sets the text content of the high indicator text object.
790 /// <since_tizen> 6 </since_tizen>
791 public string HighIndicatorTextContent
795 return highIndicatorText?.Text;
799 if (null != highIndicatorText)
801 highIndicatorText.Text = value;
807 /// Gets or sets the size of the low indicator object(image or text).
809 /// <since_tizen> 6 </since_tizen>
810 public Size LowIndicatorSize
814 return lowIndicatorSize;
818 lowIndicatorSize = value;
819 UpdateLowIndicatorSize();
821 UpdateBgTrackPosition();
827 /// Gets or sets the size of the high indicator object(image or text).
829 /// <since_tizen> 6 </since_tizen>
830 public Size HighIndicatorSize
834 return highIndicatorText?.Size;
838 if (null != highIndicatorText)
840 highIndicatorText.Size = value;
846 /// Gets or sets the value of the space between track and indicator.
848 /// <since_tizen> 6 </since_tizen>
849 public uint SpaceBetweenTrackAndIndicator
853 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
857 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
862 /// Flag to decide whether the value indicator is shown
864 /// <since_tizen> 9 </since_tizen>
865 public bool IsValueShown
869 return (bool)GetValue(IsValueShownProperty);
873 SetValue(IsValueShownProperty, value);
878 /// Gets or sets the text of value indicator.
880 /// <since_tizen> 9 </since_tizen>
881 public string ValueIndicatorText
885 return (string)GetValue(ValueIndicatorTextProperty);
889 SetValue(ValueIndicatorTextProperty, value);
894 /// Gets or sets the size of the value indicator image object.
896 /// <since_tizen> 9 </since_tizen>
897 public Size ValueIndicatorSize
901 return valueIndicatorImage?.Size;
905 if (null != valueIndicatorImage)
907 valueIndicatorImage.Size = value;
913 /// Gets or sets the resource url of the value indicator image object.
915 /// <since_tizen> 9 </since_tizen>
916 public string ValueIndicatorUrl
920 return valueIndicatorImage?.ResourceUrl;
924 if (null != valueIndicatorImage)
926 valueIndicatorImage.ResourceUrl = value;
932 /// Flag to decide whether the thumb snap to the nearest discrete value when the user drags the thumb or taps.
934 /// The default value is false.
936 /// <since_tizen> 9 </since_tizen>
937 public bool IsDiscrete { get; set; } = false;
940 /// Gets or sets the discrete value of slider.
942 /// The discrete value is evenly spaced between MinValue and MaxValue.
943 /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
944 /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
945 /// The default is 0.
947 /// <since_tizen> 9 </since_tizen>
948 public float DiscreteValue
952 return discreteValue;
956 discreteValue = value;
961 private Extents spaceBetweenTrackAndIndicator
965 if (null == spaceTrackIndicator)
967 spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
969 Extents extents = new Extents(start, end, top, bottom);
970 spaceTrackIndicator.CopyFrom(extents);
974 return spaceTrackIndicator;
978 private IndicatorType privateIndicatorType
982 return indicatorType;
986 if (indicatorType == value)
990 indicatorType = value;
991 RelayoutBaseComponent(false);
993 UpdateBgTrackPosition();
998 private uint privateTrackThickness
1002 return trackThickness ?? 0;
1006 trackThickness = value;
1007 if (bgTrackImage != null)
1009 if (direction == DirectionType.Horizontal)
1011 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1013 else if (direction == DirectionType.Vertical)
1015 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1018 if (slidedTrackImage != null)
1020 if (direction == DirectionType.Horizontal)
1022 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1024 else if (direction == DirectionType.Vertical)
1026 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1029 if (warningTrackImage != null)
1031 if (direction == DirectionType.Horizontal)
1033 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1035 else if (direction == DirectionType.Vertical)
1037 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1040 if (warningSlidedTrackImage != null)
1042 if (direction == DirectionType.Horizontal)
1044 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1046 else if (direction == DirectionType.Vertical)
1048 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1054 private uint privateSpaceBetweenTrackAndIndicator
1058 return privateTrackPadding.Start;
1062 ushort val = (ushort)value;
1063 privateTrackPadding = new Extents(val, val, val, val);
1067 private Extents privateTrackPadding
1071 return spaceBetweenTrackAndIndicator;
1075 spaceBetweenTrackAndIndicator.CopyFrom(value);
1076 UpdateComponentByIndicatorTypeChanged();
1077 UpdateBgTrackSize();
1078 UpdateBgTrackPosition();
1084 /// Focus gained callback.
1086 /// <since_tizen> 8 </since_tizen>
1087 public override void OnFocusGained()
1089 //State = ControlStates.Focused;
1090 UpdateState(true, isPressed);
1091 base.OnFocusGained();
1095 /// Focus Lost callback.
1097 /// <since_tizen> 8 </since_tizen>
1098 public override void OnFocusLost()
1100 //State = ControlStates.Normal;
1101 UpdateState(false, isPressed);
1106 /// Apply style to scrollbar.
1108 /// <param name="viewStyle">The style to apply.</param>
1109 /// <since_tizen> 8 </since_tizen>
1110 public override void ApplyStyle(ViewStyle viewStyle)
1112 base.ApplyStyle(viewStyle);
1114 SliderStyle sliderStyle = viewStyle as SliderStyle;
1116 if (null != sliderStyle?.Progress)
1118 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1121 if (null != sliderStyle?.LowIndicator)
1123 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1126 if (null != sliderStyle?.HighIndicator)
1128 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1131 if (null != sliderStyle?.Track)
1133 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1136 if (null != sliderStyle?.Thumb)
1138 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1141 if (null != sliderStyle?.ValueIndicatorText)
1143 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1146 if (null != sliderStyle?.ValueIndicatorImage)
1148 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1151 if (null != sliderStyle?.WarningTrack)
1153 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1156 if (null != sliderStyle?.WarningProgress)
1158 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1161 EnableControlStatePropagation = true;
1165 /// Prevents from showing child widgets in AT-SPI tree.
1167 [EditorBrowsable(EditorBrowsableState.Never)]
1168 protected override bool AccessibilityShouldReportZeroChildren()
1176 [EditorBrowsable(EditorBrowsableState.Never)]
1177 protected override double AccessibilityGetMinimum()
1179 return (double)MinValue;
1185 [EditorBrowsable(EditorBrowsableState.Never)]
1186 protected override double AccessibilityGetCurrent()
1188 return (double)CurrentValue;
1194 [EditorBrowsable(EditorBrowsableState.Never)]
1195 protected override double AccessibilityGetMaximum()
1197 return (double)MaxValue;
1203 [EditorBrowsable(EditorBrowsableState.Never)]
1204 protected override bool AccessibilitySetCurrent(double value)
1206 var f = (float)value;
1208 if (f >= MinValue && f <= MaxValue)
1211 if (sliderValueChangedHandler != null)
1213 sliderValueChangedHandler(this, new SliderValueChangedEventArgs { CurrentValue = f });
1222 /// Minimum increment.
1224 [EditorBrowsable(EditorBrowsableState.Never)]
1225 protected override double AccessibilityGetMinimumIncrement()
1228 return (MaxValue - MinValue) / 20.0;
1232 /// Initialize AT-SPI object.
1234 [EditorBrowsable(EditorBrowsableState.Never)]
1235 public override void OnInitialize()
1237 base.OnInitialize();
1238 SetAccessibilityConstructor(Role.Slider, AccessibilityInterface.Value);
1242 /// Get Slider style.
1244 /// <returns>The default slider style.</returns>
1245 /// <since_tizen> 8 </since_tizen>
1246 protected override ViewStyle CreateViewStyle()
1248 return new SliderStyle();
1254 /// <param name="type">Dispose type.</param>
1255 /// <since_tizen> 6 </since_tizen>
1256 protected override void Dispose(DisposeTypes type)
1263 if (type == DisposeTypes.Explicit)
1265 if (null != panGestureDetector)
1267 panGestureDetector.Detach(this);
1268 panGestureDetector.Detected -= OnPanGestureDetected;
1269 panGestureDetector.Dispose();
1270 panGestureDetector = null;
1273 if (null != thumbImage)
1275 thumbImage.TouchEvent -= OnTouchEventForThumb;
1276 Utility.Dispose(thumbImage);
1278 Utility.Dispose(warningSlidedTrackImage);
1279 Utility.Dispose(warningTrackImage);
1280 Utility.Dispose(slidedTrackImage);
1281 if (null != bgTrackImage)
1283 bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
1284 Utility.Dispose(bgTrackImage);
1286 Utility.Dispose(lowIndicatorImage);
1287 Utility.Dispose(highIndicatorImage);
1288 Utility.Dispose(lowIndicatorText);
1289 Utility.Dispose(highIndicatorText);
1290 Utility.Dispose(valueIndicatorImage);
1291 Utility.Dispose(valueIndicatorText);
1298 /// Update Slider by style.
1300 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1301 [EditorBrowsable(EditorBrowsableState.Never)]
1302 protected override void OnUpdate()
1304 RelayoutBaseComponent();
1306 UpdateComponentByIndicatorTypeChanged();
1307 UpdateBgTrackSize();
1308 UpdateBgTrackPosition();
1309 UpdateWarningTrackSize();
1310 UpdateLowIndicatorSize();
1314 private void CalculateCurrentValueByGesture(float offset)
1316 currentSlidedOffset += offset;
1318 if (currentSlidedOffset <= 0)
1320 this.CurrentValue = minValue;
1322 else if (currentSlidedOffset >= BgTrackLength())
1324 this.CurrentValue = maxValue;
1328 int bgTrackLength = BgTrackLength();
1329 if (bgTrackLength != 0)
1331 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1337 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1340 if (valueChangedHandler != null)
1342 ValueChangedArgs args = new ValueChangedArgs();
1343 args.CurrentValue = this.CurrentValue;
1344 valueChangedHandler(this, args);
1347 if (sliderValueChangedHandler != null)
1349 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1350 args.CurrentValue = this.CurrentValue;
1351 sliderValueChangedHandler(this, args);
1355 private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
1357 PointStateType state = e.Touch.GetState(0);
1358 if (state == PointStateType.Down)
1362 valueIndicatorImage.Show();
1365 Vector2 pos = e.Touch.GetLocalPosition(0);
1366 CalculateCurrentValueByTouch(pos);
1368 if (null != slidingFinishedHandler)
1370 SlidingFinishedArgs args = new SlidingFinishedArgs();
1371 args.CurrentValue = curValue;
1372 slidingFinishedHandler(this, args);
1375 if (null != sliderSlidingFinishedHandler)
1377 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
1378 args.CurrentValue = curValue;
1379 sliderSlidingFinishedHandler(this, args);
1382 else if (state == PointStateType.Up)
1386 valueIndicatorImage.Hide();
1392 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1394 PointStateType state = e.Touch.GetState(0);
1395 if (state == PointStateType.Down)
1397 UpdateState(isFocused, true);
1399 else if (state == PointStateType.Up)
1401 UpdateState(isFocused, false);
1406 private void CalculateCurrentValueByTouch(Vector2 pos)
1408 int bgTrackLength = BgTrackLength();
1409 if (direction == DirectionType.Horizontal)
1411 currentSlidedOffset = pos.X;
1413 else if (direction == DirectionType.Vertical)
1415 currentSlidedOffset = bgTrackLength - pos.Y;
1418 if (bgTrackLength != 0)
1420 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1424 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1427 if (null != valueChangedHandler)
1429 ValueChangedArgs args = new ValueChangedArgs();
1430 args.CurrentValue = this.CurrentValue;
1431 valueChangedHandler(this, args);
1434 if (null != sliderValueChangedHandler)
1436 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1437 args.CurrentValue = this.CurrentValue;
1438 sliderValueChangedHandler(this, args);
1443 private float CalculateDiscreteValue(float value)
1445 return ((float)Math.Round((value / discreteValue)) * discreteValue);
1448 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1450 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1454 if (thumbImage == null || Style == null)
1458 isFocused = isFocusedNew;
1459 isPressed = isPressedNew;
1461 if (!isFocused && !isPressed)
1463 ControlState = ControlState.Normal;
1464 thumbImage.ResourceUrl = thumbImageUrlSelector?.Normal;
1466 if (stateChangedHandler != null)
1468 StateChangedArgs args = new StateChangedArgs();
1469 args.CurrentState = (ControlStates)ControlStates.Normal;
1470 stateChangedHandler(this, args);
1475 ControlState = ControlState.Pressed;
1476 thumbImage.ResourceUrl = thumbImageUrlSelector?.Pressed;
1478 if (stateChangedHandler != null)
1480 StateChangedArgs args = new StateChangedArgs();
1481 args.CurrentState = (ControlStates)ControlStates.Pressed;
1482 stateChangedHandler(this, args);
1485 else if (!isPressed && isFocused)
1487 ControlState = ControlState.Focused;
1488 thumbImage.ResourceUrl = thumbImageUrlSelector?.Focused;
1490 if (stateChangedHandler != null)
1492 StateChangedArgs args = new StateChangedArgs();
1493 args.CurrentState = (ControlStates)ControlStates.Focused;
1494 stateChangedHandler(this, args);
1499 private void UpdateComponentByIndicatorTypeChanged()
1501 IndicatorType type = CurrentIndicatorType();
1502 if (type == IndicatorType.None)
1504 if (lowIndicatorImage != null)
1506 lowIndicatorImage.Hide();
1508 if (highIndicatorImage != null)
1510 highIndicatorImage.Hide();
1512 if (lowIndicatorText != null)
1514 lowIndicatorText.Hide();
1516 if (highIndicatorText != null)
1518 highIndicatorText.Hide();
1521 else if (type == IndicatorType.Image)
1523 if (lowIndicatorImage != null)
1525 lowIndicatorImage.Show();
1527 if (highIndicatorImage != null)
1529 highIndicatorImage.Show();
1531 if (lowIndicatorText != null)
1533 lowIndicatorText.Hide();
1535 if (highIndicatorText != null)
1537 highIndicatorText.Hide();
1540 else if (type == IndicatorType.Text)
1542 if (lowIndicatorText != null)
1544 lowIndicatorText.Show();
1546 if (highIndicatorText != null)
1548 highIndicatorText.Show();
1550 if (lowIndicatorImage != null)
1552 lowIndicatorImage.Hide();
1554 if (highIndicatorImage != null)
1556 highIndicatorImage.Hide();
1562 /// Value Changed event data.
1564 /// <since_tizen> 6 </since_tizen>
1565 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
1566 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1567 public class ValueChangedArgs : EventArgs
1572 /// <since_tizen> 6 </since_tizen>
1573 /// It will be removed in API10
1574 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1575 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
1576 public float CurrentValue;
1580 /// Value Changed event data.
1582 /// <since_tizen> 6 </since_tizen>
1583 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
1584 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1585 public class SlidingFinishedArgs : EventArgs
1590 /// <since_tizen> 6 </since_tizen>
1591 /// It will be removed in API10
1592 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1593 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
1594 public float CurrentValue;
1598 /// State Changed event data.
1600 /// <since_tizen> 6 </since_tizen>
1601 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
1602 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1603 public class StateChangedArgs : EventArgs
1608 /// <since_tizen> 6 </since_tizen>
1609 /// It will be removed in API10
1610 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1611 [Obsolete("Deprecated in API8; Will be removed in API10")]
1612 public ControlStates CurrentState;