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.
943 /// The discrete value is evenly spaced between MinValue and MaxValue.
944 /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
945 /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
946 /// The default is 0.
948 /// <since_tizen> 9 </since_tizen>
949 public float DiscreteValue
953 return discreteValue;
957 discreteValue = value;
962 private Extents spaceBetweenTrackAndIndicator
966 if (null == spaceTrackIndicator)
968 spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
970 Extents extents = new Extents(start, end, top, bottom);
971 spaceTrackIndicator.CopyFrom(extents);
975 return spaceTrackIndicator;
979 private IndicatorType privateIndicatorType
983 return indicatorType;
987 if (indicatorType == value)
991 indicatorType = value;
992 RelayoutBaseComponent(false);
994 UpdateBgTrackPosition();
999 private uint privateTrackThickness
1003 return trackThickness ?? 0;
1007 trackThickness = value;
1008 if (bgTrackImage != null)
1010 if (direction == DirectionType.Horizontal)
1012 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1014 else if (direction == DirectionType.Vertical)
1016 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1019 if (slidedTrackImage != null)
1021 if (direction == DirectionType.Horizontal)
1023 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1025 else if (direction == DirectionType.Vertical)
1027 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1030 if (warningTrackImage != null)
1032 if (direction == DirectionType.Horizontal)
1034 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1036 else if (direction == DirectionType.Vertical)
1038 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1041 if (warningSlidedTrackImage != null)
1043 if (direction == DirectionType.Horizontal)
1045 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1047 else if (direction == DirectionType.Vertical)
1049 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1055 private uint privateSpaceBetweenTrackAndIndicator
1059 return privateTrackPadding.Start;
1063 ushort val = (ushort)value;
1064 privateTrackPadding = new Extents(val, val, val, val);
1068 private Extents privateTrackPadding
1072 return spaceBetweenTrackAndIndicator;
1076 spaceBetweenTrackAndIndicator.CopyFrom(value);
1077 UpdateComponentByIndicatorTypeChanged();
1078 UpdateBgTrackSize();
1079 UpdateBgTrackPosition();
1085 /// Focus gained callback.
1087 /// <since_tizen> 8 </since_tizen>
1088 public override void OnFocusGained()
1090 //State = ControlStates.Focused;
1091 UpdateState(true, isPressed);
1092 base.OnFocusGained();
1096 /// Focus Lost callback.
1098 /// <since_tizen> 8 </since_tizen>
1099 public override void OnFocusLost()
1101 //State = ControlStates.Normal;
1102 UpdateState(false, isPressed);
1107 /// Apply style to scrollbar.
1109 /// <param name="viewStyle">The style to apply.</param>
1110 /// <since_tizen> 8 </since_tizen>
1111 public override void ApplyStyle(ViewStyle viewStyle)
1113 base.ApplyStyle(viewStyle);
1115 SliderStyle sliderStyle = viewStyle as SliderStyle;
1117 if (null != sliderStyle?.Progress)
1119 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1122 if (null != sliderStyle?.LowIndicator)
1124 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1127 if (null != sliderStyle?.HighIndicator)
1129 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1132 if (null != sliderStyle?.Track)
1134 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1137 if (null != sliderStyle?.Thumb)
1139 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1142 if (null != sliderStyle?.ValueIndicatorText)
1144 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1147 if (null != sliderStyle?.ValueIndicatorImage)
1149 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1152 if (null != sliderStyle?.WarningTrack)
1154 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1157 if (null != sliderStyle?.WarningProgress)
1159 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1162 EnableControlStatePropagation = true;
1166 /// Prevents from showing child widgets in AT-SPI tree.
1168 [EditorBrowsable(EditorBrowsableState.Never)]
1169 protected override bool AccessibilityShouldReportZeroChildren()
1177 [EditorBrowsable(EditorBrowsableState.Never)]
1178 protected override double AccessibilityGetMinimum()
1180 return (double)MinValue;
1186 [EditorBrowsable(EditorBrowsableState.Never)]
1187 protected override double AccessibilityGetCurrent()
1189 return (double)CurrentValue;
1195 [EditorBrowsable(EditorBrowsableState.Never)]
1196 protected override double AccessibilityGetMaximum()
1198 return (double)MaxValue;
1204 [EditorBrowsable(EditorBrowsableState.Never)]
1205 protected override bool AccessibilitySetCurrent(double value)
1207 var f = (float)value;
1209 if (f >= MinValue && f <= MaxValue)
1212 if (sliderValueChangedHandler != null)
1214 sliderValueChangedHandler(this, new SliderValueChangedEventArgs { CurrentValue = f });
1223 /// Minimum increment.
1225 [EditorBrowsable(EditorBrowsableState.Never)]
1226 protected override double AccessibilityGetMinimumIncrement()
1229 return (MaxValue - MinValue) / 20.0;
1233 /// Initialize AT-SPI object.
1235 [EditorBrowsable(EditorBrowsableState.Never)]
1236 public override void OnInitialize()
1238 base.OnInitialize();
1239 SetAccessibilityConstructor(Role.Slider, AccessibilityInterface.Value);
1243 /// Get Slider style.
1245 /// <returns>The default slider style.</returns>
1246 /// <since_tizen> 8 </since_tizen>
1247 protected override ViewStyle CreateViewStyle()
1249 return new SliderStyle();
1255 /// <param name="type">Dispose type.</param>
1256 /// <since_tizen> 6 </since_tizen>
1257 protected override void Dispose(DisposeTypes type)
1264 if (type == DisposeTypes.Explicit)
1266 if (null != panGestureDetector)
1268 panGestureDetector.Detach(this);
1269 panGestureDetector.Detected -= OnPanGestureDetected;
1270 panGestureDetector.Dispose();
1271 panGestureDetector = null;
1274 if (null != thumbImage)
1276 thumbImage.TouchEvent -= OnTouchEventForThumb;
1277 Utility.Dispose(thumbImage);
1279 Utility.Dispose(warningSlidedTrackImage);
1280 Utility.Dispose(warningTrackImage);
1281 Utility.Dispose(slidedTrackImage);
1282 if (null != bgTrackImage)
1284 bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
1285 Utility.Dispose(bgTrackImage);
1287 Utility.Dispose(lowIndicatorImage);
1288 Utility.Dispose(highIndicatorImage);
1289 Utility.Dispose(lowIndicatorText);
1290 Utility.Dispose(highIndicatorText);
1291 Utility.Dispose(valueIndicatorImage);
1292 Utility.Dispose(valueIndicatorText);
1299 /// Update Slider by style.
1301 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1302 [EditorBrowsable(EditorBrowsableState.Never)]
1303 protected override void OnUpdate()
1305 RelayoutBaseComponent();
1307 UpdateComponentByIndicatorTypeChanged();
1308 UpdateBgTrackSize();
1309 UpdateBgTrackPosition();
1310 UpdateWarningTrackSize();
1311 UpdateLowIndicatorSize();
1315 private void CalculateCurrentValueByGesture(float offset)
1317 currentSlidedOffset += offset;
1319 if (currentSlidedOffset <= 0)
1321 this.CurrentValue = minValue;
1323 else if (currentSlidedOffset >= BgTrackLength())
1325 this.CurrentValue = maxValue;
1329 int bgTrackLength = BgTrackLength();
1330 if (bgTrackLength != 0)
1332 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1338 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1341 if (valueChangedHandler != null)
1343 ValueChangedArgs args = new ValueChangedArgs();
1344 args.CurrentValue = this.CurrentValue;
1345 valueChangedHandler(this, args);
1348 if (sliderValueChangedHandler != null)
1350 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1351 args.CurrentValue = this.CurrentValue;
1352 sliderValueChangedHandler(this, args);
1356 private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
1358 PointStateType state = e.Touch.GetState(0);
1359 if (state == PointStateType.Down)
1363 valueIndicatorImage.Show();
1366 Vector2 pos = e.Touch.GetLocalPosition(0);
1367 CalculateCurrentValueByTouch(pos);
1369 if (null != slidingFinishedHandler)
1371 SlidingFinishedArgs args = new SlidingFinishedArgs();
1372 args.CurrentValue = curValue;
1373 slidingFinishedHandler(this, args);
1376 if (null != sliderSlidingFinishedHandler)
1378 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
1379 args.CurrentValue = curValue;
1380 sliderSlidingFinishedHandler(this, args);
1383 else if (state == PointStateType.Up)
1387 valueIndicatorImage.Hide();
1393 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1395 PointStateType state = e.Touch.GetState(0);
1396 if (state == PointStateType.Down)
1398 UpdateState(isFocused, true);
1400 else if (state == PointStateType.Up)
1402 UpdateState(isFocused, false);
1407 private void CalculateCurrentValueByTouch(Vector2 pos)
1409 int bgTrackLength = BgTrackLength();
1410 if (direction == DirectionType.Horizontal)
1412 currentSlidedOffset = pos.X;
1414 else if (direction == DirectionType.Vertical)
1416 currentSlidedOffset = bgTrackLength - pos.Y;
1419 if (bgTrackLength != 0)
1421 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1425 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1428 if (null != valueChangedHandler)
1430 ValueChangedArgs args = new ValueChangedArgs();
1431 args.CurrentValue = this.CurrentValue;
1432 valueChangedHandler(this, args);
1435 if (null != sliderValueChangedHandler)
1437 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1438 args.CurrentValue = this.CurrentValue;
1439 sliderValueChangedHandler(this, args);
1444 private float CalculateDiscreteValue(float value)
1446 return ((float)Math.Round((value / discreteValue)) * discreteValue);
1449 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1451 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1455 if (thumbImage == null || Style == null)
1459 isFocused = isFocusedNew;
1460 isPressed = isPressedNew;
1462 if (!isFocused && !isPressed)
1464 ControlState = ControlState.Normal;
1465 thumbImage.ResourceUrl = thumbImageUrlSelector?.Normal;
1467 if (stateChangedHandler != null)
1469 StateChangedArgs args = new StateChangedArgs();
1470 args.CurrentState = (ControlStates)ControlStates.Normal;
1471 stateChangedHandler(this, args);
1476 ControlState = ControlState.Pressed;
1477 thumbImage.ResourceUrl = thumbImageUrlSelector?.Pressed;
1479 if (stateChangedHandler != null)
1481 StateChangedArgs args = new StateChangedArgs();
1482 args.CurrentState = (ControlStates)ControlStates.Pressed;
1483 stateChangedHandler(this, args);
1486 else if (!isPressed && isFocused)
1488 ControlState = ControlState.Focused;
1489 thumbImage.ResourceUrl = thumbImageUrlSelector?.Focused;
1491 if (stateChangedHandler != null)
1493 StateChangedArgs args = new StateChangedArgs();
1494 args.CurrentState = (ControlStates)ControlStates.Focused;
1495 stateChangedHandler(this, args);
1500 private void UpdateComponentByIndicatorTypeChanged()
1502 IndicatorType type = CurrentIndicatorType();
1503 if (type == IndicatorType.None)
1505 if (lowIndicatorImage != null)
1507 lowIndicatorImage.Hide();
1509 if (highIndicatorImage != null)
1511 highIndicatorImage.Hide();
1513 if (lowIndicatorText != null)
1515 lowIndicatorText.Hide();
1517 if (highIndicatorText != null)
1519 highIndicatorText.Hide();
1522 else if (type == IndicatorType.Image)
1524 if (lowIndicatorImage != null)
1526 lowIndicatorImage.Show();
1528 if (highIndicatorImage != null)
1530 highIndicatorImage.Show();
1532 if (lowIndicatorText != null)
1534 lowIndicatorText.Hide();
1536 if (highIndicatorText != null)
1538 highIndicatorText.Hide();
1541 else if (type == IndicatorType.Text)
1543 if (lowIndicatorText != null)
1545 lowIndicatorText.Show();
1547 if (highIndicatorText != null)
1549 highIndicatorText.Show();
1551 if (lowIndicatorImage != null)
1553 lowIndicatorImage.Hide();
1555 if (highIndicatorImage != null)
1557 highIndicatorImage.Hide();
1563 /// Value Changed event data.
1565 /// <since_tizen> 6 </since_tizen>
1566 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
1567 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1568 public class ValueChangedArgs : EventArgs
1573 /// <since_tizen> 6 </since_tizen>
1574 /// It will be removed in API10
1575 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1576 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
1577 public float CurrentValue;
1581 /// Value Changed event data.
1583 /// <since_tizen> 6 </since_tizen>
1584 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
1585 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1586 public class SlidingFinishedArgs : EventArgs
1591 /// <since_tizen> 6 </since_tizen>
1592 /// It will be removed in API10
1593 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1594 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
1595 public float CurrentValue;
1599 /// State Changed event data.
1601 /// <since_tizen> 6 </since_tizen>
1602 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
1603 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1604 public class StateChangedArgs : EventArgs
1609 /// <since_tizen> 6 </since_tizen>
1610 /// It will be removed in API10
1611 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1612 [Obsolete("Deprecated in API8; Will be removed in API10")]
1613 public ControlStates CurrentState;