2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Tizen.NUI.BaseComponents;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.Components
25 /// Slider value changed event data.
27 /// <since_tizen> 8 </since_tizen>
28 public class SliderValueChangedEventArgs : EventArgs
31 /// Current Slider value
33 /// <since_tizen> 8 </since_tizen>
34 public float CurrentValue { get; set; }
38 /// Slider sliding started event data.
40 /// <since_tizen> 8 </since_tizen>
41 public class SliderSlidingStartedEventArgs : EventArgs
44 /// Current Slider value
46 /// <since_tizen> 8 </since_tizen>
47 public float CurrentValue { get; set; }
51 /// Slider sliding finished event data.
53 /// <since_tizen> 8 </since_tizen>
54 public class SliderSlidingFinishedEventArgs : EventArgs
57 /// Current Slider value
59 /// <since_tizen> 8 </since_tizen>
60 public float CurrentValue { get; set; }
64 /// A slider lets users select a value from a continuous or discrete range of values by moving the slider thumb.
66 /// <since_tizen> 6 </since_tizen>
67 public partial class Slider : Control
70 /// IndicatorTypeProperty
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 public static readonly BindableProperty IndicatorTypeProperty = BindableProperty.Create("IndicatorType", typeof(IndicatorType), typeof(Slider), IndicatorType.None, propertyChanged: (bindable, oldValue, newValue) =>
75 var instance = (Slider)bindable;
78 instance.privateIndicatorType = (IndicatorType)newValue;
81 defaultValueCreator: (bindable) =>
83 var instance = (Slider)bindable;
84 return instance.privateIndicatorType;
88 /// SpaceBetweenTrackAndIndicatorProperty
90 [EditorBrowsable(EditorBrowsableState.Never)]
91 public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create(nameof(SpaceBetweenTrackAndIndicator), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
93 var instance = (Slider)bindable;
96 instance.privateSpaceBetweenTrackAndIndicator = (uint)newValue;
99 defaultValueCreator: (bindable) =>
101 var instance = (Slider)bindable;
102 return instance.privateSpaceBetweenTrackAndIndicator;
106 /// TrackThicknessProperty
108 [EditorBrowsable(EditorBrowsableState.Never)]
109 public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
111 var instance = (Slider)bindable;
112 if (newValue != null)
114 instance.privateTrackThickness = (uint)newValue;
117 defaultValueCreator: (bindable) =>
119 var instance = (Slider)bindable;
120 return instance.privateTrackThickness;
124 /// IsValueShownProperty
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public static readonly BindableProperty IsValueShownProperty = BindableProperty.Create(nameof(IsValueShown), typeof(bool), typeof(Slider), true, propertyChanged: (bindable, oldValue, newValue) =>
129 var instance = (Slider)bindable;
130 if (newValue != null)
132 bool newValueShown = (bool)newValue;
133 if (instance.isValueShown != newValueShown)
135 instance.isValueShown = newValueShown;
139 defaultValueCreator: (bindable) =>
141 var instance = (Slider)bindable;
142 return instance.isValueShown;
146 /// ValueIndicatorTextProperty
148 [EditorBrowsable(EditorBrowsableState.Never)]
149 public static readonly BindableProperty ValueIndicatorTextProperty = BindableProperty.Create(nameof(ValueIndicatorText), typeof(string), typeof(Slider), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
151 var instance = (Slider)bindable;
152 if (newValue != null)
154 string newText = (string)newValue;
155 instance.valueIndicatorText.Text = newText;
156 if (instance.sliderStyle != null)
158 instance.sliderStyle.ValueIndicatorText.Text = newText;
162 defaultValueCreator: (bindable) =>
164 var instance = (Slider)bindable;
165 return instance.valueIndicatorText.Text;
171 /// The constructor of the Slider class.
173 /// <since_tizen> 6 </since_tizen>
180 /// The constructor of the Slider class with specific style.
182 /// <param name="style">The string to initialize the Slider</param>
183 /// <since_tizen> 8 </since_tizen>
184 public Slider(string style) : base(style)
190 /// The constructor of the Slider class with specific style.
192 /// <param name="sliderStyle">The style object to initialize the Slider</param>
193 /// <since_tizen> 8 </since_tizen>
194 public Slider(SliderStyle sliderStyle) : base(sliderStyle)
200 /// The value changed event handler.
202 /// <since_tizen> 6 </since_tizen>
203 [Obsolete("Deprecated in API8; Will be removed in API10. Please use ValueChanged event instead.")]
204 public event EventHandler<ValueChangedArgs> ValueChangedEvent
208 valueChangedHandler += value;
212 valueChangedHandler -= value;
217 /// The sliding finished event handler.
219 /// <since_tizen> 6 </since_tizen>
220 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SlidingFinished event instead.")]
221 public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
225 slidingFinishedHandler += value;
229 slidingFinishedHandler -= value;
234 /// The value changed event handler.
236 /// <since_tizen> 8 </since_tizen>
237 public event EventHandler<SliderValueChangedEventArgs> ValueChanged
241 sliderValueChangedHandler += value;
245 sliderValueChangedHandler -= value;
250 /// The sliding started event handler.
252 /// <since_tizen> 8 </since_tizen>
253 public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
257 sliderSlidingStartedHandler += value;
261 sliderSlidingStartedHandler -= value;
266 /// The sliding finished event handler.
268 /// <since_tizen> 8 </since_tizen>
269 public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
273 sliderSlidingFinishedHandler += value;
277 sliderSlidingFinishedHandler -= value;
282 /// The state changed event handler.
284 /// <since_tizen> 6 </since_tizen>
285 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
286 public event EventHandler<StateChangedArgs> StateChangedEvent
290 stateChangedHandler += value;
294 stateChangedHandler -= value;
299 /// The direction type of slider.
301 /// <since_tizen> 6 </since_tizen>
302 public enum DirectionType
305 /// The Horizontal type.
307 /// <since_tizen> 6 </since_tizen>
311 /// The Vertical type.
313 /// <since_tizen> 6 </since_tizen>
318 /// The indicator type of slider.
320 /// <since_tizen> 6 </since_tizen>
321 public enum IndicatorType
323 /// <summary> Only contains slider bar.</summary>
324 /// <since_tizen> 6 </since_tizen>
327 /// <summary> Contains slider bar, IndicatorImage.</summary>
328 /// <since_tizen> 6 </since_tizen>
331 /// <summary> Contains slider bar, IndicatorText.</summary>
332 /// <since_tizen> 6 </since_tizen>
337 /// Return a copied Style instance of Slider
340 /// It returns copied Style instance and changing it does not effect to the Slider.
341 /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
343 /// <since_tizen> 8 </since_tizen>
344 public new SliderStyle Style
348 var result = new SliderStyle(sliderStyle);
349 result.CopyPropertiesFromView(this);
350 result.Track.CopyPropertiesFromView(bgTrackImage);
351 result.Progress.CopyPropertiesFromView(slidedTrackImage);
352 result.Thumb.CopyPropertiesFromView(thumbImage);
353 result.LowIndicatorImage.CopyPropertiesFromView(lowIndicatorImage);
354 result.HighIndicatorImage.CopyPropertiesFromView(highIndicatorImage);
355 result.LowIndicator.CopyPropertiesFromView(lowIndicatorText);
356 result.HighIndicator.CopyPropertiesFromView(highIndicatorText);
357 result.ValueIndicatorText.CopyPropertiesFromView(valueIndicatorText);
358 result.ValueIndicatorImage.CopyPropertiesFromView(valueIndicatorImage);
364 /// Return a copied Style instance of Slider
366 private SliderStyle sliderStyle => ViewStyle as SliderStyle;
369 /// Gets or sets the direction type of slider.
371 /// <since_tizen> 6 </since_tizen>
372 public DirectionType Direction
380 if (direction == value)
385 RelayoutBaseComponent(false);
387 UpdateBgTrackPosition();
388 UpdateWarningTrackSize();
394 /// Gets or sets the indicator type, arrow or sign.
396 /// <since_tizen> 6 </since_tizen>
397 public IndicatorType Indicator
401 return (IndicatorType)GetValue(IndicatorTypeProperty);
405 SetValue(IndicatorTypeProperty, value);
410 /// Gets or sets the minimum value of slider.
412 /// <since_tizen> 6 </since_tizen>
413 public float MinValue
427 /// Gets or sets the maximum value of slider.
429 /// <since_tizen> 6 </since_tizen>
430 public float MaxValue
444 /// Gets or sets the current value of slider.
446 /// <since_tizen> 6 </since_tizen>
447 public float CurrentValue
461 /// Gets or sets the size of the thumb image object.
463 /// <since_tizen> 6 </since_tizen>
464 public Size ThumbSize
468 return thumbImage?.Size;
472 if (null != thumbImage)
474 thumbImage.Size = value;
476 sliderStyle.Thumb.Size = value;
482 /// Gets or sets the resource url of the thumb image object.
484 /// Please use ThumbImageUri 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;
499 sliderStyle.Thumb.ResourceUrl = value;
505 /// Gets or sets the resource url selector of the thumb image object.
506 /// Getter returns copied selector value if exist, null otherwise.
508 /// Please use ThumbImageUri property.
510 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
511 /// <since_tizen> 6 </since_tizen>
512 public StringSelector ThumbImageURLSelector
514 get => thumbImage == null ? null : new StringSelector((Selector<string>)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty));
517 if (value == null || thumbImage == null)
519 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
523 thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, value);
524 thumbImageUrlSelector = value;
530 /// Gets or sets the Uri of the thumb image.
532 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
533 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
534 [EditorBrowsable(EditorBrowsableState.Never)]
535 public Selector<Uri> ThumbImageUri
539 if (thumbImage == null)
545 return ((Selector<string>)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty)).Clone<Uri>(str => { return new Uri(str); });
550 if (value == null || thumbImage == null)
552 throw new NullReferenceException("Slider.ThumbImageUri is null");
556 Selector<string> stringValue = value.Clone<string>(m => m?.AbsoluteUri);
557 thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, stringValue);
558 thumbImageUrlSelector = stringValue;
564 /// Gets or sets the color of the thumb image object.
566 /// <since_tizen> 8 </since_tizen>
567 public Color ThumbColor
571 return thumbImage?.Color;
575 if (null != thumbImage)
577 thumbImage.Color = value;
579 sliderStyle.Thumb.Color = value;
585 /// Gets or sets the color of the background track image object.
587 /// <since_tizen> 6 </since_tizen>
588 public Color BgTrackColor
592 return bgTrackImage?.BackgroundColor;
596 if (null != bgTrackImage)
598 bgTrackImage.BackgroundColor = value;
599 sliderStyle.Track.BackgroundColor = value;
605 /// Gets or sets the color of the slided track image object.
607 /// <since_tizen> 6 </since_tizen>
608 public Color SlidedTrackColor
612 return slidedTrackImage?.BackgroundColor;
616 if (null != slidedTrackImage)
618 slidedTrackImage.BackgroundColor = value;
619 sliderStyle.Progress.BackgroundColor = value;
625 /// Gets or sets the thickness value of the track.
627 /// <since_tizen> 6 </since_tizen>
628 public uint TrackThickness
632 return (uint)GetValue(TrackThicknessProperty);
636 SetValue(TrackThicknessProperty, value);
641 /// Gets or sets the warning start value between minimum value and maximum value of slider.
643 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
644 [EditorBrowsable(EditorBrowsableState.Never)]
645 public float WarningStartValue
649 return warningStartValue;
653 warningStartValue = value;
659 /// Gets or sets the color of the warning track image object.
661 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
662 [EditorBrowsable(EditorBrowsableState.Never)]
663 public Color WarningTrackColor
667 return warningTrackImage?.BackgroundColor;
671 if (null != warningTrackImage)
673 warningTrackImage.BackgroundColor = value;
674 sliderStyle.WarningTrack.BackgroundColor = value;
680 /// Gets or sets the color of the warning slided track image object.
682 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
683 [EditorBrowsable(EditorBrowsableState.Never)]
684 public Color WarningSlidedTrackColor
688 return warningSlidedTrackImage?.BackgroundColor;
692 if (null != warningSlidedTrackImage)
694 warningSlidedTrackImage.BackgroundColor = value;
695 sliderStyle.WarningProgress.BackgroundColor = value;
701 /// Gets or sets the resource url of the warning thumb image object.
703 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
704 [EditorBrowsable(EditorBrowsableState.Never)]
705 public string WarningThumbImageUrl
709 return warningThumbImageUrl;
713 warningThumbImageUrl = value;
718 /// Gets or sets the Uri of the warning thumb image.
720 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
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 Selector<Uri> WarningThumbImageUri
727 return warningThumbImageUrlSelector?.Clone<Uri>(str => { return new Uri(str); });
731 if (value == null || thumbImage == null)
733 throw new NullReferenceException("Slider.WarningThumbImageUri is null");
737 warningThumbImageUrlSelector = value.Clone<string>(m => m?.AbsoluteUri);
743 /// Gets or sets the color of the warning thumb image object.
745 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
746 [EditorBrowsable(EditorBrowsableState.Never)]
747 public Color WarningThumbColor
751 return warningThumbColor;
755 warningThumbColor = value;
760 /// Gets or sets the resource url of the low indicator image object.
762 /// <since_tizen> 6 </since_tizen>
763 public string LowIndicatorImageURL
767 return lowIndicatorImage?.ResourceUrl;
771 if (null == lowIndicatorImage) lowIndicatorImage = new ImageView();
772 lowIndicatorImage.ResourceUrl = value;
773 sliderStyle.LowIndicatorImage.ResourceUrl = value;
778 /// Gets or sets the resource url of the high indicator image object.
780 /// <since_tizen> 6 </since_tizen>
781 public string HighIndicatorImageURL
785 return highIndicatorImage?.ResourceUrl;
789 if (null == highIndicatorImage) highIndicatorImage = new ImageView();
790 highIndicatorImage.ResourceUrl = value;
791 sliderStyle.HighIndicatorImage.ResourceUrl = value;
796 /// Gets or sets the text content of the low indicator text object.
798 /// <since_tizen> 6 </since_tizen>
799 public string LowIndicatorTextContent
803 return lowIndicatorText?.Text;
807 if (null != lowIndicatorText)
809 lowIndicatorText.Text = value;
810 sliderStyle.LowIndicator.Text = value;
816 /// Gets or sets the text content of the high indicator text object.
818 /// <since_tizen> 6 </since_tizen>
819 public string HighIndicatorTextContent
823 return highIndicatorText?.Text;
827 if (null != highIndicatorText)
829 highIndicatorText.Text = value;
830 sliderStyle.HighIndicator.Text = value;
836 /// Gets or sets the size of the low indicator object(image or text).
838 /// <since_tizen> 6 </since_tizen>
839 public Size LowIndicatorSize
843 return lowIndicatorSize;
847 lowIndicatorSize = value;
848 UpdateLowIndicatorSize();
850 UpdateBgTrackPosition();
856 /// Gets or sets the size of the high indicator object(image or text).
858 /// <since_tizen> 6 </since_tizen>
859 public Size HighIndicatorSize
863 return highIndicatorText?.Size;
867 if (null != highIndicatorText)
869 highIndicatorText.Size = value;
870 sliderStyle.HighIndicator.Size = value;
876 /// Gets or sets the value of the space between track and indicator.
878 /// <since_tizen> 6 </since_tizen>
879 public uint SpaceBetweenTrackAndIndicator
883 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
887 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
892 /// Flag to decide whether the value indicator is shown
894 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
895 [EditorBrowsable(EditorBrowsableState.Never)]
896 public bool IsValueShown
900 return (bool)GetValue(IsValueShownProperty);
904 SetValue(IsValueShownProperty, value);
909 /// Gets or sets the text of value indicator.
911 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
912 [EditorBrowsable(EditorBrowsableState.Never)]
913 public string ValueIndicatorText
917 return (string)GetValue(ValueIndicatorTextProperty);
921 SetValue(ValueIndicatorTextProperty, value);
926 /// Gets or sets the size of the value indicator image object.
928 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
929 [EditorBrowsable(EditorBrowsableState.Never)]
930 public Size ValueIndicatorSize
934 return valueIndicatorImage?.Size;
938 if (null != valueIndicatorImage)
940 valueIndicatorImage.Size = value;
941 sliderStyle.ValueIndicatorImage.Size = value;
947 /// Gets or sets the resource url of the value indicator image object.
949 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
950 [EditorBrowsable(EditorBrowsableState.Never)]
951 public string ValueIndicatorUrl
955 return valueIndicatorImage?.ResourceUrl;
959 if (null != valueIndicatorImage)
961 valueIndicatorImage.ResourceUrl = value;
962 sliderStyle.ValueIndicatorImage.ResourceUrl = value;
967 private Extents spaceBetweenTrackAndIndicator
971 if (null == _spaceBetweenTrackAndIndicator)
973 _spaceBetweenTrackAndIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
975 Extents extents = new Extents(start, end, top, bottom);
976 _spaceBetweenTrackAndIndicator.CopyFrom(extents);
980 return _spaceBetweenTrackAndIndicator;
984 private IndicatorType privateIndicatorType
988 return indicatorType;
992 if (indicatorType == value)
996 indicatorType = value;
997 RelayoutBaseComponent(false);
999 UpdateBgTrackPosition();
1004 private uint privateTrackThickness
1008 return trackThickness ?? 0;
1012 trackThickness = value;
1013 if (bgTrackImage != null)
1015 if (direction == DirectionType.Horizontal)
1017 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1019 else if (direction == DirectionType.Vertical)
1021 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1024 if (slidedTrackImage != null)
1026 if (direction == DirectionType.Horizontal)
1028 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1030 else if (direction == DirectionType.Vertical)
1032 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1035 if (warningTrackImage != null)
1037 if (direction == DirectionType.Horizontal)
1039 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1041 else if (direction == DirectionType.Vertical)
1043 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1046 if (warningSlidedTrackImage != null)
1048 if (direction == DirectionType.Horizontal)
1050 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1052 else if (direction == DirectionType.Vertical)
1054 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1060 private uint privateSpaceBetweenTrackAndIndicator
1064 return privateTrackPadding.Start;
1068 ushort val = (ushort)value;
1069 privateTrackPadding = new Extents(val, val, val, val);
1073 private Extents privateTrackPadding
1077 return spaceBetweenTrackAndIndicator;
1081 spaceBetweenTrackAndIndicator.CopyFrom(value);
1082 UpdateComponentByIndicatorTypeChanged();
1083 UpdateBgTrackSize();
1084 UpdateBgTrackPosition();
1090 /// Focus gained callback.
1092 /// <since_tizen> 8 </since_tizen>
1093 public override void OnFocusGained()
1095 //State = ControlStates.Focused;
1096 UpdateState(true, isPressed);
1097 base.OnFocusGained();
1101 /// Focus Lost callback.
1103 /// <since_tizen> 8 </since_tizen>
1104 public override void OnFocusLost()
1106 //State = ControlStates.Normal;
1107 UpdateState(false, isPressed);
1112 /// Apply style to scrollbar.
1114 /// <param name="viewStyle">The style to apply.</param>
1115 /// <since_tizen> 8 </since_tizen>
1116 public override void ApplyStyle(ViewStyle viewStyle)
1118 base.ApplyStyle(viewStyle);
1120 SliderStyle sliderStyle = viewStyle as SliderStyle;
1122 if (null != sliderStyle?.Progress)
1124 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1127 if (null != sliderStyle?.LowIndicator)
1129 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1132 if (null != sliderStyle?.HighIndicator)
1134 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1137 if (null != sliderStyle?.Track)
1139 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1142 if (null != sliderStyle?.Thumb)
1144 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1147 if (null != sliderStyle?.ValueIndicatorText)
1149 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1152 if (null != sliderStyle?.ValueIndicatorImage)
1154 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1157 if (null != sliderStyle?.WarningTrack)
1159 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1162 if (null != sliderStyle?.WarningProgress)
1164 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1167 EnableControlStatePropagation = true;
1171 /// Get Slider style.
1173 /// <returns>The default slider style.</returns>
1174 /// <since_tizen> 8 </since_tizen>
1175 protected override ViewStyle CreateViewStyle()
1177 return new SliderStyle();
1183 /// <param name="type">Dispose type.</param>
1184 /// <since_tizen> 6 </since_tizen>
1185 protected override void Dispose(DisposeTypes type)
1192 if (type == DisposeTypes.Explicit)
1194 if (null != panGestureDetector)
1196 panGestureDetector.Detach(this);
1197 panGestureDetector.Detected -= OnPanGestureDetected;
1198 panGestureDetector.Dispose();
1199 panGestureDetector = null;
1202 if (null != thumbImage)
1204 thumbImage.TouchEvent -= OnTouchEventForThumb;
1205 Utility.Dispose(thumbImage);
1207 Utility.Dispose(warningSlidedTrackImage);
1208 Utility.Dispose(warningTrackImage);
1209 Utility.Dispose(slidedTrackImage);
1210 if (null != bgTrackImage)
1212 bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
1213 Utility.Dispose(bgTrackImage);
1215 Utility.Dispose(lowIndicatorImage);
1216 Utility.Dispose(highIndicatorImage);
1217 Utility.Dispose(lowIndicatorText);
1218 Utility.Dispose(highIndicatorText);
1219 Utility.Dispose(valueIndicatorImage);
1220 Utility.Dispose(valueIndicatorText);
1227 /// Update Slider by style.
1229 /// <since_tizen> 6 </since_tizen>
1230 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1231 [EditorBrowsable(EditorBrowsableState.Never)]
1232 protected override void OnUpdate()
1234 RelayoutBaseComponent();
1236 UpdateComponentByIndicatorTypeChanged();
1237 UpdateBgTrackSize();
1238 UpdateBgTrackPosition();
1239 UpdateWarningTrackSize();
1240 UpdateLowIndicatorSize();
1244 private void CalculateCurrentValueByGesture(float offset)
1246 currentSlidedOffset += offset;
1248 if (currentSlidedOffset <= 0)
1250 curValue = minValue;
1252 else if (currentSlidedOffset >= BgTrackLength())
1254 curValue = maxValue;
1258 int bgTrackLength = BgTrackLength();
1259 if (bgTrackLength != 0)
1261 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1264 if (valueChangedHandler != null)
1266 ValueChangedArgs args = new ValueChangedArgs();
1267 args.CurrentValue = curValue;
1268 valueChangedHandler(this, args);
1271 if (sliderValueChangedHandler != null)
1273 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1274 args.CurrentValue = curValue;
1275 sliderValueChangedHandler(this, args);
1279 private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
1281 PointStateType state = e.Touch.GetState(0);
1282 if (state == PointStateType.Down)
1286 valueIndicatorImage.Show();
1289 Vector2 pos = e.Touch.GetLocalPosition(0);
1290 CalculateCurrentValueByTouch(pos);
1292 if (null != slidingFinishedHandler)
1294 SlidingFinishedArgs args = new SlidingFinishedArgs();
1295 args.CurrentValue = curValue;
1296 slidingFinishedHandler(this, args);
1299 if (null != sliderSlidingFinishedHandler)
1301 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
1302 args.CurrentValue = curValue;
1303 sliderSlidingFinishedHandler(this, args);
1306 else if (state == PointStateType.Up)
1310 valueIndicatorImage.Hide();
1316 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1318 PointStateType state = e.Touch.GetState(0);
1319 if (state == PointStateType.Down)
1321 UpdateState(isFocused, true);
1323 else if (state == PointStateType.Up)
1325 UpdateState(isFocused, false);
1330 private void CalculateCurrentValueByTouch(Vector2 pos)
1332 int bgTrackLength = BgTrackLength();
1333 if (direction == DirectionType.Horizontal)
1335 currentSlidedOffset = pos.X;
1337 else if (direction == DirectionType.Vertical)
1339 currentSlidedOffset = bgTrackLength - pos.Y;
1342 if (bgTrackLength != 0)
1344 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1345 if (null != valueChangedHandler)
1347 ValueChangedArgs args = new ValueChangedArgs();
1348 args.CurrentValue = curValue;
1349 valueChangedHandler(this, args);
1352 if (null != sliderValueChangedHandler)
1354 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1355 args.CurrentValue = curValue;
1356 sliderValueChangedHandler(this, args);
1361 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1363 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1367 if (thumbImage == null || Style == null)
1371 isFocused = isFocusedNew;
1372 isPressed = isPressedNew;
1374 if (!isFocused && !isPressed)
1376 ControlState = ControlState.Normal;
1377 thumbImage.ResourceUrl = thumbImageUrlSelector?.Normal;
1379 if (stateChangedHandler != null)
1381 StateChangedArgs args = new StateChangedArgs();
1382 args.CurrentState = (ControlStates)ControlStates.Normal;
1383 stateChangedHandler(this, args);
1388 ControlState = ControlState.Pressed;
1389 thumbImage.ResourceUrl = thumbImageUrlSelector?.Pressed;
1391 if (stateChangedHandler != null)
1393 StateChangedArgs args = new StateChangedArgs();
1394 args.CurrentState = (ControlStates)ControlStates.Pressed;
1395 stateChangedHandler(this, args);
1398 else if (!isPressed && isFocused)
1400 ControlState = ControlState.Focused;
1401 thumbImage.ResourceUrl = thumbImageUrlSelector?.Focused;
1403 if (stateChangedHandler != null)
1405 StateChangedArgs args = new StateChangedArgs();
1406 args.CurrentState = (ControlStates)ControlStates.Focused;
1407 stateChangedHandler(this, args);
1412 private void UpdateComponentByIndicatorTypeChanged()
1414 IndicatorType type = CurrentIndicatorType();
1415 if (type == IndicatorType.None)
1417 if (lowIndicatorImage != null)
1419 lowIndicatorImage.Hide();
1421 if (highIndicatorImage != null)
1423 highIndicatorImage.Hide();
1425 if (lowIndicatorText != null)
1427 lowIndicatorText.Hide();
1429 if (highIndicatorText != null)
1431 highIndicatorText.Hide();
1434 else if (type == IndicatorType.Image)
1436 if (lowIndicatorImage != null)
1438 lowIndicatorImage.Show();
1440 if (highIndicatorImage != null)
1442 highIndicatorImage.Show();
1444 if (lowIndicatorText != null)
1446 lowIndicatorText.Hide();
1448 if (highIndicatorText != null)
1450 highIndicatorText.Hide();
1453 else if (type == IndicatorType.Text)
1455 if (lowIndicatorText != null)
1457 lowIndicatorText.Show();
1459 if (highIndicatorText != null)
1461 highIndicatorText.Show();
1463 if (lowIndicatorImage != null)
1465 lowIndicatorImage.Hide();
1467 if (highIndicatorImage != null)
1469 highIndicatorImage.Hide();
1475 /// Value Changed event data.
1477 /// <since_tizen> 6 </since_tizen>
1478 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
1479 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1480 public class ValueChangedArgs : EventArgs
1485 /// <since_tizen> 6 </since_tizen>
1486 /// It will be removed in API10
1487 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1488 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
1489 public float CurrentValue;
1493 /// Value Changed event data.
1495 /// <since_tizen> 6 </since_tizen>
1496 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
1497 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1498 public class SlidingFinishedArgs : EventArgs
1503 /// <since_tizen> 6 </since_tizen>
1504 /// It will be removed in API10
1505 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1506 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
1507 public float CurrentValue;
1511 /// State Changed event data.
1513 /// <since_tizen> 6 </since_tizen>
1514 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
1515 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1516 public class StateChangedArgs : EventArgs
1521 /// <since_tizen> 6 </since_tizen>
1522 /// It will be removed in API10
1523 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1524 [Obsolete("Deprecated in API8; Will be removed in API10")]
1525 public ControlStates CurrentState;