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 /// SpaceBetweenTrackAndIndicatorProperty
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 public static readonly BindableProperty IndicatorProperty = BindableProperty.Create(nameof(Indicator), 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.IsEnabled && instance.IsHighlighted)
181 instance.EmitAccessibilityEvent(AccessibilityPropertyChangeEvent.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
378 return (DirectionType)GetValue(DirectionProperty);
382 SetValue(DirectionProperty, value);
383 NotifyPropertyChanged();
386 private DirectionType InternalDirection
394 if (direction == value)
399 RelayoutBaseComponent(false);
401 UpdateBgTrackPosition();
402 UpdateWarningTrackSize();
408 /// Gets or sets the indicator type, arrow or sign.
410 /// <since_tizen> 6 </since_tizen>
411 public IndicatorType Indicator
415 return (IndicatorType)GetValue(IndicatorProperty);
419 SetValue(IndicatorProperty, value);
424 /// Gets or sets the minimum value of slider.
426 /// <since_tizen> 6 </since_tizen>
427 public float MinValue
431 return (float)GetValue(MinValueProperty);
435 SetValue(MinValueProperty, value);
436 NotifyPropertyChanged();
439 private float InternalMinValue
453 /// Gets or sets the maximum value of slider.
455 /// <since_tizen> 6 </since_tizen>
456 public float MaxValue
460 return (float)GetValue(MaxValueProperty);
464 SetValue(MaxValueProperty, value);
465 NotifyPropertyChanged();
468 private float InternalMaxValue
482 /// Gets or sets the current value of slider.
484 /// <since_tizen> 6 </since_tizen>
485 public float CurrentValue
489 return (float)GetValue(CurrentValueProperty);
493 SetValue(CurrentValueProperty, value);
498 /// Gets or sets the size of the thumb image object.
500 /// <since_tizen> 6 </since_tizen>
501 public Size ThumbSize
505 return GetValue(ThumbSizeProperty) as Size;
509 SetValue(ThumbSizeProperty, value);
510 NotifyPropertyChanged();
513 private Size InternalThumbSize
517 return thumbImage?.Size;
521 if (null != thumbImage)
523 thumbImage.Size = value;
530 /// Gets or sets the resource url of the thumb image object.
532 /// Please use ThumbImageUrl property.
534 /// <since_tizen> 6 </since_tizen>
535 public string ThumbImageURL
539 return GetValue(ThumbImageURLProperty) as string;
543 SetValue(ThumbImageURLProperty, value);
544 NotifyPropertyChanged();
547 private string InternalThumbImageURL
551 return thumbImage?.ResourceUrl;
555 if (null != thumbImage)
557 thumbImage.ResourceUrl = value;
558 thumbImageUrl = value;
564 /// Gets or sets the resource url selector of the thumb image object.
565 /// Getter returns copied selector value if exist, null otherwise.
567 /// Please use ThumbImageUrl property.
569 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
570 /// <since_tizen> 6 </since_tizen>
571 public StringSelector ThumbImageURLSelector
575 return GetValue(ThumbImageURLSelectorProperty) as StringSelector;
579 SetValue(ThumbImageURLSelectorProperty, value);
580 NotifyPropertyChanged();
583 private StringSelector InternalThumbImageURLSelector
585 get => thumbImage?.ResourceUrlSelector == null ? null : new StringSelector(thumbImage.ResourceUrlSelector);
588 if (value == null || thumbImage == null)
590 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
594 thumbImage.ResourceUrlSelector = value;
600 /// Gets or sets the Url of the thumb image.
602 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
603 /// <since_tizen> 9 </since_tizen>
604 public Selector<string> ThumbImageUrl
608 return GetValue(ThumbImageUrlProperty) as Selector<string>;
612 SetValue(ThumbImageUrlProperty, value);
613 NotifyPropertyChanged();
616 private Selector<string> InternalThumbImageUrl
620 if (thumbImage == null)
626 return thumbImage.ResourceUrlSelector;
631 if (value == null || thumbImage == null)
633 throw new NullReferenceException("Slider.ThumbImageUrl is null");
637 thumbImage.ResourceUrlSelector = value;
643 /// Gets or sets the color of the thumb image object.
645 /// <since_tizen> 8 </since_tizen>
646 public Color ThumbColor
650 return GetValue(ThumbColorProperty) as Color;
654 SetValue(ThumbColorProperty, value);
655 NotifyPropertyChanged();
658 private Color InternalThumbColor
662 return thumbImage?.Color;
666 if (null != thumbImage)
668 thumbImage.BackgroundColor = value;
675 /// Gets or sets the color of the background track image object.
677 /// <since_tizen> 6 </since_tizen>
678 public Color BgTrackColor
682 return GetValue(BgTrackColorProperty) as Color;
686 SetValue(BgTrackColorProperty, value);
687 NotifyPropertyChanged();
690 private Color InternalBgTrackColor
694 return bgTrackImage?.BackgroundColor;
698 if (null != bgTrackImage)
700 bgTrackImage.BackgroundColor = value;
706 /// Gets or sets the color of the slided track image object.
708 /// <since_tizen> 6 </since_tizen>
709 public Color SlidedTrackColor
713 return GetValue(SlidedTrackColorProperty) as Color;
717 SetValue(SlidedTrackColorProperty, value);
718 NotifyPropertyChanged();
721 private Color InternalSlidedTrackColor
725 return slidedTrackImage?.BackgroundColor;
729 if (null != slidedTrackImage)
731 slidedTrackImage.BackgroundColor = value;
737 /// Gets or sets the thickness value of the track.
739 /// <since_tizen> 6 </since_tizen>
740 public uint TrackThickness
744 return (uint)GetValue(TrackThicknessProperty);
748 SetValue(TrackThicknessProperty, value);
753 /// Gets or sets the warning start value between minimum value and maximum value of slider.
755 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
756 [EditorBrowsable(EditorBrowsableState.Never)]
757 public float WarningStartValue
761 return (float)GetValue(WarningStartValueProperty);
765 SetValue(WarningStartValueProperty, value);
766 NotifyPropertyChanged();
769 private float InternalWarningStartValue
773 return warningStartValue;
777 warningStartValue = value;
783 /// Gets or sets the color of the warning track image object.
785 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
786 [EditorBrowsable(EditorBrowsableState.Never)]
787 public Color WarningTrackColor
791 return GetValue(WarningTrackColorProperty) as Color;
795 SetValue(WarningTrackColorProperty, value);
796 NotifyPropertyChanged();
799 private Color InternalWarningTrackColor
803 return warningTrackImage?.BackgroundColor;
807 if (null != warningTrackImage)
809 warningTrackImage.BackgroundColor = value;
815 /// Gets or sets the color of the warning slided track image object.
817 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
818 [EditorBrowsable(EditorBrowsableState.Never)]
819 public Color WarningSlidedTrackColor
823 return GetValue(WarningSlidedTrackColorProperty) as Color;
827 SetValue(WarningSlidedTrackColorProperty, value);
828 NotifyPropertyChanged();
831 private Color InternalWarningSlidedTrackColor
835 return warningSlidedTrackImage?.BackgroundColor;
839 if (null != warningSlidedTrackImage)
841 warningSlidedTrackImage.BackgroundColor = value;
847 /// Gets or sets the Url of the warning thumb image.
849 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
850 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
851 [EditorBrowsable(EditorBrowsableState.Never)]
852 public Selector<string> WarningThumbImageUrl
856 return GetValue(WarningThumbImageUrlProperty) as Selector<string>;
860 SetValue(WarningThumbImageUrlProperty, value);
861 NotifyPropertyChanged();
864 private Selector<string> InternalWarningThumbImageUrl
868 return warningThumbImageUrlSelector;
872 if (value == null || thumbImage == null)
874 throw new NullReferenceException("Slider.WarningThumbImageUrl is null");
878 warningThumbImageUrlSelector = value;
884 /// Gets or sets the color of the warning thumb image object.
886 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
887 [EditorBrowsable(EditorBrowsableState.Never)]
888 public Color WarningThumbColor
892 return GetValue(WarningThumbColorProperty) as Color;
896 SetValue(WarningThumbColorProperty, value);
897 NotifyPropertyChanged();
900 private Color InternalWarningThumbColor
904 return warningThumbColor;
908 warningThumbColor = value;
913 /// Gets or sets the resource url of the low indicator image object.
915 /// <since_tizen> 6 </since_tizen>
916 public string LowIndicatorImageURL
920 return GetValue(LowIndicatorImageURLProperty) as string;
924 SetValue(LowIndicatorImageURLProperty, value);
925 NotifyPropertyChanged();
928 private string InternalLowIndicatorImageURL
932 return lowIndicatorImage?.ResourceUrl;
936 if (null == lowIndicatorImage) lowIndicatorImage = new ImageView();
937 lowIndicatorImage.ResourceUrl = value;
942 /// Gets or sets the resource url of the high indicator image object.
944 /// <since_tizen> 6 </since_tizen>
945 public string HighIndicatorImageURL
949 return GetValue(HighIndicatorImageURLProperty) as string;
953 SetValue(HighIndicatorImageURLProperty, value);
954 NotifyPropertyChanged();
957 private string InternalHighIndicatorImageURL
961 return highIndicatorImage?.ResourceUrl;
965 if (null == highIndicatorImage) highIndicatorImage = new ImageView();
966 highIndicatorImage.ResourceUrl = value;
971 /// Gets or sets the text content of the low indicator text object.
973 /// <since_tizen> 6 </since_tizen>
974 public string LowIndicatorTextContent
978 return GetValue(LowIndicatorTextContentProperty) as string;
982 SetValue(LowIndicatorTextContentProperty, value);
983 NotifyPropertyChanged();
986 private string InternalLowIndicatorTextContent
990 return lowIndicatorText?.Text;
994 if (null != lowIndicatorText)
996 lowIndicatorText.Text = value;
1002 /// Gets or sets the text content of the high indicator text object.
1004 /// <since_tizen> 6 </since_tizen>
1005 public string HighIndicatorTextContent
1009 return GetValue(HighIndicatorTextContentProperty) as string;
1013 SetValue(HighIndicatorTextContentProperty, value);
1014 NotifyPropertyChanged();
1017 private string InternalHighIndicatorTextContent
1021 return highIndicatorText?.Text;
1025 if (null != highIndicatorText)
1027 highIndicatorText.Text = value;
1033 /// Gets or sets the size of the low indicator object(image or text).
1035 /// <since_tizen> 6 </since_tizen>
1036 public Size LowIndicatorSize
1040 return GetValue(LowIndicatorSizeProperty) as Size;
1044 SetValue(LowIndicatorSizeProperty, value);
1045 NotifyPropertyChanged();
1048 private Size InternalLowIndicatorSize
1052 return lowIndicatorSize;
1056 lowIndicatorSize = value;
1057 UpdateLowIndicatorSize();
1058 UpdateBgTrackSize();
1059 UpdateBgTrackPosition();
1065 /// Gets or sets the size of the high indicator object(image or text).
1067 /// <since_tizen> 6 </since_tizen>
1068 public Size HighIndicatorSize
1072 return GetValue(HighIndicatorSizeProperty) as Size;
1076 SetValue(HighIndicatorSizeProperty, value);
1077 NotifyPropertyChanged();
1080 private Size InternalHighIndicatorSize
1084 return highIndicatorText?.Size;
1088 if (null != highIndicatorText)
1090 highIndicatorText.Size = value;
1096 /// Gets or sets the value of the space between track and indicator.
1098 /// <since_tizen> 6 </since_tizen>
1099 public uint SpaceBetweenTrackAndIndicator
1103 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
1107 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
1112 /// Flag to decide whether the value indicator is shown
1114 /// <since_tizen> 9 </since_tizen>
1115 public bool IsValueShown
1119 return (bool)GetValue(IsValueShownProperty);
1123 SetValue(IsValueShownProperty, value);
1128 /// Gets or sets the text of value indicator.
1130 /// <since_tizen> 9 </since_tizen>
1131 public string ValueIndicatorText
1135 return (string)GetValue(ValueIndicatorTextProperty);
1139 SetValue(ValueIndicatorTextProperty, value);
1144 /// Gets or sets the size of the value indicator image object.
1146 /// <since_tizen> 9 </since_tizen>
1147 public Size ValueIndicatorSize
1151 return GetValue(ValueIndicatorSizeProperty) as Size;
1155 SetValue(ValueIndicatorSizeProperty, value);
1156 NotifyPropertyChanged();
1159 private Size InternalValueIndicatorSize
1163 return valueIndicatorImage?.Size;
1167 if (null != valueIndicatorImage)
1169 valueIndicatorImage.Size = value;
1175 /// Gets or sets the resource url of the value indicator image object.
1177 /// <since_tizen> 9 </since_tizen>
1178 public string ValueIndicatorUrl
1182 return GetValue(ValueIndicatorUrlProperty) as string;
1186 SetValue(ValueIndicatorUrlProperty, value);
1187 NotifyPropertyChanged();
1190 private string InternalValueIndicatorUrl
1194 return valueIndicatorImage?.ResourceUrl;
1198 if (null != valueIndicatorImage)
1200 valueIndicatorImage.ResourceUrl = value;
1206 /// Flag to decide whether the thumb snaps to the nearest discrete value when the user drags the thumb or taps.
1208 /// The default value is false.
1210 /// <since_tizen> 9 </since_tizen>
1211 public bool IsDiscrete
1215 return (bool)GetValue(IsDiscreteProperty);
1219 SetValue(IsDiscreteProperty, value);
1220 NotifyPropertyChanged();
1223 private bool InternalIsDiscrete { get; set; } = false;
1226 /// Gets or sets the discrete value of slider.
1229 /// The discrete value is evenly spaced between MinValue and MaxValue.
1230 /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
1231 /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
1232 /// The default is 0.
1234 /// <since_tizen> 9 </since_tizen>
1235 public float DiscreteValue
1239 return (float)GetValue(DiscreteValueProperty);
1243 SetValue(DiscreteValueProperty, value);
1244 NotifyPropertyChanged();
1247 private float InternalDiscreteValue
1251 return discreteValue;
1255 discreteValue = value;
1260 private Extents spaceBetweenTrackAndIndicator
1264 if (null == spaceTrackIndicator)
1266 spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
1268 Extents extents = new Extents(start, end, top, bottom);
1269 spaceTrackIndicator.CopyFrom(extents);
1273 return spaceTrackIndicator;
1277 private IndicatorType privateIndicatorType
1281 return indicatorType;
1285 if (indicatorType == value)
1289 indicatorType = value;
1290 RelayoutBaseComponent(false);
1291 UpdateBgTrackSize();
1292 UpdateBgTrackPosition();
1297 private uint privateTrackThickness
1301 return trackThickness ?? 0;
1305 trackThickness = value;
1306 if (bgTrackImage != null)
1308 if (direction == DirectionType.Horizontal)
1310 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1312 else if (direction == DirectionType.Vertical)
1314 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1317 if (slidedTrackImage != null)
1319 if (direction == DirectionType.Horizontal)
1321 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1323 else if (direction == DirectionType.Vertical)
1325 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1328 if (warningTrackImage != null)
1330 if (direction == DirectionType.Horizontal)
1332 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1334 else if (direction == DirectionType.Vertical)
1336 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1339 if (warningSlidedTrackImage != null)
1341 if (direction == DirectionType.Horizontal)
1343 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1345 else if (direction == DirectionType.Vertical)
1347 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1353 private uint privateSpaceBetweenTrackAndIndicator
1357 return privateTrackPadding.Start;
1361 ushort val = (ushort)value;
1362 privateTrackPadding = new Extents(val, val, val, val);
1366 private Extents privateTrackPadding
1370 return spaceBetweenTrackAndIndicator;
1374 spaceBetweenTrackAndIndicator.CopyFrom(value);
1375 UpdateComponentByIndicatorTypeChanged();
1376 UpdateBgTrackSize();
1377 UpdateBgTrackPosition();
1383 /// Focus gained callback.
1385 /// <since_tizen> 8 </since_tizen>
1386 public override void OnFocusGained()
1388 //State = ControlStates.Focused;
1389 UpdateState(true, isPressed);
1390 base.OnFocusGained();
1394 /// Focus Lost callback.
1396 /// <since_tizen> 8 </since_tizen>
1397 public override void OnFocusLost()
1399 //State = ControlStates.Normal;
1400 UpdateState(false, isPressed);
1405 [EditorBrowsable(EditorBrowsableState.Never)]
1406 public override bool OnKey(Key key)
1408 if (!IsEnabled || null == key)
1413 if (key.State == Key.StateType.Down)
1415 if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Left") ||
1416 (direction == DirectionType.Vertical && key.KeyPressedName == "Down"))
1418 if (MinValue < CurrentValue)
1423 float value = CurrentValue - discreteValue;
1424 CurrentValue = value < MinValue ? MinValue : value;
1430 return true; // Consumed
1433 else if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Right") ||
1434 (direction == DirectionType.Vertical && key.KeyPressedName == "Up"))
1436 if (MaxValue > CurrentValue)
1441 float value = CurrentValue + discreteValue;
1442 CurrentValue = value > MaxValue ? MaxValue : value;
1448 return true; // Consumed
1452 else if (key.State == Key.StateType.Up)
1461 /// Apply style to scrollbar.
1463 /// <param name="viewStyle">The style to apply.</param>
1464 /// <since_tizen> 8 </since_tizen>
1465 public override void ApplyStyle(ViewStyle viewStyle)
1467 base.ApplyStyle(viewStyle);
1469 SliderStyle sliderStyle = viewStyle as SliderStyle;
1471 if (null != sliderStyle?.Progress)
1473 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1476 if (null != sliderStyle?.LowIndicator)
1478 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1481 if (null != sliderStyle?.HighIndicator)
1483 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1486 if (null != sliderStyle?.Track)
1488 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1491 if (null != sliderStyle?.Thumb)
1493 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1496 if (null != sliderStyle?.ValueIndicatorText)
1498 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1501 if (null != sliderStyle?.ValueIndicatorImage)
1503 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1506 if (null != sliderStyle?.WarningTrack)
1508 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1511 if (null != sliderStyle?.WarningProgress)
1513 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1516 EnableControlStatePropagation = true;
1520 /// Prevents from showing child widgets in AT-SPI tree.
1522 [EditorBrowsable(EditorBrowsableState.Never)]
1523 protected override bool AccessibilityShouldReportZeroChildren()
1529 /// Gets minimum value for Accessibility.
1531 [EditorBrowsable(EditorBrowsableState.Never)]
1532 protected override double AccessibilityGetMinimum()
1534 return (double)MinValue;
1538 /// Gets the current value for Accessibility.
1540 [EditorBrowsable(EditorBrowsableState.Never)]
1541 protected override double AccessibilityGetCurrent()
1543 return (double)CurrentValue;
1547 /// Gets maximum value for Accessibility.
1549 [EditorBrowsable(EditorBrowsableState.Never)]
1550 protected override double AccessibilityGetMaximum()
1552 return (double)MaxValue;
1556 /// Sets the current value using Accessibility.
1558 [EditorBrowsable(EditorBrowsableState.Never)]
1559 protected override bool AccessibilitySetCurrent(double value)
1561 var current = (float)value;
1563 if (current >= MinValue && current <= MaxValue)
1565 CurrentValue = current;
1566 if (sliderValueChangedHandler != null)
1568 sliderValueChangedHandler(this, new SliderValueChangedEventArgs { CurrentValue = current });
1577 /// Gets minimum increment for Accessibility.
1579 [EditorBrowsable(EditorBrowsableState.Never)]
1580 protected override double AccessibilityGetMinimumIncrement()
1583 return (MaxValue - MinValue) / 20.0;
1587 /// Initialize AT-SPI object.
1589 [EditorBrowsable(EditorBrowsableState.Never)]
1590 public override void OnInitialize()
1592 base.OnInitialize();
1593 SetAccessibilityConstructor(Role.Slider, AccessibilityInterface.Value);
1597 /// Get Slider style.
1599 /// <returns>The default slider style.</returns>
1600 /// <since_tizen> 8 </since_tizen>
1601 protected override ViewStyle CreateViewStyle()
1603 return new SliderStyle();
1609 /// <param name="type">Dispose type.</param>
1610 /// <since_tizen> 6 </since_tizen>
1611 protected override void Dispose(DisposeTypes type)
1618 if (type == DisposeTypes.Explicit)
1620 if (null != panGestureDetector)
1622 panGestureDetector.Detach(this);
1623 panGestureDetector.Detected -= OnPanGestureDetected;
1624 panGestureDetector.Dispose();
1625 panGestureDetector = null;
1628 if (null != thumbImage)
1630 thumbImage.TouchEvent -= OnTouchEventForThumb;
1631 Utility.Dispose(thumbImage);
1633 Utility.Dispose(warningSlidedTrackImage);
1634 Utility.Dispose(warningTrackImage);
1635 Utility.Dispose(slidedTrackImage);
1636 Utility.Dispose(bgTrackImage);
1637 Utility.Dispose(lowIndicatorImage);
1638 Utility.Dispose(highIndicatorImage);
1639 Utility.Dispose(lowIndicatorText);
1640 Utility.Dispose(highIndicatorText);
1641 Utility.Dispose(valueIndicatorImage);
1642 Utility.Dispose(valueIndicatorText);
1644 this.TouchEvent -= OnTouchEventForTrack;
1651 /// Update Slider by style.
1653 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1654 [EditorBrowsable(EditorBrowsableState.Never)]
1655 protected override void OnUpdate()
1657 RelayoutBaseComponent();
1659 UpdateComponentByIndicatorTypeChanged();
1660 UpdateBgTrackSize();
1661 UpdateBgTrackPosition();
1662 UpdateWarningTrackSize();
1663 UpdateLowIndicatorSize();
1668 [EditorBrowsable(EditorBrowsableState.Never)]
1669 protected override void OnEnabled(bool enabled)
1671 base.OnEnabled(enabled);
1675 private void CalculateCurrentValueByGesture(float offset)
1677 currentSlidedOffset += offset;
1679 if (currentSlidedOffset <= 0)
1681 this.CurrentValue = minValue;
1683 else if (currentSlidedOffset >= BgTrackLength())
1685 this.CurrentValue = maxValue;
1689 int bgTrackLength = BgTrackLength();
1690 if (bgTrackLength != 0)
1692 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1698 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1701 if (valueChangedHandler != null)
1703 ValueChangedArgs args = new ValueChangedArgs();
1704 args.CurrentValue = this.CurrentValue;
1705 valueChangedHandler(this, args);
1708 if (sliderValueChangedHandler != null)
1710 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1711 args.CurrentValue = this.CurrentValue;
1712 sliderValueChangedHandler(this, args);
1716 private bool OnTouchEventForTrack(object source, TouchEventArgs e)
1723 PointStateType state = e.Touch.GetState(0);
1724 if (state == PointStateType.Down)
1728 valueIndicatorImage.Show();
1731 Vector2 pos = e.Touch.GetLocalPosition(0);
1732 CalculateCurrentValueByTouch(pos);
1734 if (null != slidingFinishedHandler)
1736 SlidingFinishedArgs args = new SlidingFinishedArgs();
1737 args.CurrentValue = curValue;
1738 slidingFinishedHandler(this, args);
1741 if (null != sliderSlidingFinishedHandler)
1743 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
1744 args.CurrentValue = curValue;
1745 sliderSlidingFinishedHandler(this, args);
1748 else if (state == PointStateType.Up)
1752 valueIndicatorImage.Hide();
1758 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1760 PointStateType state = e.Touch.GetState(0);
1761 if (state == PointStateType.Down)
1763 UpdateState(isFocused, true);
1765 else if (state == PointStateType.Up)
1767 UpdateState(isFocused, false);
1772 private void CalculateCurrentValueByTouch(Vector2 pos)
1774 int bgTrackLength = BgTrackLength();
1775 if (direction == DirectionType.Horizontal)
1777 currentSlidedOffset = pos.X;
1779 else if (direction == DirectionType.Vertical)
1781 currentSlidedOffset = bgTrackLength - pos.Y;
1784 if (bgTrackLength != 0)
1786 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1790 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1793 if (null != valueChangedHandler)
1795 ValueChangedArgs args = new ValueChangedArgs();
1796 args.CurrentValue = this.CurrentValue;
1797 valueChangedHandler(this, args);
1800 if (null != sliderValueChangedHandler)
1802 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1803 args.CurrentValue = this.CurrentValue;
1804 sliderValueChangedHandler(this, args);
1809 private float CalculateDiscreteValue(float value)
1811 return ((float)Math.Round((value / discreteValue)) * discreteValue);
1814 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1816 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1820 if (thumbImage == null || Style == null)
1824 isFocused = isFocusedNew;
1825 isPressed = isPressedNew;
1827 if(!IsEnabled) // Disabled
1829 ControlState = ControlState.Disabled;
1831 if (stateChangedHandler != null)
1833 StateChangedArgs args = new StateChangedArgs();
1834 args.CurrentState = (ControlStates)ControlStates.Disabled;
1835 stateChangedHandler(this, args);
1838 else if (!isFocused && !isPressed)
1840 ControlState = ControlState.Normal;
1842 if (stateChangedHandler != null)
1844 StateChangedArgs args = new StateChangedArgs();
1845 args.CurrentState = (ControlStates)ControlStates.Normal;
1846 stateChangedHandler(this, args);
1851 ControlState = ControlState.Pressed;
1853 if (stateChangedHandler != null)
1855 StateChangedArgs args = new StateChangedArgs();
1856 args.CurrentState = (ControlStates)ControlStates.Pressed;
1857 stateChangedHandler(this, args);
1860 else if (!isPressed && isFocused)
1862 ControlState = ControlState.Focused;
1864 if (stateChangedHandler != null)
1866 StateChangedArgs args = new StateChangedArgs();
1867 args.CurrentState = (ControlStates)ControlStates.Focused;
1868 stateChangedHandler(this, args);
1873 private void UpdateComponentByIndicatorTypeChanged()
1875 IndicatorType type = CurrentIndicatorType();
1876 if (type == IndicatorType.None)
1878 if (lowIndicatorImage != null)
1880 lowIndicatorImage.Hide();
1882 if (highIndicatorImage != null)
1884 highIndicatorImage.Hide();
1886 if (lowIndicatorText != null)
1888 lowIndicatorText.Hide();
1890 if (highIndicatorText != null)
1892 highIndicatorText.Hide();
1895 else if (type == IndicatorType.Image)
1897 if (lowIndicatorImage != null)
1899 lowIndicatorImage.Show();
1901 if (highIndicatorImage != null)
1903 highIndicatorImage.Show();
1905 if (lowIndicatorText != null)
1907 lowIndicatorText.Hide();
1909 if (highIndicatorText != null)
1911 highIndicatorText.Hide();
1914 else if (type == IndicatorType.Text)
1916 if (lowIndicatorText != null)
1918 lowIndicatorText.Show();
1920 if (highIndicatorText != null)
1922 highIndicatorText.Show();
1924 if (lowIndicatorImage != null)
1926 lowIndicatorImage.Hide();
1928 if (highIndicatorImage != null)
1930 highIndicatorImage.Hide();
1936 /// Value Changed event data.
1938 /// <since_tizen> 6 </since_tizen>
1939 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
1940 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1941 public class ValueChangedArgs : EventArgs
1946 /// <since_tizen> 6 </since_tizen>
1947 /// It will be removed in API10
1948 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1949 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
1950 public float CurrentValue;
1954 /// Value Changed event data.
1956 /// <since_tizen> 6 </since_tizen>
1957 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
1958 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1959 public class SlidingFinishedArgs : EventArgs
1964 /// <since_tizen> 6 </since_tizen>
1965 /// It will be removed in API10
1966 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1967 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
1968 public float CurrentValue;
1972 /// State Changed event data.
1974 /// <since_tizen> 6 </since_tizen>
1975 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
1976 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1977 public class StateChangedArgs : EventArgs
1982 /// <since_tizen> 6 </since_tizen>
1983 /// It will be removed in API10
1984 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
1985 [Obsolete("Deprecated in API8; Will be removed in API10")]
1986 public ControlStates CurrentState;