2 * Copyright(c) 2022 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>
206 /// The constructor of the Slider class with specific style.
208 /// <param name="style">The string to initialize the Slider</param>
209 /// <since_tizen> 8 </since_tizen>
210 public Slider(string style) : base(style)
217 /// The constructor of the Slider class with specific style.
219 /// <param name="sliderStyle">The style object to initialize the Slider</param>
220 /// <since_tizen> 8 </since_tizen>
221 public Slider(SliderStyle sliderStyle) : base(sliderStyle)
228 /// The value changed event handler.
230 /// <since_tizen> 6 </since_tizen>
231 [Obsolete("Deprecated in API8; Will be removed in API10. Please use ValueChanged event instead.")]
232 public event EventHandler<ValueChangedArgs> ValueChangedEvent
236 valueChangedHandler += value;
240 valueChangedHandler -= value;
245 /// The sliding finished event handler.
247 /// <since_tizen> 6 </since_tizen>
248 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SlidingFinished event instead.")]
249 public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
253 slidingFinishedHandler += value;
257 slidingFinishedHandler -= value;
262 /// The value changed event handler.
264 /// <since_tizen> 8 </since_tizen>
265 public event EventHandler<SliderValueChangedEventArgs> ValueChanged
269 sliderValueChangedHandler += value;
273 sliderValueChangedHandler -= value;
278 /// The sliding started event handler.
280 /// <since_tizen> 8 </since_tizen>
281 public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
285 sliderSlidingStartedHandler += value;
289 sliderSlidingStartedHandler -= value;
294 /// The sliding finished event handler.
296 /// <since_tizen> 8 </since_tizen>
297 public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
301 sliderSlidingFinishedHandler += value;
305 sliderSlidingFinishedHandler -= value;
310 /// The state changed event handler.
312 /// <since_tizen> 6 </since_tizen>
313 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
314 public event EventHandler<StateChangedArgs> StateChangedEvent
318 stateChangedHandler += value;
322 stateChangedHandler -= value;
327 /// The direction type of slider.
329 /// <since_tizen> 6 </since_tizen>
330 public enum DirectionType
333 /// The Horizontal type.
335 /// <since_tizen> 6 </since_tizen>
339 /// The Vertical type.
341 /// <since_tizen> 6 </since_tizen>
346 /// The indicator type of slider.
348 /// <since_tizen> 6 </since_tizen>
349 public enum IndicatorType
351 /// <summary> Only contains slider bar.</summary>
352 /// <since_tizen> 6 </since_tizen>
355 /// <summary> Contains slider bar, IndicatorImage.</summary>
356 /// <since_tizen> 6 </since_tizen>
359 /// <summary> Contains slider bar, IndicatorText.</summary>
360 /// <since_tizen> 6 </since_tizen>
365 /// Return currently applied style.
368 /// Modifying contents in style may cause unexpected behaviour.
370 /// <since_tizen> 8 </since_tizen>
371 public SliderStyle Style => (SliderStyle)(ViewStyle as SliderStyle)?.Clone();
374 /// Gets or sets the direction type of slider.
376 /// <since_tizen> 6 </since_tizen>
377 public DirectionType Direction
381 return (DirectionType)GetValue(DirectionProperty);
385 SetValue(DirectionProperty, value);
386 NotifyPropertyChanged();
389 private DirectionType InternalDirection
397 if (direction == value)
402 RelayoutBaseComponent(false);
404 UpdateBgTrackPosition();
405 UpdateWarningTrackSize();
411 /// Gets or sets the indicator type, arrow or sign.
413 /// <since_tizen> 6 </since_tizen>
414 public IndicatorType Indicator
418 return (IndicatorType)GetValue(IndicatorProperty);
422 SetValue(IndicatorProperty, value);
427 /// Gets or sets the minimum value of slider.
429 /// <since_tizen> 6 </since_tizen>
430 public float MinValue
434 return (float)GetValue(MinValueProperty);
438 SetValue(MinValueProperty, value);
439 NotifyPropertyChanged();
442 private float InternalMinValue
456 /// Gets or sets the maximum value of slider.
458 /// <since_tizen> 6 </since_tizen>
459 public float MaxValue
463 return (float)GetValue(MaxValueProperty);
467 SetValue(MaxValueProperty, value);
468 NotifyPropertyChanged();
471 private float InternalMaxValue
485 /// Gets or sets the current value of slider.
487 /// <since_tizen> 6 </since_tizen>
488 public float CurrentValue
492 return (float)GetValue(CurrentValueProperty);
496 SetValue(CurrentValueProperty, value);
501 /// Gets or sets the size of the thumb image object.
503 /// <since_tizen> 6 </since_tizen>
504 public Size ThumbSize
508 return GetValue(ThumbSizeProperty) as Size;
512 SetValue(ThumbSizeProperty, value);
513 NotifyPropertyChanged();
516 private Size InternalThumbSize
520 return thumbImage?.Size;
524 if (null != thumbImage)
526 thumbImage.Size = value;
533 /// Gets or sets the resource url of the thumb image object.
535 /// Please use ThumbImageUrl property.
537 /// <since_tizen> 6 </since_tizen>
538 public string ThumbImageURL
542 return GetValue(ThumbImageURLProperty) as string;
546 SetValue(ThumbImageURLProperty, value);
547 NotifyPropertyChanged();
550 private string InternalThumbImageURL
554 return thumbImage?.ResourceUrl;
558 if (null != thumbImage)
560 thumbImage.ResourceUrl = value;
561 thumbImageUrl = value;
567 /// Gets or sets the resource url selector of the thumb image object.
568 /// Getter returns copied selector value if exist, null otherwise.
570 /// Please use ThumbImageUrl property.
572 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
573 /// <since_tizen> 6 </since_tizen>
574 public StringSelector ThumbImageURLSelector
578 return GetValue(ThumbImageURLSelectorProperty) as StringSelector;
582 SetValue(ThumbImageURLSelectorProperty, value);
583 NotifyPropertyChanged();
586 private StringSelector InternalThumbImageURLSelector
588 get => thumbImage?.ResourceUrlSelector == null ? null : new StringSelector(thumbImage.ResourceUrlSelector);
591 if (value == null || thumbImage == null)
593 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
597 thumbImage.ResourceUrlSelector = value;
603 /// Gets or sets the Url of the thumb image.
605 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
606 /// <since_tizen> 9 </since_tizen>
607 public Selector<string> ThumbImageUrl
611 return GetValue(ThumbImageUrlProperty) as Selector<string>;
615 SetValue(ThumbImageUrlProperty, value);
616 NotifyPropertyChanged();
619 private Selector<string> InternalThumbImageUrl
623 if (thumbImage == null)
629 return thumbImage.ResourceUrlSelector;
634 if (value == null || thumbImage == null)
636 throw new NullReferenceException("Slider.ThumbImageUrl is null");
640 thumbImage.ResourceUrlSelector = value;
646 /// Gets or sets the color of the thumb image object.
648 /// <since_tizen> 8 </since_tizen>
649 public Color ThumbColor
653 return GetValue(ThumbColorProperty) as Color;
657 SetValue(ThumbColorProperty, value);
658 NotifyPropertyChanged();
661 private Color InternalThumbColor
665 return thumbImage?.Color;
669 if (null != thumbImage)
671 thumbImage.BackgroundColor = value;
678 /// Gets or sets the color of the background track image object.
680 /// <since_tizen> 6 </since_tizen>
681 public Color BgTrackColor
685 return GetValue(BgTrackColorProperty) as Color;
689 SetValue(BgTrackColorProperty, value);
690 NotifyPropertyChanged();
693 private Color InternalBgTrackColor
697 return bgTrackImage?.BackgroundColor;
701 if (null != bgTrackImage)
703 bgTrackImage.BackgroundColor = value;
709 /// Gets or sets the color of the slided track image object.
711 /// <since_tizen> 6 </since_tizen>
712 public Color SlidedTrackColor
716 return GetValue(SlidedTrackColorProperty) as Color;
720 SetValue(SlidedTrackColorProperty, value);
721 NotifyPropertyChanged();
724 private Color InternalSlidedTrackColor
728 return slidedTrackImage?.BackgroundColor;
732 if (null != slidedTrackImage)
734 slidedTrackImage.BackgroundColor = value;
740 /// Gets or sets the thickness value of the track.
742 /// <since_tizen> 6 </since_tizen>
743 public uint TrackThickness
747 return (uint)GetValue(TrackThicknessProperty);
751 SetValue(TrackThicknessProperty, value);
756 /// Gets or sets the warning start value between minimum value and maximum value of slider.
758 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
759 [EditorBrowsable(EditorBrowsableState.Never)]
760 public float WarningStartValue
764 return (float)GetValue(WarningStartValueProperty);
768 SetValue(WarningStartValueProperty, value);
769 NotifyPropertyChanged();
772 private float InternalWarningStartValue
776 return warningStartValue;
780 warningStartValue = value;
786 /// Gets or sets the color of the warning track image object.
788 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
789 [EditorBrowsable(EditorBrowsableState.Never)]
790 public Color WarningTrackColor
794 return GetValue(WarningTrackColorProperty) as Color;
798 SetValue(WarningTrackColorProperty, value);
799 NotifyPropertyChanged();
802 private Color InternalWarningTrackColor
806 return warningTrackImage?.BackgroundColor;
810 if (null != warningTrackImage)
812 warningTrackImage.BackgroundColor = value;
818 /// Gets or sets the color of the warning slided track image object.
820 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
821 [EditorBrowsable(EditorBrowsableState.Never)]
822 public Color WarningSlidedTrackColor
826 return GetValue(WarningSlidedTrackColorProperty) as Color;
830 SetValue(WarningSlidedTrackColorProperty, value);
831 NotifyPropertyChanged();
834 private Color InternalWarningSlidedTrackColor
838 return warningSlidedTrackImage?.BackgroundColor;
842 if (null != warningSlidedTrackImage)
844 warningSlidedTrackImage.BackgroundColor = value;
850 /// Gets or sets the Url of the warning thumb image.
852 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
853 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
854 [EditorBrowsable(EditorBrowsableState.Never)]
855 public Selector<string> WarningThumbImageUrl
859 return GetValue(WarningThumbImageUrlProperty) as Selector<string>;
863 SetValue(WarningThumbImageUrlProperty, value);
864 NotifyPropertyChanged();
867 private Selector<string> InternalWarningThumbImageUrl
871 return warningThumbImageUrlSelector;
875 if (value == null || thumbImage == null)
877 throw new NullReferenceException("Slider.WarningThumbImageUrl is null");
881 warningThumbImageUrlSelector = value;
887 /// Gets or sets the color of the warning thumb image object.
889 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
890 [EditorBrowsable(EditorBrowsableState.Never)]
891 public Color WarningThumbColor
895 return GetValue(WarningThumbColorProperty) as Color;
899 SetValue(WarningThumbColorProperty, value);
900 NotifyPropertyChanged();
903 private Color InternalWarningThumbColor
907 return warningThumbColor;
911 warningThumbColor = value;
916 /// Gets or sets the resource url of the low indicator image object.
918 /// <since_tizen> 6 </since_tizen>
919 public string LowIndicatorImageURL
923 return GetValue(LowIndicatorImageURLProperty) as string;
927 SetValue(LowIndicatorImageURLProperty, value);
928 NotifyPropertyChanged();
931 private string InternalLowIndicatorImageURL
935 return lowIndicatorImage?.ResourceUrl;
939 if (null == lowIndicatorImage) lowIndicatorImage = new ImageView();
940 lowIndicatorImage.ResourceUrl = value;
945 /// Gets or sets the resource url of the high indicator image object.
947 /// <since_tizen> 6 </since_tizen>
948 public string HighIndicatorImageURL
952 return GetValue(HighIndicatorImageURLProperty) as string;
956 SetValue(HighIndicatorImageURLProperty, value);
957 NotifyPropertyChanged();
960 private string InternalHighIndicatorImageURL
964 return highIndicatorImage?.ResourceUrl;
968 if (null == highIndicatorImage) highIndicatorImage = new ImageView();
969 highIndicatorImage.ResourceUrl = value;
974 /// Gets or sets the text content of the low indicator text object.
976 /// <since_tizen> 6 </since_tizen>
977 public string LowIndicatorTextContent
981 return GetValue(LowIndicatorTextContentProperty) as string;
985 SetValue(LowIndicatorTextContentProperty, value);
986 NotifyPropertyChanged();
989 private string InternalLowIndicatorTextContent
993 return lowIndicatorText?.Text;
997 if (null != lowIndicatorText)
999 lowIndicatorText.Text = value;
1005 /// Gets or sets the text content of the high indicator text object.
1007 /// <since_tizen> 6 </since_tizen>
1008 public string HighIndicatorTextContent
1012 return GetValue(HighIndicatorTextContentProperty) as string;
1016 SetValue(HighIndicatorTextContentProperty, value);
1017 NotifyPropertyChanged();
1020 private string InternalHighIndicatorTextContent
1024 return highIndicatorText?.Text;
1028 if (null != highIndicatorText)
1030 highIndicatorText.Text = value;
1036 /// Gets or sets the size of the low indicator object(image or text).
1038 /// <since_tizen> 6 </since_tizen>
1039 public Size LowIndicatorSize
1043 return GetValue(LowIndicatorSizeProperty) as Size;
1047 SetValue(LowIndicatorSizeProperty, value);
1048 NotifyPropertyChanged();
1051 private Size InternalLowIndicatorSize
1055 return lowIndicatorSize;
1059 lowIndicatorSize = value;
1060 UpdateLowIndicatorSize();
1061 UpdateBgTrackSize();
1062 UpdateBgTrackPosition();
1068 /// Gets or sets the size of the high indicator object(image or text).
1070 /// <since_tizen> 6 </since_tizen>
1071 public Size HighIndicatorSize
1075 return GetValue(HighIndicatorSizeProperty) as Size;
1079 SetValue(HighIndicatorSizeProperty, value);
1080 NotifyPropertyChanged();
1083 private Size InternalHighIndicatorSize
1087 return highIndicatorText?.Size;
1091 if (null != highIndicatorText)
1093 highIndicatorText.Size = value;
1099 /// Gets or sets the value of the space between track and indicator.
1101 /// <since_tizen> 6 </since_tizen>
1102 public uint SpaceBetweenTrackAndIndicator
1106 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
1110 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
1115 /// Flag to decide whether the value indicator is shown
1117 /// <since_tizen> 9 </since_tizen>
1118 public bool IsValueShown
1122 return (bool)GetValue(IsValueShownProperty);
1126 SetValue(IsValueShownProperty, value);
1131 /// Gets or sets the text of value indicator.
1133 /// <since_tizen> 9 </since_tizen>
1134 public string ValueIndicatorText
1138 return (string)GetValue(ValueIndicatorTextProperty);
1142 SetValue(ValueIndicatorTextProperty, value);
1147 /// Gets or sets the size of the value indicator image object.
1149 /// <since_tizen> 9 </since_tizen>
1150 public Size ValueIndicatorSize
1154 return GetValue(ValueIndicatorSizeProperty) as Size;
1158 SetValue(ValueIndicatorSizeProperty, value);
1159 NotifyPropertyChanged();
1162 private Size InternalValueIndicatorSize
1166 return valueIndicatorImage?.Size;
1170 if (null != valueIndicatorImage)
1172 valueIndicatorImage.Size = value;
1178 /// Gets or sets the resource url of the value indicator image object.
1180 /// <since_tizen> 9 </since_tizen>
1181 public string ValueIndicatorUrl
1185 return GetValue(ValueIndicatorUrlProperty) as string;
1189 SetValue(ValueIndicatorUrlProperty, value);
1190 NotifyPropertyChanged();
1193 private string InternalValueIndicatorUrl
1197 return valueIndicatorImage?.ResourceUrl;
1201 if (null != valueIndicatorImage)
1203 valueIndicatorImage.ResourceUrl = value;
1209 /// Flag to decide whether the thumb snaps to the nearest discrete value when the user drags the thumb or taps.
1211 /// The default value is false.
1213 /// <since_tizen> 9 </since_tizen>
1214 public bool IsDiscrete
1218 return (bool)GetValue(IsDiscreteProperty);
1222 SetValue(IsDiscreteProperty, value);
1223 NotifyPropertyChanged();
1226 private bool InternalIsDiscrete { get; set; } = false;
1229 /// Gets or sets the discrete value of slider.
1232 /// The discrete value is evenly spaced between MinValue and MaxValue.
1233 /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
1234 /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
1235 /// The default is 0.
1237 /// <since_tizen> 9 </since_tizen>
1238 public float DiscreteValue
1242 return (float)GetValue(DiscreteValueProperty);
1246 SetValue(DiscreteValueProperty, value);
1247 NotifyPropertyChanged();
1250 private float InternalDiscreteValue
1254 return discreteValue;
1258 discreteValue = value;
1263 private Extents spaceBetweenTrackAndIndicator
1267 if (null == spaceTrackIndicator)
1269 spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
1271 Extents extents = new Extents(start, end, top, bottom);
1272 spaceTrackIndicator.CopyFrom(extents);
1276 return spaceTrackIndicator;
1280 private IndicatorType privateIndicatorType
1284 return indicatorType;
1288 if (indicatorType == value)
1292 indicatorType = value;
1293 RelayoutBaseComponent(false);
1294 UpdateBgTrackSize();
1295 UpdateBgTrackPosition();
1300 private uint privateTrackThickness
1304 return trackThickness ?? 0;
1308 trackThickness = value;
1309 if (bgTrackImage != null)
1311 if (direction == DirectionType.Horizontal)
1313 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1315 else if (direction == DirectionType.Vertical)
1317 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1320 if (slidedTrackImage != null)
1322 if (direction == DirectionType.Horizontal)
1324 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1326 else if (direction == DirectionType.Vertical)
1328 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1331 if (warningTrackImage != null)
1333 if (direction == DirectionType.Horizontal)
1335 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1337 else if (direction == DirectionType.Vertical)
1339 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1342 if (warningSlidedTrackImage != null)
1344 if (direction == DirectionType.Horizontal)
1346 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1348 else if (direction == DirectionType.Vertical)
1350 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1356 private uint privateSpaceBetweenTrackAndIndicator
1360 return privateTrackPadding.Start;
1364 ushort val = (ushort)value;
1365 privateTrackPadding = new Extents(val, val, val, val);
1369 private Extents privateTrackPadding
1373 return spaceBetweenTrackAndIndicator;
1377 spaceBetweenTrackAndIndicator.CopyFrom(value);
1378 UpdateComponentByIndicatorTypeChanged();
1379 UpdateBgTrackSize();
1380 UpdateBgTrackPosition();
1386 /// Focus gained callback.
1388 /// <since_tizen> 8 </since_tizen>
1389 public override void OnFocusGained()
1391 //State = ControlStates.Focused;
1392 UpdateState(true, isPressed);
1393 base.OnFocusGained();
1397 /// Focus Lost callback.
1399 /// <since_tizen> 8 </since_tizen>
1400 public override void OnFocusLost()
1402 //State = ControlStates.Normal;
1403 UpdateState(false, isPressed);
1407 private bool editMode = false;
1408 private View recoverIndicator;
1409 private View editModeIndicator;
1412 [EditorBrowsable(EditorBrowsableState.Never)]
1413 public override bool OnKeyboardEnter()
1421 //set editMode false (toggle the mode)
1423 FocusManager.Instance.FocusIndicator = recoverIndicator;
1427 //set editMode true (toggle the mode)
1429 if (editModeIndicator == null)
1431 editModeIndicator = new View()
1433 PositionUsesPivotPoint = true,
1434 PivotPoint = new Position(0, 0, 0),
1435 WidthResizePolicy = ResizePolicyType.FillToParent,
1436 HeightResizePolicy = ResizePolicyType.FillToParent,
1437 BorderlineColor = Color.Red,
1438 BorderlineWidth = 6.0f,
1439 BorderlineOffset = -1f,
1440 BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.4f),
1443 recoverIndicator = FocusManager.Instance.FocusIndicator;
1444 FocusManager.Instance.FocusIndicator = editModeIndicator;
1450 [EditorBrowsable(EditorBrowsableState.Never)]
1451 public override bool OnKey(Key key)
1453 if (!IsEnabled || null == key)
1458 if (key.State == Key.StateType.Down)
1460 if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Left") ||
1461 (direction == DirectionType.Vertical && key.KeyPressedName == "Down"))
1465 if (MinValue < CurrentValue)
1470 float value = CurrentValue - discreteValue;
1471 CurrentValue = value < MinValue ? MinValue : value;
1478 return true; // Consumed
1481 else if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Right") ||
1482 (direction == DirectionType.Vertical && key.KeyPressedName == "Up"))
1486 if (MaxValue > CurrentValue)
1491 float value = CurrentValue + discreteValue;
1492 CurrentValue = value > MaxValue ? MaxValue : value;
1499 return true; // Consumed
1503 else if (key.State == Key.StateType.Up)
1508 if (key.KeyPressedName == "Up" || key.KeyPressedName == "Right" || key.KeyPressedName == "Down" || key.KeyPressedName == "Left")
1519 /// Apply style to scrollbar.
1521 /// <param name="viewStyle">The style to apply.</param>
1522 /// <since_tizen> 8 </since_tizen>
1523 public override void ApplyStyle(ViewStyle viewStyle)
1525 base.ApplyStyle(viewStyle);
1527 SliderStyle sliderStyle = viewStyle as SliderStyle;
1529 if (null != sliderStyle?.Progress)
1531 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1534 if (null != sliderStyle?.LowIndicator)
1536 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1539 if (null != sliderStyle?.HighIndicator)
1541 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1544 if (null != sliderStyle?.Track)
1546 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1549 if (null != sliderStyle?.Thumb)
1551 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1554 if (null != sliderStyle?.ValueIndicatorText)
1556 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1559 if (null != sliderStyle?.ValueIndicatorImage)
1561 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1564 if (null != sliderStyle?.WarningTrack)
1566 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1569 if (null != sliderStyle?.WarningProgress)
1571 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1574 EnableControlStatePropagation = true;
1578 /// Prevents from showing child widgets in AT-SPI tree.
1580 [EditorBrowsable(EditorBrowsableState.Never)]
1581 protected override bool AccessibilityShouldReportZeroChildren()
1587 /// Gets minimum value for Accessibility.
1589 [EditorBrowsable(EditorBrowsableState.Never)]
1590 protected override double AccessibilityGetMinimum()
1592 return (double)MinValue;
1596 /// Gets the current value for Accessibility.
1598 [EditorBrowsable(EditorBrowsableState.Never)]
1599 protected override double AccessibilityGetCurrent()
1601 return (double)CurrentValue;
1605 /// Gets maximum value for Accessibility.
1607 [EditorBrowsable(EditorBrowsableState.Never)]
1608 protected override double AccessibilityGetMaximum()
1610 return (double)MaxValue;
1614 /// Sets the current value using Accessibility.
1616 [EditorBrowsable(EditorBrowsableState.Never)]
1617 protected override bool AccessibilitySetCurrent(double value)
1619 var current = (float)value;
1621 if (current >= MinValue && current <= MaxValue)
1623 CurrentValue = current;
1624 if (sliderValueChangedHandler != null)
1626 sliderValueChangedHandler(this, new SliderValueChangedEventArgs { CurrentValue = current });
1635 /// Gets minimum increment for Accessibility.
1637 [EditorBrowsable(EditorBrowsableState.Never)]
1638 protected override double AccessibilityGetMinimumIncrement()
1641 return (MaxValue - MinValue) / 20.0;
1645 /// Initialize AT-SPI object.
1647 [EditorBrowsable(EditorBrowsableState.Never)]
1648 public override void OnInitialize()
1650 base.OnInitialize();
1651 SetAccessibilityConstructor(Role.Slider, AccessibilityInterface.Value);
1655 /// Get Slider style.
1657 /// <returns>The default slider style.</returns>
1658 /// <since_tizen> 8 </since_tizen>
1659 protected override ViewStyle CreateViewStyle()
1661 return new SliderStyle();
1667 /// <param name="type">Dispose type.</param>
1668 /// <since_tizen> 6 </since_tizen>
1669 protected override void Dispose(DisposeTypes type)
1676 if (type == DisposeTypes.Explicit)
1678 if (null != panGestureDetector)
1680 panGestureDetector.Detach(this);
1681 panGestureDetector.Detected -= OnPanGestureDetected;
1682 panGestureDetector.Dispose();
1683 panGestureDetector = null;
1686 if (null != thumbImage)
1688 thumbImage.TouchEvent -= OnTouchEventForThumb;
1689 Utility.Dispose(thumbImage);
1691 Utility.Dispose(warningSlidedTrackImage);
1692 Utility.Dispose(warningTrackImage);
1693 Utility.Dispose(slidedTrackImage);
1694 Utility.Dispose(bgTrackImage);
1695 Utility.Dispose(lowIndicatorImage);
1696 Utility.Dispose(highIndicatorImage);
1697 Utility.Dispose(lowIndicatorText);
1698 Utility.Dispose(highIndicatorText);
1699 Utility.Dispose(valueIndicatorImage);
1700 Utility.Dispose(valueIndicatorText);
1702 this.TouchEvent -= OnTouchEventForTrack;
1704 recoverIndicator = null;
1705 editModeIndicator.Dispose();
1706 editModeIndicator = null;
1713 /// Update Slider by style.
1715 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1716 [EditorBrowsable(EditorBrowsableState.Never)]
1717 protected override void OnUpdate()
1719 RelayoutBaseComponent();
1721 UpdateComponentByIndicatorTypeChanged();
1722 UpdateBgTrackSize();
1723 UpdateBgTrackPosition();
1724 UpdateWarningTrackSize();
1725 UpdateLowIndicatorSize();
1730 [EditorBrowsable(EditorBrowsableState.Never)]
1731 protected override void OnEnabled(bool enabled)
1733 base.OnEnabled(enabled);
1737 private void CalculateCurrentValueByGesture(float offset)
1739 currentSlidedOffset += offset;
1741 if (currentSlidedOffset <= 0)
1743 this.CurrentValue = minValue;
1745 else if (currentSlidedOffset >= BgTrackLength())
1747 this.CurrentValue = maxValue;
1751 int bgTrackLength = BgTrackLength();
1752 if (bgTrackLength != 0)
1754 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1760 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1763 if (valueChangedHandler != null)
1765 ValueChangedArgs args = new ValueChangedArgs();
1766 args.CurrentValue = this.CurrentValue;
1767 valueChangedHandler(this, args);
1770 if (sliderValueChangedHandler != null)
1772 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1773 args.CurrentValue = this.CurrentValue;
1774 sliderValueChangedHandler(this, args);
1778 private bool OnTouchEventForTrack(object source, TouchEventArgs e)
1785 PointStateType state = e.Touch.GetState(0);
1786 if (state == PointStateType.Down)
1790 valueIndicatorImage.Show();
1793 Vector2 pos = e.Touch.GetLocalPosition(0);
1794 CalculateCurrentValueByTouch(pos);
1796 if (null != slidingFinishedHandler)
1798 SlidingFinishedArgs args = new SlidingFinishedArgs();
1799 args.CurrentValue = curValue;
1800 slidingFinishedHandler(this, args);
1803 if (null != sliderSlidingFinishedHandler)
1805 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
1806 args.CurrentValue = curValue;
1807 sliderSlidingFinishedHandler(this, args);
1810 else if (state == PointStateType.Up)
1814 valueIndicatorImage.Hide();
1820 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1822 PointStateType state = e.Touch.GetState(0);
1823 if (state == PointStateType.Down)
1825 UpdateState(isFocused, true);
1827 else if (state == PointStateType.Up)
1829 UpdateState(isFocused, false);
1834 private void CalculateCurrentValueByTouch(Vector2 pos)
1836 int bgTrackLength = BgTrackLength();
1837 if (direction == DirectionType.Horizontal)
1839 currentSlidedOffset = pos.X;
1841 else if (direction == DirectionType.Vertical)
1843 currentSlidedOffset = bgTrackLength - pos.Y;
1846 if (bgTrackLength != 0)
1848 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1852 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1855 if (null != valueChangedHandler)
1857 ValueChangedArgs args = new ValueChangedArgs();
1858 args.CurrentValue = this.CurrentValue;
1859 valueChangedHandler(this, args);
1862 if (null != sliderValueChangedHandler)
1864 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1865 args.CurrentValue = this.CurrentValue;
1866 sliderValueChangedHandler(this, args);
1871 private float CalculateDiscreteValue(float value)
1873 return ((float)Math.Round((value / discreteValue)) * discreteValue);
1876 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1878 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1882 if (thumbImage == null || Style == null)
1886 isFocused = isFocusedNew;
1887 isPressed = isPressedNew;
1889 if (!IsEnabled) // Disabled
1891 ControlState = ControlState.Disabled;
1893 if (stateChangedHandler != null)
1895 StateChangedArgs args = new StateChangedArgs();
1896 args.CurrentState = (ControlStates)ControlStates.Disabled;
1897 stateChangedHandler(this, args);
1900 else if (!isFocused && !isPressed)
1902 ControlState = ControlState.Normal;
1904 if (stateChangedHandler != null)
1906 StateChangedArgs args = new StateChangedArgs();
1907 args.CurrentState = (ControlStates)ControlStates.Normal;
1908 stateChangedHandler(this, args);
1913 ControlState = ControlState.Pressed;
1915 if (stateChangedHandler != null)
1917 StateChangedArgs args = new StateChangedArgs();
1918 args.CurrentState = (ControlStates)ControlStates.Pressed;
1919 stateChangedHandler(this, args);
1922 else if (!isPressed && isFocused)
1924 ControlState = ControlState.Focused;
1926 if (stateChangedHandler != null)
1928 StateChangedArgs args = new StateChangedArgs();
1929 args.CurrentState = (ControlStates)ControlStates.Focused;
1930 stateChangedHandler(this, args);
1935 private void UpdateComponentByIndicatorTypeChanged()
1937 IndicatorType type = CurrentIndicatorType();
1938 if (type == IndicatorType.None)
1940 if (lowIndicatorImage != null)
1942 lowIndicatorImage.Hide();
1944 if (highIndicatorImage != null)
1946 highIndicatorImage.Hide();
1948 if (lowIndicatorText != null)
1950 lowIndicatorText.Hide();
1952 if (highIndicatorText != null)
1954 highIndicatorText.Hide();
1957 else if (type == IndicatorType.Image)
1959 if (lowIndicatorImage != null)
1961 lowIndicatorImage.Show();
1963 if (highIndicatorImage != null)
1965 highIndicatorImage.Show();
1967 if (lowIndicatorText != null)
1969 lowIndicatorText.Hide();
1971 if (highIndicatorText != null)
1973 highIndicatorText.Hide();
1976 else if (type == IndicatorType.Text)
1978 if (lowIndicatorText != null)
1980 lowIndicatorText.Show();
1982 if (highIndicatorText != null)
1984 highIndicatorText.Show();
1986 if (lowIndicatorImage != null)
1988 lowIndicatorImage.Hide();
1990 if (highIndicatorImage != null)
1992 highIndicatorImage.Hide();
1998 /// Value Changed event data.
2000 /// <since_tizen> 6 </since_tizen>
2001 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
2002 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
2003 public class ValueChangedArgs : EventArgs
2008 /// <since_tizen> 6 </since_tizen>
2009 /// It will be removed in API10
2010 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
2011 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
2012 public float CurrentValue;
2016 /// Value Changed event data.
2018 /// <since_tizen> 6 </since_tizen>
2019 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
2020 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
2021 public class SlidingFinishedArgs : EventArgs
2026 /// <since_tizen> 6 </since_tizen>
2027 /// It will be removed in API10
2028 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
2029 [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
2030 public float CurrentValue;
2034 /// State Changed event data.
2036 /// <since_tizen> 6 </since_tizen>
2037 [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
2038 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
2039 public class StateChangedArgs : EventArgs
2044 /// <since_tizen> 6 </since_tizen>
2045 /// It will be removed in API10
2046 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
2047 [Obsolete("Deprecated in API8; Will be removed in API10")]
2048 public ControlStates CurrentState;