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((Selector<string>)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty));
516 if (value == null || thumbImage == null)
518 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
522 thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, 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 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
533 [EditorBrowsable(EditorBrowsableState.Never)]
534 public Selector<string> ThumbImageUrl
538 if (thumbImage == null)
544 return (Selector<string>)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty);
549 if (value == null || thumbImage == null)
551 throw new NullReferenceException("Slider.ThumbImageUrl is null");
555 thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, value);
556 thumbImageUrlSelector = value;
562 /// Gets or sets the color of the thumb image object.
564 /// <since_tizen> 8 </since_tizen>
565 public Color ThumbColor
569 return thumbImage?.Color;
573 if (null != thumbImage)
575 thumbImage.BackgroundColor = value;
582 /// Gets or sets the color of the background track image object.
584 /// <since_tizen> 6 </since_tizen>
585 public Color BgTrackColor
589 return bgTrackImage?.BackgroundColor;
593 if (null != bgTrackImage)
595 bgTrackImage.BackgroundColor = value;
601 /// Gets or sets the color of the slided track image object.
603 /// <since_tizen> 6 </since_tizen>
604 public Color SlidedTrackColor
608 return slidedTrackImage?.BackgroundColor;
612 if (null != slidedTrackImage)
614 slidedTrackImage.BackgroundColor = value;
620 /// Gets or sets the thickness value of the track.
622 /// <since_tizen> 6 </since_tizen>
623 public uint TrackThickness
627 return (uint)GetValue(TrackThicknessProperty);
631 SetValue(TrackThicknessProperty, value);
636 /// Gets or sets the warning start value between minimum value and maximum value of slider.
638 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
639 [EditorBrowsable(EditorBrowsableState.Never)]
640 public float WarningStartValue
644 return warningStartValue;
648 warningStartValue = value;
654 /// Gets or sets the color of the warning track image object.
656 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
657 [EditorBrowsable(EditorBrowsableState.Never)]
658 public Color WarningTrackColor
662 return warningTrackImage?.BackgroundColor;
666 if (null != warningTrackImage)
668 warningTrackImage.BackgroundColor = value;
674 /// Gets or sets the color of the warning slided track image object.
676 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
677 [EditorBrowsable(EditorBrowsableState.Never)]
678 public Color WarningSlidedTrackColor
682 return warningSlidedTrackImage?.BackgroundColor;
686 if (null != warningSlidedTrackImage)
688 warningSlidedTrackImage.BackgroundColor = value;
694 /// Gets or sets the Url of the warning thumb image.
696 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
697 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
698 [EditorBrowsable(EditorBrowsableState.Never)]
699 public Selector<string> WarningThumbImageUrl
703 return warningThumbImageUrlSelector;
707 if (value == null || thumbImage == null)
709 throw new NullReferenceException("Slider.WarningThumbImageUrl is null");
713 warningThumbImageUrlSelector = value;
719 /// Gets or sets the color of the warning thumb image object.
721 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
722 [EditorBrowsable(EditorBrowsableState.Never)]
723 public Color WarningThumbColor
727 return warningThumbColor;
731 warningThumbColor = value;
736 /// Gets or sets the resource url of the low indicator image object.
738 /// <since_tizen> 6 </since_tizen>
739 public string LowIndicatorImageURL
743 return lowIndicatorImage?.ResourceUrl;
747 if (null == lowIndicatorImage) lowIndicatorImage = new ImageView();
748 lowIndicatorImage.ResourceUrl = value;
753 /// Gets or sets the resource url of the high indicator image object.
755 /// <since_tizen> 6 </since_tizen>
756 public string HighIndicatorImageURL
760 return highIndicatorImage?.ResourceUrl;
764 if (null == highIndicatorImage) highIndicatorImage = new ImageView();
765 highIndicatorImage.ResourceUrl = value;
770 /// Gets or sets the text content of the low indicator text object.
772 /// <since_tizen> 6 </since_tizen>
773 public string LowIndicatorTextContent
777 return lowIndicatorText?.Text;
781 if (null != lowIndicatorText)
783 lowIndicatorText.Text = value;
789 /// Gets or sets the text content of the high indicator text object.
791 /// <since_tizen> 6 </since_tizen>
792 public string HighIndicatorTextContent
796 return highIndicatorText?.Text;
800 if (null != highIndicatorText)
802 highIndicatorText.Text = value;
808 /// Gets or sets the size of the low indicator object(image or text).
810 /// <since_tizen> 6 </since_tizen>
811 public Size LowIndicatorSize
815 return lowIndicatorSize;
819 lowIndicatorSize = value;
820 UpdateLowIndicatorSize();
822 UpdateBgTrackPosition();
828 /// Gets or sets the size of the high indicator object(image or text).
830 /// <since_tizen> 6 </since_tizen>
831 public Size HighIndicatorSize
835 return highIndicatorText?.Size;
839 if (null != highIndicatorText)
841 highIndicatorText.Size = value;
847 /// Gets or sets the value of the space between track and indicator.
849 /// <since_tizen> 6 </since_tizen>
850 public uint SpaceBetweenTrackAndIndicator
854 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
858 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
863 /// Flag to decide whether the value indicator is shown
865 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
866 [EditorBrowsable(EditorBrowsableState.Never)]
867 public bool IsValueShown
871 return (bool)GetValue(IsValueShownProperty);
875 SetValue(IsValueShownProperty, value);
880 /// Gets or sets the text of value indicator.
882 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
883 [EditorBrowsable(EditorBrowsableState.Never)]
884 public string ValueIndicatorText
888 return (string)GetValue(ValueIndicatorTextProperty);
892 SetValue(ValueIndicatorTextProperty, value);
897 /// Gets or sets the size of the value indicator image object.
899 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
900 [EditorBrowsable(EditorBrowsableState.Never)]
901 public Size ValueIndicatorSize
905 return valueIndicatorImage?.Size;
909 if (null != valueIndicatorImage)
911 valueIndicatorImage.Size = value;
917 /// Gets or sets the resource url of the value indicator image object.
919 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
920 [EditorBrowsable(EditorBrowsableState.Never)]
921 public string ValueIndicatorUrl
925 return valueIndicatorImage?.ResourceUrl;
929 if (null != valueIndicatorImage)
931 valueIndicatorImage.ResourceUrl = value;
937 /// Flag to decide whether the thumb snap to the nearest discrete value when the user drags the thumb or taps.
939 /// The default value is false.
941 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
942 [EditorBrowsable(EditorBrowsableState.Never)]
943 public bool IsDiscrete { get; set; } = false;
946 /// Gets or sets the discrete value of slider.
948 /// The discrete value is evenly spaced between MinValue and MaxValue.
949 /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
950 /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
951 /// The default is 0.
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 float DiscreteValue
959 return discreteValue;
963 discreteValue = value;
968 private Extents spaceBetweenTrackAndIndicator
972 if (null == spaceTrackIndicator)
974 spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
976 Extents extents = new Extents(start, end, top, bottom);
977 spaceTrackIndicator.CopyFrom(extents);
981 return spaceTrackIndicator;
985 private IndicatorType privateIndicatorType
989 return indicatorType;
993 if (indicatorType == value)
997 indicatorType = value;
998 RelayoutBaseComponent(false);
1000 UpdateBgTrackPosition();
1005 private uint privateTrackThickness
1009 return trackThickness ?? 0;
1013 trackThickness = value;
1014 if (bgTrackImage != null)
1016 if (direction == DirectionType.Horizontal)
1018 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1020 else if (direction == DirectionType.Vertical)
1022 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1025 if (slidedTrackImage != null)
1027 if (direction == DirectionType.Horizontal)
1029 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1031 else if (direction == DirectionType.Vertical)
1033 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1036 if (warningTrackImage != null)
1038 if (direction == DirectionType.Horizontal)
1040 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1042 else if (direction == DirectionType.Vertical)
1044 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1047 if (warningSlidedTrackImage != null)
1049 if (direction == DirectionType.Horizontal)
1051 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1053 else if (direction == DirectionType.Vertical)
1055 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1061 private uint privateSpaceBetweenTrackAndIndicator
1065 return privateTrackPadding.Start;
1069 ushort val = (ushort)value;
1070 privateTrackPadding = new Extents(val, val, val, val);
1074 private Extents privateTrackPadding
1078 return spaceBetweenTrackAndIndicator;
1082 spaceBetweenTrackAndIndicator.CopyFrom(value);
1083 UpdateComponentByIndicatorTypeChanged();
1084 UpdateBgTrackSize();
1085 UpdateBgTrackPosition();
1091 /// Focus gained callback.
1093 /// <since_tizen> 8 </since_tizen>
1094 public override void OnFocusGained()
1096 //State = ControlStates.Focused;
1097 UpdateState(true, isPressed);
1098 base.OnFocusGained();
1102 /// Focus Lost callback.
1104 /// <since_tizen> 8 </since_tizen>
1105 public override void OnFocusLost()
1107 //State = ControlStates.Normal;
1108 UpdateState(false, isPressed);
1113 /// Apply style to scrollbar.
1115 /// <param name="viewStyle">The style to apply.</param>
1116 /// <since_tizen> 8 </since_tizen>
1117 public override void ApplyStyle(ViewStyle viewStyle)
1119 base.ApplyStyle(viewStyle);
1121 SliderStyle sliderStyle = viewStyle as SliderStyle;
1123 if (null != sliderStyle?.Progress)
1125 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1128 if (null != sliderStyle?.LowIndicator)
1130 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1133 if (null != sliderStyle?.HighIndicator)
1135 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1138 if (null != sliderStyle?.Track)
1140 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1143 if (null != sliderStyle?.Thumb)
1145 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1148 if (null != sliderStyle?.ValueIndicatorText)
1150 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1153 if (null != sliderStyle?.ValueIndicatorImage)
1155 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1158 if (null != sliderStyle?.WarningTrack)
1160 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1163 if (null != sliderStyle?.WarningProgress)
1165 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1168 EnableControlStatePropagation = true;
1172 /// Prevents from showing child widgets in AT-SPI tree.
1174 [EditorBrowsable(EditorBrowsableState.Never)]
1175 protected override bool AccessibilityShouldReportZeroChildren()
1183 [EditorBrowsable(EditorBrowsableState.Never)]
1184 protected override double AccessibilityGetMinimum()
1186 return (double)MinValue;
1192 [EditorBrowsable(EditorBrowsableState.Never)]
1193 protected override double AccessibilityGetCurrent()
1195 return (double)CurrentValue;
1201 [EditorBrowsable(EditorBrowsableState.Never)]
1202 protected override double AccessibilityGetMaximum()
1204 return (double)MaxValue;
1210 [EditorBrowsable(EditorBrowsableState.Never)]
1211 protected override bool AccessibilitySetCurrent(double value)
1213 var f = (float)value;
1215 if (f >= MinValue && f <= MaxValue)
1218 if (sliderValueChangedHandler != null)
1220 sliderValueChangedHandler(this, new SliderValueChangedEventArgs { CurrentValue = f });
1229 /// Minimum increment.
1231 [EditorBrowsable(EditorBrowsableState.Never)]
1232 protected override double AccessibilityGetMinimumIncrement()
1235 return (MaxValue - MinValue) / 20.0;
1239 /// Initialize AT-SPI object.
1241 [EditorBrowsable(EditorBrowsableState.Never)]
1242 public override void OnInitialize()
1244 base.OnInitialize();
1245 SetAccessibilityConstructor(Role.Slider, AccessibilityInterface.Value);
1249 /// Get Slider style.
1251 /// <returns>The default slider style.</returns>
1252 /// <since_tizen> 8 </since_tizen>
1253 protected override ViewStyle CreateViewStyle()
1255 return new SliderStyle();
1261 /// <param name="type">Dispose type.</param>
1262 /// <since_tizen> 6 </since_tizen>
1263 protected override void Dispose(DisposeTypes type)
1270 if (type == DisposeTypes.Explicit)
1272 if (null != panGestureDetector)
1274 panGestureDetector.Detach(this);
1275 panGestureDetector.Detected -= OnPanGestureDetected;
1276 panGestureDetector.Dispose();
1277 panGestureDetector = null;
1280 if (null != thumbImage)
1282 thumbImage.TouchEvent -= OnTouchEventForThumb;
1283 Utility.Dispose(thumbImage);
1285 Utility.Dispose(warningSlidedTrackImage);
1286 Utility.Dispose(warningTrackImage);
1287 Utility.Dispose(slidedTrackImage);
1288 if (null != bgTrackImage)
1290 bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
1291 Utility.Dispose(bgTrackImage);
1293 Utility.Dispose(lowIndicatorImage);
1294 Utility.Dispose(highIndicatorImage);
1295 Utility.Dispose(lowIndicatorText);
1296 Utility.Dispose(highIndicatorText);
1297 Utility.Dispose(valueIndicatorImage);
1298 Utility.Dispose(valueIndicatorText);
1305 /// Update Slider by style.
1307 /// <since_tizen> 6 </since_tizen>
1308 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1309 [EditorBrowsable(EditorBrowsableState.Never)]
1310 protected override void OnUpdate()
1312 RelayoutBaseComponent();
1314 UpdateComponentByIndicatorTypeChanged();
1315 UpdateBgTrackSize();
1316 UpdateBgTrackPosition();
1317 UpdateWarningTrackSize();
1318 UpdateLowIndicatorSize();
1322 private void CalculateCurrentValueByGesture(float offset)
1324 currentSlidedOffset += offset;
1326 if (currentSlidedOffset <= 0)
1328 this.CurrentValue = minValue;
1330 else if (currentSlidedOffset >= BgTrackLength())
1332 this.CurrentValue = maxValue;
1336 int bgTrackLength = BgTrackLength();
1337 if (bgTrackLength != 0)
1339 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1345 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1348 if (valueChangedHandler != null)
1350 ValueChangedArgs args = new ValueChangedArgs();
1351 args.CurrentValue = this.CurrentValue;
1352 valueChangedHandler(this, args);
1355 if (sliderValueChangedHandler != null)
1357 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1358 args.CurrentValue = this.CurrentValue;
1359 sliderValueChangedHandler(this, args);
1363 private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
1365 PointStateType state = e.Touch.GetState(0);
1366 if (state == PointStateType.Down)
1370 valueIndicatorImage.Show();
1373 Vector2 pos = e.Touch.GetLocalPosition(0);
1374 CalculateCurrentValueByTouch(pos);
1376 if (null != slidingFinishedHandler)
1378 SlidingFinishedArgs args = new SlidingFinishedArgs();
1379 args.CurrentValue = curValue;
1380 slidingFinishedHandler(this, args);
1383 if (null != sliderSlidingFinishedHandler)
1385 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
1386 args.CurrentValue = curValue;
1387 sliderSlidingFinishedHandler(this, args);
1390 else if (state == PointStateType.Up)
1394 valueIndicatorImage.Hide();
1400 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1402 PointStateType state = e.Touch.GetState(0);
1403 if (state == PointStateType.Down)
1405 UpdateState(isFocused, true);
1407 else if (state == PointStateType.Up)
1409 UpdateState(isFocused, false);
1414 private void CalculateCurrentValueByTouch(Vector2 pos)
1416 int bgTrackLength = BgTrackLength();
1417 if (direction == DirectionType.Horizontal)
1419 currentSlidedOffset = pos.X;
1421 else if (direction == DirectionType.Vertical)
1423 currentSlidedOffset = bgTrackLength - pos.Y;
1426 if (bgTrackLength != 0)
1428 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1432 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1435 if (null != valueChangedHandler)
1437 ValueChangedArgs args = new ValueChangedArgs();
1438 args.CurrentValue = this.CurrentValue;
1439 valueChangedHandler(this, args);
1442 if (null != sliderValueChangedHandler)
1444 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1445 args.CurrentValue = this.CurrentValue;
1446 sliderValueChangedHandler(this, args);
1451 private float CalculateDiscreteValue(float value)
1453 return ((float)Math.Round((value / discreteValue)) * discreteValue);
1456 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1458 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1462 if (thumbImage == null || Style == null)
1466 isFocused = isFocusedNew;
1467 isPressed = isPressedNew;
1469 if (!isFocused && !isPressed)
1471 ControlState = ControlState.Normal;
1472 thumbImage.ResourceUrl = thumbImageUrlSelector?.Normal;
1474 if (stateChangedHandler != null)
1476 StateChangedArgs args = new StateChangedArgs();
1477 args.CurrentState = (ControlStates)ControlStates.Normal;
1478 stateChangedHandler(this, args);
1483 ControlState = ControlState.Pressed;
1484 thumbImage.ResourceUrl = thumbImageUrlSelector?.Pressed;
1486 if (stateChangedHandler != null)
1488 StateChangedArgs args = new StateChangedArgs();
1489 args.CurrentState = (ControlStates)ControlStates.Pressed;
1490 stateChangedHandler(this, args);
1493 else if (!isPressed && isFocused)
1495 ControlState = ControlState.Focused;
1496 thumbImage.ResourceUrl = thumbImageUrlSelector?.Focused;
1498 if (stateChangedHandler != null)
1500 StateChangedArgs args = new StateChangedArgs();
1501 args.CurrentState = (ControlStates)ControlStates.Focused;
1502 stateChangedHandler(this, args);
1507 private void UpdateComponentByIndicatorTypeChanged()
1509 IndicatorType type = CurrentIndicatorType();
1510 if (type == IndicatorType.None)
1512 if (lowIndicatorImage != null)
1514 lowIndicatorImage.Hide();
1516 if (highIndicatorImage != null)
1518 highIndicatorImage.Hide();
1520 if (lowIndicatorText != null)
1522 lowIndicatorText.Hide();
1524 if (highIndicatorText != null)
1526 highIndicatorText.Hide();
1529 else if (type == IndicatorType.Image)
1531 if (lowIndicatorImage != null)
1533 lowIndicatorImage.Show();
1535 if (highIndicatorImage != null)
1537 highIndicatorImage.Show();
1539 if (lowIndicatorText != null)
1541 lowIndicatorText.Hide();
1543 if (highIndicatorText != null)
1545 highIndicatorText.Hide();
1548 else if (type == IndicatorType.Text)
1550 if (lowIndicatorText != null)
1552 lowIndicatorText.Show();
1554 if (highIndicatorText != null)
1556 highIndicatorText.Show();
1558 if (lowIndicatorImage != null)
1560 lowIndicatorImage.Hide();
1562 if (highIndicatorImage != null)
1564 highIndicatorImage.Hide();
1570 /// Value Changed event data.
1572 /// <since_tizen> 6 </since_tizen>
1573 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
1574 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1575 public class ValueChangedArgs : EventArgs
1580 /// <since_tizen> 6 </since_tizen>
1581 /// It will be removed in API10
1582 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1583 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
1584 public float CurrentValue;
1588 /// Value Changed event data.
1590 /// <since_tizen> 6 </since_tizen>
1591 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
1592 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1593 public class SlidingFinishedArgs : EventArgs
1598 /// <since_tizen> 6 </since_tizen>
1599 /// It will be removed in API10
1600 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1601 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
1602 public float CurrentValue;
1606 /// State Changed event data.
1608 /// <since_tizen> 6 </since_tizen>
1609 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
1610 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1611 public class StateChangedArgs : EventArgs
1616 /// <since_tizen> 6 </since_tizen>
1617 /// It will be removed in API10
1618 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1619 [Obsolete("Deprecated in API8; Will be removed in API10")]
1620 public ControlStates CurrentState;