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 (Accessibility.Accessibility.Enabled && instance.IsHighlighted)
181 instance.EmitAccessibilityEvent(AccessibilityPropertyChangeEvent.Value);
183 instance.UpdateValue();
186 defaultValueCreator: (bindable) =>
188 var instance = (Slider)bindable;
189 return instance.curValue;
194 /// IsEnabledProperty
196 [EditorBrowsable(EditorBrowsableState.Never)]
197 public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(Slider), true, propertyChanged: (bindable, oldValue, newValue) =>
199 var instance = (Slider)bindable;
200 if (newValue != null)
202 bool newEnabled = (bool)newValue;
203 if (instance.isEnabled != newEnabled)
205 instance.isEnabled = newEnabled;
206 instance.Sensitive = newEnabled;
207 instance.UpdateValue();
211 defaultValueCreator: (bindable) => ((Slider)bindable).isEnabled);
216 /// The constructor of the Slider class.
218 /// <since_tizen> 6 </since_tizen>
225 /// The constructor of the Slider class with specific style.
227 /// <param name="style">The string to initialize the Slider</param>
228 /// <since_tizen> 8 </since_tizen>
229 public Slider(string style) : base(style)
235 /// The constructor of the Slider class with specific style.
237 /// <param name="sliderStyle">The style object to initialize the Slider</param>
238 /// <since_tizen> 8 </since_tizen>
239 public Slider(SliderStyle sliderStyle) : base(sliderStyle)
245 /// The value changed event handler.
247 /// <since_tizen> 6 </since_tizen>
248 [Obsolete("Deprecated in API8; Will be removed in API10. Please use ValueChanged event instead.")]
249 public event EventHandler<ValueChangedArgs> ValueChangedEvent
253 valueChangedHandler += value;
257 valueChangedHandler -= value;
262 /// The sliding finished event handler.
264 /// <since_tizen> 6 </since_tizen>
265 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SlidingFinished event instead.")]
266 public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
270 slidingFinishedHandler += value;
274 slidingFinishedHandler -= value;
279 /// The value changed event handler.
281 /// <since_tizen> 8 </since_tizen>
282 public event EventHandler<SliderValueChangedEventArgs> ValueChanged
286 sliderValueChangedHandler += value;
290 sliderValueChangedHandler -= value;
295 /// The sliding started event handler.
297 /// <since_tizen> 8 </since_tizen>
298 public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
302 sliderSlidingStartedHandler += value;
306 sliderSlidingStartedHandler -= value;
311 /// The sliding finished event handler.
313 /// <since_tizen> 8 </since_tizen>
314 public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
318 sliderSlidingFinishedHandler += value;
322 sliderSlidingFinishedHandler -= value;
327 /// The state changed event handler.
329 /// <since_tizen> 6 </since_tizen>
330 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
331 public event EventHandler<StateChangedArgs> StateChangedEvent
335 stateChangedHandler += value;
339 stateChangedHandler -= value;
344 /// The direction type of slider.
346 /// <since_tizen> 6 </since_tizen>
347 public enum DirectionType
350 /// The Horizontal type.
352 /// <since_tizen> 6 </since_tizen>
356 /// The Vertical type.
358 /// <since_tizen> 6 </since_tizen>
363 /// The indicator type of slider.
365 /// <since_tizen> 6 </since_tizen>
366 public enum IndicatorType
368 /// <summary> Only contains slider bar.</summary>
369 /// <since_tizen> 6 </since_tizen>
372 /// <summary> Contains slider bar, IndicatorImage.</summary>
373 /// <since_tizen> 6 </since_tizen>
376 /// <summary> Contains slider bar, IndicatorText.</summary>
377 /// <since_tizen> 6 </since_tizen>
382 /// Return currently applied style.
385 /// Modifying contents in style may cause unexpected behaviour.
387 /// <since_tizen> 8 </since_tizen>
388 public SliderStyle Style => (SliderStyle)(ViewStyle as SliderStyle)?.Clone();
391 /// Gets or sets the direction type of slider.
393 /// <since_tizen> 6 </since_tizen>
394 public DirectionType Direction
402 if (direction == value)
407 RelayoutBaseComponent(false);
409 UpdateBgTrackPosition();
410 UpdateWarningTrackSize();
416 /// Gets or sets the indicator type, arrow or sign.
418 /// <since_tizen> 6 </since_tizen>
419 public IndicatorType Indicator
423 return (IndicatorType)GetValue(IndicatorTypeProperty);
427 SetValue(IndicatorTypeProperty, value);
432 /// Gets or sets the minimum value of slider.
434 /// <since_tizen> 6 </since_tizen>
435 public float MinValue
449 /// Gets or sets the maximum value of slider.
451 /// <since_tizen> 6 </since_tizen>
452 public float MaxValue
466 /// Gets or sets the current value of slider.
468 /// <since_tizen> 6 </since_tizen>
469 public float CurrentValue
473 return (float)GetValue(CurrentValueProperty);
477 SetValue(CurrentValueProperty, value);
482 /// Gets or sets the size of the thumb image object.
484 /// <since_tizen> 6 </since_tizen>
485 public Size ThumbSize
489 return thumbImage?.Size;
493 if (null != thumbImage)
495 thumbImage.Size = value;
502 /// Gets or sets the resource url of the thumb image object.
504 /// Please use ThumbImageUrl property.
506 /// <since_tizen> 6 </since_tizen>
507 public string ThumbImageURL
511 return thumbImage?.ResourceUrl;
515 if (null != thumbImage)
517 thumbImage.ResourceUrl = value;
518 thumbImageUrl = value;
524 /// Gets or sets the resource url selector of the thumb image object.
525 /// Getter returns copied selector value if exist, null otherwise.
527 /// Please use ThumbImageUrl property.
529 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
530 /// <since_tizen> 6 </since_tizen>
531 public StringSelector ThumbImageURLSelector
533 get => thumbImage == null ? null : new StringSelector(thumbImage.ResourceUrlSelector);
536 if (value == null || thumbImage == null)
538 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
542 thumbImage.ResourceUrlSelector = value;
548 /// Gets or sets the Url of the thumb image.
550 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
551 /// <since_tizen> 9 </since_tizen>
552 public Selector<string> ThumbImageUrl
556 if (thumbImage == null)
562 return thumbImage.ResourceUrlSelector;
567 if (value == null || thumbImage == null)
569 throw new NullReferenceException("Slider.ThumbImageUrl is null");
573 thumbImage.ResourceUrlSelector = value;
579 /// Gets or sets the color of the thumb image object.
581 /// <since_tizen> 8 </since_tizen>
582 public Color ThumbColor
586 return thumbImage?.Color;
590 if (null != thumbImage)
592 thumbImage.BackgroundColor = value;
599 /// Gets or sets the color of the background track image object.
601 /// <since_tizen> 6 </since_tizen>
602 public Color BgTrackColor
606 return bgTrackImage?.BackgroundColor;
610 if (null != bgTrackImage)
612 bgTrackImage.BackgroundColor = value;
618 /// Gets or sets the color of the slided track image object.
620 /// <since_tizen> 6 </since_tizen>
621 public Color SlidedTrackColor
625 return slidedTrackImage?.BackgroundColor;
629 if (null != slidedTrackImage)
631 slidedTrackImage.BackgroundColor = value;
637 /// Gets or sets the thickness value of the track.
639 /// <since_tizen> 6 </since_tizen>
640 public uint TrackThickness
644 return (uint)GetValue(TrackThicknessProperty);
648 SetValue(TrackThicknessProperty, value);
653 /// Gets or sets the warning start value between minimum value and maximum value of slider.
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 float WarningStartValue
661 return warningStartValue;
665 warningStartValue = value;
671 /// Gets or sets the color of the warning track image object.
673 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
674 [EditorBrowsable(EditorBrowsableState.Never)]
675 public Color WarningTrackColor
679 return warningTrackImage?.BackgroundColor;
683 if (null != warningTrackImage)
685 warningTrackImage.BackgroundColor = value;
691 /// Gets or sets the color of the warning slided track image object.
693 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
694 [EditorBrowsable(EditorBrowsableState.Never)]
695 public Color WarningSlidedTrackColor
699 return warningSlidedTrackImage?.BackgroundColor;
703 if (null != warningSlidedTrackImage)
705 warningSlidedTrackImage.BackgroundColor = value;
711 /// Gets or sets the Url of the warning thumb image.
713 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
714 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
715 [EditorBrowsable(EditorBrowsableState.Never)]
716 public Selector<string> WarningThumbImageUrl
720 return warningThumbImageUrlSelector;
724 if (value == null || thumbImage == null)
726 throw new NullReferenceException("Slider.WarningThumbImageUrl is null");
730 warningThumbImageUrlSelector = value;
736 /// Gets or sets the color of the warning thumb image object.
738 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
739 [EditorBrowsable(EditorBrowsableState.Never)]
740 public Color WarningThumbColor
744 return warningThumbColor;
748 warningThumbColor = value;
753 /// Gets or sets the resource url of the low indicator image object.
755 /// <since_tizen> 6 </since_tizen>
756 public string LowIndicatorImageURL
760 return lowIndicatorImage?.ResourceUrl;
764 if (null == lowIndicatorImage) lowIndicatorImage = new ImageView();
765 lowIndicatorImage.ResourceUrl = value;
770 /// Gets or sets the resource url of the high indicator image object.
772 /// <since_tizen> 6 </since_tizen>
773 public string HighIndicatorImageURL
777 return highIndicatorImage?.ResourceUrl;
781 if (null == highIndicatorImage) highIndicatorImage = new ImageView();
782 highIndicatorImage.ResourceUrl = value;
787 /// Gets or sets the text content of the low indicator text object.
789 /// <since_tizen> 6 </since_tizen>
790 public string LowIndicatorTextContent
794 return lowIndicatorText?.Text;
798 if (null != lowIndicatorText)
800 lowIndicatorText.Text = value;
806 /// Gets or sets the text content of the high indicator text object.
808 /// <since_tizen> 6 </since_tizen>
809 public string HighIndicatorTextContent
813 return highIndicatorText?.Text;
817 if (null != highIndicatorText)
819 highIndicatorText.Text = value;
825 /// Gets or sets the size of the low indicator object(image or text).
827 /// <since_tizen> 6 </since_tizen>
828 public Size LowIndicatorSize
832 return lowIndicatorSize;
836 lowIndicatorSize = value;
837 UpdateLowIndicatorSize();
839 UpdateBgTrackPosition();
845 /// Gets or sets the size of the high indicator object(image or text).
847 /// <since_tizen> 6 </since_tizen>
848 public Size HighIndicatorSize
852 return highIndicatorText?.Size;
856 if (null != highIndicatorText)
858 highIndicatorText.Size = value;
864 /// Gets or sets the value of the space between track and indicator.
866 /// <since_tizen> 6 </since_tizen>
867 public uint SpaceBetweenTrackAndIndicator
871 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
875 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
880 /// Flag to decide whether the value indicator is shown
882 /// <since_tizen> 9 </since_tizen>
883 public bool IsValueShown
887 return (bool)GetValue(IsValueShownProperty);
891 SetValue(IsValueShownProperty, value);
896 /// Gets or sets the text of value indicator.
898 /// <since_tizen> 9 </since_tizen>
899 public string ValueIndicatorText
903 return (string)GetValue(ValueIndicatorTextProperty);
907 SetValue(ValueIndicatorTextProperty, value);
912 /// Gets or sets the size of the value indicator image object.
914 /// <since_tizen> 9 </since_tizen>
915 public Size ValueIndicatorSize
919 return valueIndicatorImage?.Size;
923 if (null != valueIndicatorImage)
925 valueIndicatorImage.Size = value;
931 /// Gets or sets the resource url of the value indicator image object.
933 /// <since_tizen> 9 </since_tizen>
934 public string ValueIndicatorUrl
938 return valueIndicatorImage?.ResourceUrl;
942 if (null != valueIndicatorImage)
944 valueIndicatorImage.ResourceUrl = value;
950 /// Flag to decide whether the thumb snaps to the nearest discrete value when the user drags the thumb or taps.
952 /// The default value is false.
954 /// <since_tizen> 9 </since_tizen>
955 public bool IsDiscrete { get; set; } = false;
958 /// Gets or sets the discrete value of slider.
961 /// The discrete value is evenly spaced between MinValue and MaxValue.
962 /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
963 /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
964 /// The default is 0.
966 /// <since_tizen> 9 </since_tizen>
967 public float DiscreteValue
971 return discreteValue;
975 discreteValue = value;
981 /// Flag to decide enable or disable in Slider.
983 [EditorBrowsable(EditorBrowsableState.Never)]
984 public bool IsEnabled
988 return (bool)GetValue(IsEnabledProperty);
992 SetValue(IsEnabledProperty, value);
996 private Extents spaceBetweenTrackAndIndicator
1000 if (null == spaceTrackIndicator)
1002 spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
1004 Extents extents = new Extents(start, end, top, bottom);
1005 spaceTrackIndicator.CopyFrom(extents);
1009 return spaceTrackIndicator;
1013 private IndicatorType privateIndicatorType
1017 return indicatorType;
1021 if (indicatorType == value)
1025 indicatorType = value;
1026 RelayoutBaseComponent(false);
1027 UpdateBgTrackSize();
1028 UpdateBgTrackPosition();
1033 private uint privateTrackThickness
1037 return trackThickness ?? 0;
1041 trackThickness = value;
1042 if (bgTrackImage != null)
1044 if (direction == DirectionType.Horizontal)
1046 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1048 else if (direction == DirectionType.Vertical)
1050 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1053 if (slidedTrackImage != null)
1055 if (direction == DirectionType.Horizontal)
1057 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1059 else if (direction == DirectionType.Vertical)
1061 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1064 if (warningTrackImage != null)
1066 if (direction == DirectionType.Horizontal)
1068 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1070 else if (direction == DirectionType.Vertical)
1072 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1075 if (warningSlidedTrackImage != null)
1077 if (direction == DirectionType.Horizontal)
1079 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1081 else if (direction == DirectionType.Vertical)
1083 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1089 private uint privateSpaceBetweenTrackAndIndicator
1093 return privateTrackPadding.Start;
1097 ushort val = (ushort)value;
1098 privateTrackPadding = new Extents(val, val, val, val);
1102 private Extents privateTrackPadding
1106 return spaceBetweenTrackAndIndicator;
1110 spaceBetweenTrackAndIndicator.CopyFrom(value);
1111 UpdateComponentByIndicatorTypeChanged();
1112 UpdateBgTrackSize();
1113 UpdateBgTrackPosition();
1119 /// Focus gained callback.
1121 /// <since_tizen> 8 </since_tizen>
1122 public override void OnFocusGained()
1124 //State = ControlStates.Focused;
1125 UpdateState(true, isPressed);
1126 base.OnFocusGained();
1130 /// Focus Lost callback.
1132 /// <since_tizen> 8 </since_tizen>
1133 public override void OnFocusLost()
1135 //State = ControlStates.Normal;
1136 UpdateState(false, isPressed);
1141 [EditorBrowsable(EditorBrowsableState.Never)]
1142 public override bool OnKey(Key key)
1144 if (!IsEnabled || null == key)
1149 if (key.State == Key.StateType.Down)
1151 if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Left") ||
1152 (direction == DirectionType.Vertical && key.KeyPressedName == "Down"))
1154 if (MinValue < CurrentValue)
1159 float value = CurrentValue - discreteValue;
1160 CurrentValue = value < MinValue ? MinValue : value;
1166 return true; // Consumed
1169 else if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Right") ||
1170 (direction == DirectionType.Vertical && key.KeyPressedName == "Up"))
1172 if (MaxValue > CurrentValue)
1177 float value = CurrentValue + discreteValue;
1178 CurrentValue = value > MaxValue ? MaxValue : value;
1184 return true; // Consumed
1188 else if (key.State == Key.StateType.Up)
1197 /// Apply style to scrollbar.
1199 /// <param name="viewStyle">The style to apply.</param>
1200 /// <since_tizen> 8 </since_tizen>
1201 public override void ApplyStyle(ViewStyle viewStyle)
1203 base.ApplyStyle(viewStyle);
1205 SliderStyle sliderStyle = viewStyle as SliderStyle;
1207 if (null != sliderStyle?.Progress)
1209 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1212 if (null != sliderStyle?.LowIndicator)
1214 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1217 if (null != sliderStyle?.HighIndicator)
1219 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1222 if (null != sliderStyle?.Track)
1224 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1227 if (null != sliderStyle?.Thumb)
1229 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1232 if (null != sliderStyle?.ValueIndicatorText)
1234 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1237 if (null != sliderStyle?.ValueIndicatorImage)
1239 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1242 if (null != sliderStyle?.WarningTrack)
1244 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1247 if (null != sliderStyle?.WarningProgress)
1249 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1252 EnableControlStatePropagation = true;
1256 /// Prevents from showing child widgets in AT-SPI tree.
1258 [EditorBrowsable(EditorBrowsableState.Never)]
1259 protected override bool AccessibilityShouldReportZeroChildren()
1265 /// Gets minimum value for Accessibility.
1267 [EditorBrowsable(EditorBrowsableState.Never)]
1268 protected override double AccessibilityGetMinimum()
1270 return (double)MinValue;
1274 /// Gets the current value for Accessibility.
1276 [EditorBrowsable(EditorBrowsableState.Never)]
1277 protected override double AccessibilityGetCurrent()
1279 return (double)CurrentValue;
1283 /// Gets maximum value for Accessibility.
1285 [EditorBrowsable(EditorBrowsableState.Never)]
1286 protected override double AccessibilityGetMaximum()
1288 return (double)MaxValue;
1292 /// Sets the current value using Accessibility.
1294 [EditorBrowsable(EditorBrowsableState.Never)]
1295 protected override bool AccessibilitySetCurrent(double value)
1297 var current = (float)value;
1299 if (current >= MinValue && current <= MaxValue)
1301 CurrentValue = current;
1302 if (sliderValueChangedHandler != null)
1304 sliderValueChangedHandler(this, new SliderValueChangedEventArgs { CurrentValue = current });
1313 /// Gets minimum increment for Accessibility.
1315 [EditorBrowsable(EditorBrowsableState.Never)]
1316 protected override double AccessibilityGetMinimumIncrement()
1319 return (MaxValue - MinValue) / 20.0;
1323 /// Initialize AT-SPI object.
1325 [EditorBrowsable(EditorBrowsableState.Never)]
1326 public override void OnInitialize()
1328 base.OnInitialize();
1329 SetAccessibilityConstructor(Role.Slider, AccessibilityInterface.Value);
1333 /// Get Slider style.
1335 /// <returns>The default slider style.</returns>
1336 /// <since_tizen> 8 </since_tizen>
1337 protected override ViewStyle CreateViewStyle()
1339 return new SliderStyle();
1345 /// <param name="type">Dispose type.</param>
1346 /// <since_tizen> 6 </since_tizen>
1347 protected override void Dispose(DisposeTypes type)
1354 if (type == DisposeTypes.Explicit)
1356 if (null != panGestureDetector)
1358 panGestureDetector.Detach(this);
1359 panGestureDetector.Detected -= OnPanGestureDetected;
1360 panGestureDetector.Dispose();
1361 panGestureDetector = null;
1364 if (null != thumbImage)
1366 thumbImage.TouchEvent -= OnTouchEventForThumb;
1367 Utility.Dispose(thumbImage);
1369 Utility.Dispose(warningSlidedTrackImage);
1370 Utility.Dispose(warningTrackImage);
1371 Utility.Dispose(slidedTrackImage);
1372 Utility.Dispose(bgTrackImage);
1373 Utility.Dispose(lowIndicatorImage);
1374 Utility.Dispose(highIndicatorImage);
1375 Utility.Dispose(lowIndicatorText);
1376 Utility.Dispose(highIndicatorText);
1377 Utility.Dispose(valueIndicatorImage);
1378 Utility.Dispose(valueIndicatorText);
1380 this.TouchEvent -= OnTouchEventForTrack;
1387 /// Update Slider by style.
1389 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1390 [EditorBrowsable(EditorBrowsableState.Never)]
1391 protected override void OnUpdate()
1393 RelayoutBaseComponent();
1395 UpdateComponentByIndicatorTypeChanged();
1396 UpdateBgTrackSize();
1397 UpdateBgTrackPosition();
1398 UpdateWarningTrackSize();
1399 UpdateLowIndicatorSize();
1403 private void CalculateCurrentValueByGesture(float offset)
1405 currentSlidedOffset += offset;
1407 if (currentSlidedOffset <= 0)
1409 this.CurrentValue = minValue;
1411 else if (currentSlidedOffset >= BgTrackLength())
1413 this.CurrentValue = maxValue;
1417 int bgTrackLength = BgTrackLength();
1418 if (bgTrackLength != 0)
1420 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1426 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1429 if (valueChangedHandler != null)
1431 ValueChangedArgs args = new ValueChangedArgs();
1432 args.CurrentValue = this.CurrentValue;
1433 valueChangedHandler(this, args);
1436 if (sliderValueChangedHandler != null)
1438 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1439 args.CurrentValue = this.CurrentValue;
1440 sliderValueChangedHandler(this, args);
1444 private bool OnTouchEventForTrack(object source, TouchEventArgs e)
1451 PointStateType state = e.Touch.GetState(0);
1452 if (state == PointStateType.Down)
1456 valueIndicatorImage.Show();
1459 Vector2 pos = e.Touch.GetLocalPosition(0);
1460 CalculateCurrentValueByTouch(pos);
1462 if (null != slidingFinishedHandler)
1464 SlidingFinishedArgs args = new SlidingFinishedArgs();
1465 args.CurrentValue = curValue;
1466 slidingFinishedHandler(this, args);
1469 if (null != sliderSlidingFinishedHandler)
1471 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
1472 args.CurrentValue = curValue;
1473 sliderSlidingFinishedHandler(this, args);
1476 else if (state == PointStateType.Up)
1480 valueIndicatorImage.Hide();
1486 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1488 PointStateType state = e.Touch.GetState(0);
1489 if (state == PointStateType.Down)
1491 UpdateState(isFocused, true);
1493 else if (state == PointStateType.Up)
1495 UpdateState(isFocused, false);
1500 private void CalculateCurrentValueByTouch(Vector2 pos)
1502 int bgTrackLength = BgTrackLength();
1503 if (direction == DirectionType.Horizontal)
1505 currentSlidedOffset = pos.X;
1507 else if (direction == DirectionType.Vertical)
1509 currentSlidedOffset = bgTrackLength - pos.Y;
1512 if (bgTrackLength != 0)
1514 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1518 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1521 if (null != valueChangedHandler)
1523 ValueChangedArgs args = new ValueChangedArgs();
1524 args.CurrentValue = this.CurrentValue;
1525 valueChangedHandler(this, args);
1528 if (null != sliderValueChangedHandler)
1530 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1531 args.CurrentValue = this.CurrentValue;
1532 sliderValueChangedHandler(this, args);
1537 private float CalculateDiscreteValue(float value)
1539 return ((float)Math.Round((value / discreteValue)) * discreteValue);
1542 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1544 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1548 if (thumbImage == null || Style == null)
1552 isFocused = isFocusedNew;
1553 isPressed = isPressedNew;
1555 if(!IsEnabled) // Disabled
1557 ControlState = ControlState.Disabled;
1559 if (stateChangedHandler != null)
1561 StateChangedArgs args = new StateChangedArgs();
1562 args.CurrentState = (ControlStates)ControlStates.Disabled;
1563 stateChangedHandler(this, args);
1566 else if (!isFocused && !isPressed)
1568 ControlState = ControlState.Normal;
1570 if (stateChangedHandler != null)
1572 StateChangedArgs args = new StateChangedArgs();
1573 args.CurrentState = (ControlStates)ControlStates.Normal;
1574 stateChangedHandler(this, args);
1579 ControlState = ControlState.Pressed;
1581 if (stateChangedHandler != null)
1583 StateChangedArgs args = new StateChangedArgs();
1584 args.CurrentState = (ControlStates)ControlStates.Pressed;
1585 stateChangedHandler(this, args);
1588 else if (!isPressed && isFocused)
1590 ControlState = ControlState.Focused;
1592 if (stateChangedHandler != null)
1594 StateChangedArgs args = new StateChangedArgs();
1595 args.CurrentState = (ControlStates)ControlStates.Focused;
1596 stateChangedHandler(this, args);
1601 private void UpdateComponentByIndicatorTypeChanged()
1603 IndicatorType type = CurrentIndicatorType();
1604 if (type == IndicatorType.None)
1606 if (lowIndicatorImage != null)
1608 lowIndicatorImage.Hide();
1610 if (highIndicatorImage != null)
1612 highIndicatorImage.Hide();
1614 if (lowIndicatorText != null)
1616 lowIndicatorText.Hide();
1618 if (highIndicatorText != null)
1620 highIndicatorText.Hide();
1623 else if (type == IndicatorType.Image)
1625 if (lowIndicatorImage != null)
1627 lowIndicatorImage.Show();
1629 if (highIndicatorImage != null)
1631 highIndicatorImage.Show();
1633 if (lowIndicatorText != null)
1635 lowIndicatorText.Hide();
1637 if (highIndicatorText != null)
1639 highIndicatorText.Hide();
1642 else if (type == IndicatorType.Text)
1644 if (lowIndicatorText != null)
1646 lowIndicatorText.Show();
1648 if (highIndicatorText != null)
1650 highIndicatorText.Show();
1652 if (lowIndicatorImage != null)
1654 lowIndicatorImage.Hide();
1656 if (highIndicatorImage != null)
1658 highIndicatorImage.Hide();
1664 /// Value Changed event data.
1666 /// <since_tizen> 6 </since_tizen>
1667 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
1668 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1669 public class ValueChangedArgs : EventArgs
1674 /// <since_tizen> 6 </since_tizen>
1675 /// It will be removed in API10
1676 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1677 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
1678 public float CurrentValue;
1682 /// Value Changed event data.
1684 /// <since_tizen> 6 </since_tizen>
1685 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
1686 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1687 public class SlidingFinishedArgs : EventArgs
1692 /// <since_tizen> 6 </since_tizen>
1693 /// It will be removed in API10
1694 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1695 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
1696 public float CurrentValue;
1700 /// State Changed event data.
1702 /// <since_tizen> 6 </since_tizen>
1703 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
1704 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1705 public class StateChangedArgs : EventArgs
1710 /// <since_tizen> 6 </since_tizen>
1711 /// It will be removed in API10
1712 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1713 [Obsolete("Deprecated in API8; Will be removed in API10")]
1714 public ControlStates CurrentState;