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.
19 using System.ComponentModel;
20 using Tizen.NUI.Accessibility;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.Binding;
24 namespace Tizen.NUI.Components
27 /// Slider value changed event data.
29 /// <since_tizen> 8 </since_tizen>
30 public class SliderValueChangedEventArgs : EventArgs
33 /// Current Slider value
35 /// <since_tizen> 8 </since_tizen>
36 public float CurrentValue { get; set; }
40 /// Slider sliding started event data.
42 /// <since_tizen> 8 </since_tizen>
43 public class SliderSlidingStartedEventArgs : EventArgs
46 /// Current Slider value
48 /// <since_tizen> 8 </since_tizen>
49 public float CurrentValue { get; set; }
53 /// Slider sliding finished event data.
55 /// <since_tizen> 8 </since_tizen>
56 public class SliderSlidingFinishedEventArgs : EventArgs
59 /// Current Slider value
61 /// <since_tizen> 8 </since_tizen>
62 public float CurrentValue { get; set; }
66 /// A slider lets users select a value from a continuous or discrete range of values by moving the slider thumb.
68 /// <since_tizen> 6 </since_tizen>
69 public partial class Slider : Control, IAtspiValue
72 /// SpaceBetweenTrackAndIndicatorProperty
74 [EditorBrowsable(EditorBrowsableState.Never)]
75 public static readonly BindableProperty IndicatorProperty = BindableProperty.Create(nameof(Indicator), typeof(IndicatorType), typeof(Slider), IndicatorType.None, propertyChanged: (bindable, oldValue, newValue) =>
77 var instance = (Slider)bindable;
80 instance.privateIndicatorType = (IndicatorType)newValue;
83 defaultValueCreator: (bindable) =>
85 var instance = (Slider)bindable;
86 return instance.privateIndicatorType;
90 /// SpaceBetweenTrackAndIndicatorProperty
92 [EditorBrowsable(EditorBrowsableState.Never)]
93 public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create(nameof(SpaceBetweenTrackAndIndicator), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
95 var instance = (Slider)bindable;
98 instance.privateSpaceBetweenTrackAndIndicator = (uint)newValue;
101 defaultValueCreator: (bindable) =>
103 var instance = (Slider)bindable;
104 return instance.privateSpaceBetweenTrackAndIndicator;
108 /// TrackThicknessProperty
110 [EditorBrowsable(EditorBrowsableState.Never)]
111 public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
113 var instance = (Slider)bindable;
114 if (newValue != null)
116 instance.privateTrackThickness = (uint)newValue;
119 defaultValueCreator: (bindable) =>
121 var instance = (Slider)bindable;
122 return instance.privateTrackThickness;
126 /// IsValueShownProperty
128 [EditorBrowsable(EditorBrowsableState.Never)]
129 public static readonly BindableProperty IsValueShownProperty = BindableProperty.Create(nameof(IsValueShown), typeof(bool), typeof(Slider), true, propertyChanged: (bindable, oldValue, newValue) =>
131 var instance = (Slider)bindable;
132 if (newValue != null)
134 bool newValueShown = (bool)newValue;
135 if (instance.isValueShown != newValueShown)
137 instance.isValueShown = newValueShown;
141 defaultValueCreator: (bindable) =>
143 var instance = (Slider)bindable;
144 return instance.isValueShown;
148 /// ValueIndicatorTextProperty
150 [EditorBrowsable(EditorBrowsableState.Never)]
151 public static readonly BindableProperty ValueIndicatorTextProperty = BindableProperty.Create(nameof(ValueIndicatorText), typeof(string), typeof(Slider), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
153 var instance = (Slider)bindable;
154 if (newValue != null)
156 string newText = (string)newValue;
157 instance.valueIndicatorText.Text = newText;
160 defaultValueCreator: (bindable) =>
162 var instance = (Slider)bindable;
163 return instance.valueIndicatorText.Text;
167 /// Bindable property of CurrentValue
169 /// Hidden API, used for NUI XAML data binding
172 [EditorBrowsable(EditorBrowsableState.Never)]
173 public static readonly BindableProperty CurrentValueProperty = BindableProperty.Create(nameof(CurrentValue), typeof(float), typeof(Slider), 0.0f, BindingMode.TwoWay,
174 propertyChanged: (bindable, oldValue, newValue) =>
176 var instance = (Slider)bindable;
178 if (newValue != null)
180 float value = (float)newValue;
181 if (value < instance.minValue)
183 instance.curValue = instance.minValue;
185 else if (value > instance.maxValue)
187 instance.curValue = instance.maxValue;
191 instance.curValue = value;
194 instance.sliderValueChangedHandler?.Invoke(instance, new SliderValueChangedEventArgs
196 CurrentValue = instance.curValue
198 if (Accessibility.Accessibility.IsEnabled && instance.IsHighlighted)
200 instance.EmitAccessibilityEvent(AccessibilityPropertyChangeEvent.Value);
202 instance.UpdateValue();
205 defaultValueCreator: (bindable) =>
207 var instance = (Slider)bindable;
208 return instance.curValue;
215 /// The constructor of the Slider class.
217 /// <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)
236 /// The constructor of the Slider class with specific style.
238 /// <param name="sliderStyle">The style object to initialize the Slider</param>
239 /// <since_tizen> 8 </since_tizen>
240 public Slider(SliderStyle sliderStyle) : base(sliderStyle)
247 /// The value changed event handler.
249 /// <since_tizen> 8 </since_tizen>
250 public event EventHandler<SliderValueChangedEventArgs> ValueChanged
254 sliderValueChangedHandler += value;
258 sliderValueChangedHandler -= value;
263 /// The sliding started event handler.
265 /// <since_tizen> 8 </since_tizen>
266 public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
270 sliderSlidingStartedHandler += value;
274 sliderSlidingStartedHandler -= value;
279 /// The sliding finished event handler.
281 /// <since_tizen> 8 </since_tizen>
282 public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
286 sliderSlidingFinishedHandler += value;
290 sliderSlidingFinishedHandler -= value;
295 /// The direction type of slider.
297 /// <since_tizen> 6 </since_tizen>
298 public enum DirectionType
301 /// The Horizontal type.
303 /// <since_tizen> 6 </since_tizen>
307 /// The Vertical type.
309 /// <since_tizen> 6 </since_tizen>
314 /// The indicator type of slider.
316 /// <since_tizen> 6 </since_tizen>
317 public enum IndicatorType
319 /// <summary> Only contains slider bar.</summary>
320 /// <since_tizen> 6 </since_tizen>
323 /// <summary> Contains slider bar, IndicatorImage.</summary>
324 /// <since_tizen> 6 </since_tizen>
327 /// <summary> Contains slider bar, IndicatorText.</summary>
328 /// <since_tizen> 6 </since_tizen>
333 /// Return currently applied style.
336 /// Modifying contents in style may cause unexpected behaviour.
338 /// <since_tizen> 8 </since_tizen>
339 public SliderStyle Style => (SliderStyle)(ViewStyle as SliderStyle)?.Clone();
342 /// Gets or sets the direction type of slider.
344 /// <since_tizen> 6 </since_tizen>
345 public DirectionType Direction
349 return (DirectionType)GetValue(DirectionProperty);
353 SetValue(DirectionProperty, value);
354 NotifyPropertyChanged();
357 private DirectionType InternalDirection
365 if (direction == value)
370 RelayoutBaseComponent(false);
372 UpdateBgTrackPosition();
373 UpdateWarningTrackSize();
379 /// Gets or sets the indicator type, arrow or sign.
381 /// <since_tizen> 6 </since_tizen>
382 public IndicatorType Indicator
386 return (IndicatorType)GetValue(IndicatorProperty);
390 SetValue(IndicatorProperty, value);
395 /// Gets or sets the minimum value of slider.
397 /// <since_tizen> 6 </since_tizen>
398 public float MinValue
402 return (float)GetValue(MinValueProperty);
406 SetValue(MinValueProperty, value);
407 NotifyPropertyChanged();
410 private float InternalMinValue
424 /// Gets or sets the maximum value of slider.
426 /// <since_tizen> 6 </since_tizen>
427 public float MaxValue
431 return (float)GetValue(MaxValueProperty);
435 SetValue(MaxValueProperty, value);
436 NotifyPropertyChanged();
439 private float InternalMaxValue
453 /// Gets or sets the current value of slider.
455 /// <since_tizen> 6 </since_tizen>
456 public float CurrentValue
460 return (float)GetValue(CurrentValueProperty);
464 SetValue(CurrentValueProperty, value);
469 /// Gets or sets the size of the thumb image object.
471 /// <since_tizen> 6 </since_tizen>
472 public Size ThumbSize
476 return GetValue(ThumbSizeProperty) as Size;
480 SetValue(ThumbSizeProperty, value);
481 NotifyPropertyChanged();
484 private Size InternalThumbSize
488 return thumbImage?.Size;
492 if (null != thumbImage)
494 thumbImage.Size = value;
501 /// Gets or sets the resource url of the thumb image object.
503 /// Please use ThumbImageUrl property.
505 /// <since_tizen> 6 </since_tizen>
506 public string ThumbImageURL
510 return GetValue(ThumbImageURLProperty) as string;
514 SetValue(ThumbImageURLProperty, value);
515 NotifyPropertyChanged();
518 private string InternalThumbImageURL
522 return thumbImage?.ResourceUrl;
526 if (null != thumbImage)
528 thumbImage.ResourceUrl = value;
529 thumbImageUrl = value;
535 /// Gets or sets the resource url selector of the thumb image object.
536 /// Getter returns copied selector value if exist, null otherwise.
538 /// Please use ThumbImageUrl property.
540 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
541 /// <since_tizen> 6 </since_tizen>
542 public StringSelector ThumbImageURLSelector
546 return GetValue(ThumbImageURLSelectorProperty) as StringSelector;
550 SetValue(ThumbImageURLSelectorProperty, value);
551 NotifyPropertyChanged();
554 private StringSelector InternalThumbImageURLSelector
558 Selector<string> resourceUrlSelector = thumbImage?.ResourceUrlSelector;
559 if(resourceUrlSelector != null)
561 return new StringSelector(resourceUrlSelector);
567 if (value == null || thumbImage == null)
569 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
573 thumbImage.ResourceUrlSelector = value;
579 /// Gets or sets the Url of the thumb image.
581 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
582 /// <since_tizen> 9 </since_tizen>
583 public Selector<string> ThumbImageUrl
587 return GetValue(ThumbImageUrlProperty) as Selector<string>;
591 SetValue(ThumbImageUrlProperty, value);
592 NotifyPropertyChanged();
595 private Selector<string> InternalThumbImageUrl
599 if (thumbImage == null)
605 return thumbImage.ResourceUrlSelector;
610 if (value == null || thumbImage == null)
612 throw new NullReferenceException("Slider.ThumbImageUrl is null");
616 thumbImage.ResourceUrlSelector = value;
622 /// Gets or sets the color of the thumb image object.
624 /// <since_tizen> 8 </since_tizen>
625 public Color ThumbColor
629 return GetValue(ThumbColorProperty) as Color;
633 SetValue(ThumbColorProperty, value);
634 NotifyPropertyChanged();
637 private Color InternalThumbColor
645 if (null != thumbImage)
649 if (thumbImage.ResourceUrl != null)
651 thumbImage.ResourceUrl = null;
654 using (PropertyMap map = new PropertyMap())
656 // To remove CA2000 warning messages, use `using` statement.
657 using (PropertyValue type = new PropertyValue((int)Visual.Type.Color))
659 map.Insert((int)Visual.Property.Type, type);
661 using (PropertyValue color = new PropertyValue(thumbColor))
663 map.Insert((int)ColorVisualProperty.MixColor, color);
665 using (PropertyValue radius = new PropertyValue(0.5f))
667 map.Insert((int)Visual.Property.CornerRadius, radius);
669 using (PropertyValue policyType = new PropertyValue((int)VisualTransformPolicyType.Relative))
671 map.Insert((int)Visual.Property.CornerRadiusPolicy, policyType);
673 thumbImage.Image = map;
680 /// Gets or sets the color of the background track image object.
682 /// <since_tizen> 6 </since_tizen>
683 public Color BgTrackColor
687 return GetValue(BgTrackColorProperty) as Color;
691 SetValue(BgTrackColorProperty, value);
692 NotifyPropertyChanged();
695 private Color InternalBgTrackColor
699 return bgTrackImage?.BackgroundColor;
703 if (null != bgTrackImage)
705 bgTrackImage.BackgroundColor = value;
711 /// Gets or sets the color of the slided track image object.
713 /// <since_tizen> 6 </since_tizen>
714 public Color SlidedTrackColor
718 return GetValue(SlidedTrackColorProperty) as Color;
722 SetValue(SlidedTrackColorProperty, value);
723 NotifyPropertyChanged();
726 private Color InternalSlidedTrackColor
730 return slidedTrackImage?.BackgroundColor;
734 if (null != slidedTrackImage)
736 slidedTrackImage.BackgroundColor = value;
742 /// Gets or sets the thickness value of the track.
744 /// <since_tizen> 6 </since_tizen>
745 public uint TrackThickness
749 return (uint)GetValue(TrackThicknessProperty);
753 SetValue(TrackThicknessProperty, value);
758 /// Gets or sets the warning start value between minimum value and maximum value of slider.
760 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
761 [EditorBrowsable(EditorBrowsableState.Never)]
762 public float WarningStartValue
766 return (float)GetValue(WarningStartValueProperty);
770 SetValue(WarningStartValueProperty, value);
771 NotifyPropertyChanged();
774 private float InternalWarningStartValue
778 return warningStartValue;
782 warningStartValue = value;
788 /// Gets or sets the color of the warning track image object.
790 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
791 [EditorBrowsable(EditorBrowsableState.Never)]
792 public Color WarningTrackColor
796 return GetValue(WarningTrackColorProperty) as Color;
800 SetValue(WarningTrackColorProperty, value);
801 NotifyPropertyChanged();
804 private Color InternalWarningTrackColor
808 return warningTrackImage?.BackgroundColor;
812 if (null != warningTrackImage)
814 warningTrackImage.BackgroundColor = value;
820 /// Gets or sets the color of the warning slided track image object.
822 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
823 [EditorBrowsable(EditorBrowsableState.Never)]
824 public Color WarningSlidedTrackColor
828 return GetValue(WarningSlidedTrackColorProperty) as Color;
832 SetValue(WarningSlidedTrackColorProperty, value);
833 NotifyPropertyChanged();
836 private Color InternalWarningSlidedTrackColor
840 return warningSlidedTrackImage?.BackgroundColor;
844 if (null != warningSlidedTrackImage)
846 warningSlidedTrackImage.BackgroundColor = value;
852 /// Gets or sets the Url of the warning thumb image.
854 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
855 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
856 [EditorBrowsable(EditorBrowsableState.Never)]
857 public Selector<string> WarningThumbImageUrl
861 return GetValue(WarningThumbImageUrlProperty) as Selector<string>;
865 SetValue(WarningThumbImageUrlProperty, value);
866 NotifyPropertyChanged();
869 private Selector<string> InternalWarningThumbImageUrl
873 return warningThumbImageUrlSelector;
877 if (value == null || thumbImage == null)
879 throw new NullReferenceException("Slider.WarningThumbImageUrl is null");
883 warningThumbImageUrlSelector = value;
889 /// Gets or sets the color of the warning thumb image object.
891 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
892 [EditorBrowsable(EditorBrowsableState.Never)]
893 public Color WarningThumbColor
897 return GetValue(WarningThumbColorProperty) as Color;
901 SetValue(WarningThumbColorProperty, value);
902 NotifyPropertyChanged();
905 private Color InternalWarningThumbColor
909 return warningThumbColor;
913 warningThumbColor = value;
918 /// Gets or sets the resource url of the low indicator image object.
920 /// <since_tizen> 6 </since_tizen>
921 public string LowIndicatorImageURL
925 return GetValue(LowIndicatorImageURLProperty) as string;
929 SetValue(LowIndicatorImageURLProperty, value);
930 NotifyPropertyChanged();
933 private string InternalLowIndicatorImageURL
937 return lowIndicatorImage?.ResourceUrl;
941 if (null == lowIndicatorImage)
943 lowIndicatorImage = new ImageView
945 AccessibilityHidden = true,
949 lowIndicatorImage.ResourceUrl = value;
954 /// Gets or sets the resource url of the high indicator image object.
956 /// <since_tizen> 6 </since_tizen>
957 public string HighIndicatorImageURL
961 return GetValue(HighIndicatorImageURLProperty) as string;
965 SetValue(HighIndicatorImageURLProperty, value);
966 NotifyPropertyChanged();
969 private string InternalHighIndicatorImageURL
973 return highIndicatorImage?.ResourceUrl;
977 if (null == highIndicatorImage)
979 highIndicatorImage = new ImageView
981 AccessibilityHidden = true,
985 highIndicatorImage.ResourceUrl = value;
990 /// Gets or sets the text content of the low indicator text object.
992 /// <since_tizen> 6 </since_tizen>
993 public string LowIndicatorTextContent
997 return GetValue(LowIndicatorTextContentProperty) as string;
1001 SetValue(LowIndicatorTextContentProperty, value);
1002 NotifyPropertyChanged();
1005 private string InternalLowIndicatorTextContent
1009 return lowIndicatorText?.Text;
1013 if (null != lowIndicatorText)
1015 lowIndicatorText.Text = value;
1021 /// Gets or sets the text content of the high indicator text object.
1023 /// <since_tizen> 6 </since_tizen>
1024 public string HighIndicatorTextContent
1028 return GetValue(HighIndicatorTextContentProperty) as string;
1032 SetValue(HighIndicatorTextContentProperty, value);
1033 NotifyPropertyChanged();
1036 private string InternalHighIndicatorTextContent
1040 return highIndicatorText?.Text;
1044 if (null != highIndicatorText)
1046 highIndicatorText.Text = value;
1052 /// Gets or sets the size of the low indicator object(image or text).
1054 /// <since_tizen> 6 </since_tizen>
1055 public Size LowIndicatorSize
1059 return GetValue(LowIndicatorSizeProperty) as Size;
1063 SetValue(LowIndicatorSizeProperty, value);
1064 NotifyPropertyChanged();
1067 private Size InternalLowIndicatorSize
1071 return lowIndicatorSize;
1075 lowIndicatorSize = value;
1076 UpdateLowIndicatorSize();
1077 UpdateBgTrackSize();
1078 UpdateBgTrackPosition();
1084 /// Gets or sets the size of the high indicator object(image or text).
1086 /// <since_tizen> 6 </since_tizen>
1087 public Size HighIndicatorSize
1091 return GetValue(HighIndicatorSizeProperty) as Size;
1095 SetValue(HighIndicatorSizeProperty, value);
1096 NotifyPropertyChanged();
1099 private Size InternalHighIndicatorSize
1103 return highIndicatorSize;
1107 highIndicatorSize = value;
1108 UpdateHighIndicatorSize();
1109 UpdateBgTrackSize();
1110 UpdateBgTrackPosition();
1116 /// Gets or sets the value of the space between track and indicator.
1118 /// <since_tizen> 6 </since_tizen>
1119 public uint SpaceBetweenTrackAndIndicator
1123 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
1127 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
1132 /// Flag to decide whether the value indicator is shown
1134 /// <since_tizen> 9 </since_tizen>
1135 public bool IsValueShown
1139 return (bool)GetValue(IsValueShownProperty);
1143 SetValue(IsValueShownProperty, value);
1148 /// Gets or sets the text of value indicator.
1150 /// <since_tizen> 9 </since_tizen>
1151 public string ValueIndicatorText
1155 return (string)GetValue(ValueIndicatorTextProperty);
1159 SetValue(ValueIndicatorTextProperty, value);
1164 /// Gets or sets the size of the value indicator image object.
1166 /// <since_tizen> 9 </since_tizen>
1167 public Size ValueIndicatorSize
1171 return GetValue(ValueIndicatorSizeProperty) as Size;
1175 SetValue(ValueIndicatorSizeProperty, value);
1176 NotifyPropertyChanged();
1179 private Size InternalValueIndicatorSize
1183 return valueIndicatorImage?.Size;
1187 if (null != valueIndicatorImage)
1189 valueIndicatorImage.Size = value;
1195 /// Gets or sets the resource url of the value indicator image object.
1197 /// <since_tizen> 9 </since_tizen>
1198 public string ValueIndicatorUrl
1202 return GetValue(ValueIndicatorUrlProperty) as string;
1206 SetValue(ValueIndicatorUrlProperty, value);
1207 NotifyPropertyChanged();
1210 private string InternalValueIndicatorUrl
1214 return valueIndicatorImage?.ResourceUrl;
1218 if (null != valueIndicatorImage)
1220 valueIndicatorImage.ResourceUrl = value;
1226 /// Flag to decide whether the thumb snaps to the nearest discrete value when the user drags the thumb or taps.
1228 /// The default value is false.
1230 /// <since_tizen> 9 </since_tizen>
1231 public bool IsDiscrete
1235 return (bool)GetValue(IsDiscreteProperty);
1239 SetValue(IsDiscreteProperty, value);
1240 NotifyPropertyChanged();
1243 private bool InternalIsDiscrete { get; set; } = false;
1246 /// Gets or sets the discrete value of slider.
1249 /// The discrete value is evenly spaced between MinValue and MaxValue.
1250 /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
1251 /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
1252 /// The default is 0.
1254 /// <since_tizen> 9 </since_tizen>
1255 public float DiscreteValue
1259 return (float)GetValue(DiscreteValueProperty);
1263 SetValue(DiscreteValueProperty, value);
1264 NotifyPropertyChanged();
1267 private float InternalDiscreteValue
1271 return discreteValue;
1275 discreteValue = value;
1280 private Extents spaceBetweenTrackAndIndicator
1284 if (null == spaceTrackIndicator)
1286 spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
1288 Extents extents = new Extents(start, end, top, bottom);
1289 spaceTrackIndicator.CopyFrom(extents);
1293 return spaceTrackIndicator;
1297 private IndicatorType privateIndicatorType
1301 return indicatorType;
1305 if (indicatorType == value)
1309 indicatorType = value;
1310 RelayoutBaseComponent(false);
1311 UpdateBgTrackSize();
1312 UpdateBgTrackPosition();
1317 private uint privateTrackThickness
1321 return trackThickness ?? 0;
1325 trackThickness = value;
1326 if (bgTrackImage != null)
1328 if (direction == DirectionType.Horizontal)
1330 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1332 else if (direction == DirectionType.Vertical)
1334 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1337 if (slidedTrackImage != null)
1339 if (direction == DirectionType.Horizontal)
1341 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1343 else if (direction == DirectionType.Vertical)
1345 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1348 if (warningTrackImage != null)
1350 if (direction == DirectionType.Horizontal)
1352 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1354 else if (direction == DirectionType.Vertical)
1356 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1359 if (warningSlidedTrackImage != null)
1361 if (direction == DirectionType.Horizontal)
1363 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1365 else if (direction == DirectionType.Vertical)
1367 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1373 private uint privateSpaceBetweenTrackAndIndicator
1377 return privateTrackPadding.Start;
1381 ushort val = (ushort)value;
1382 privateTrackPadding = new Extents(val, val, val, val);
1386 private Extents privateTrackPadding
1390 return spaceBetweenTrackAndIndicator;
1394 spaceBetweenTrackAndIndicator.CopyFrom(value);
1395 UpdateComponentByIndicatorTypeChanged();
1396 UpdateBgTrackSize();
1397 UpdateBgTrackPosition();
1403 /// Focus gained callback.
1405 /// <since_tizen> 8 </since_tizen>
1406 public override void OnFocusGained()
1408 //State = ControlStates.Focused;
1409 UpdateState(true, isPressed);
1410 base.OnFocusGained();
1414 /// Focus Lost callback.
1416 /// <since_tizen> 8 </since_tizen>
1417 public override void OnFocusLost()
1419 //State = ControlStates.Normal;
1420 UpdateState(false, isPressed);
1424 private bool editMode = false;
1425 private View recoverIndicator;
1426 private View editModeIndicator;
1429 [EditorBrowsable(EditorBrowsableState.Never)]
1430 public override bool OnKeyboardEnter()
1438 //set editMode false (toggle the mode)
1440 FocusManager.Instance.FocusIndicator = recoverIndicator;
1444 //set editMode true (toggle the mode)
1446 if (editModeIndicator == null)
1448 editModeIndicator = new View()
1450 PositionUsesPivotPoint = true,
1451 PivotPoint = new Position(0, 0, 0),
1452 WidthResizePolicy = ResizePolicyType.FillToParent,
1453 HeightResizePolicy = ResizePolicyType.FillToParent,
1454 BorderlineColor = Color.Red,
1455 BorderlineWidth = 6.0f,
1456 BorderlineOffset = -1f,
1457 BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.4f),
1458 AccessibilityHidden = true,
1461 recoverIndicator = FocusManager.Instance.FocusIndicator;
1462 FocusManager.Instance.FocusIndicator = editModeIndicator;
1464 UpdateState(true, isPressed);
1469 [EditorBrowsable(EditorBrowsableState.Never)]
1470 public override bool OnKey(Key key)
1472 if (!IsEnabled || null == key)
1477 if (key.State == Key.StateType.Down)
1482 valueDiff = discreteValue;
1486 // TODO : Currently we set the velocity of value as 1% hardly.
1487 // Can we use AccessibilityGetMinimumIncrement?
1488 valueDiff = (maxValue - minValue) * 0.01f;
1490 if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Left") ||
1491 (direction == DirectionType.Vertical && key.KeyPressedName == "Down"))
1495 if (minValue < curValue)
1498 CurrentValue -= valueDiff;
1500 return true; // Consumed
1503 else if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Right") ||
1504 (direction == DirectionType.Vertical && key.KeyPressedName == "Up"))
1508 if (maxValue > curValue)
1511 CurrentValue += valueDiff;
1513 return true; // Consumed
1517 else if (key.State == Key.StateType.Up)
1522 if (key.KeyPressedName == "Up" || key.KeyPressedName == "Right" || key.KeyPressedName == "Down" || key.KeyPressedName == "Left")
1533 /// Apply style to scrollbar.
1535 /// <param name="viewStyle">The style to apply.</param>
1536 /// <since_tizen> 8 </since_tizen>
1537 public override void ApplyStyle(ViewStyle viewStyle)
1539 base.ApplyStyle(viewStyle);
1541 SliderStyle sliderStyle = viewStyle as SliderStyle;
1543 if (null != sliderStyle?.Progress)
1545 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1548 if (null != sliderStyle?.LowIndicator)
1550 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1553 if (null != sliderStyle?.HighIndicator)
1555 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1558 if (null != sliderStyle?.LowIndicatorImage)
1560 CreateLowIndicatorImage().ApplyStyle(sliderStyle.LowIndicatorImage);
1563 if (null != sliderStyle?.HighIndicatorImage)
1565 CreateHighIndicatorImage().ApplyStyle(sliderStyle.HighIndicatorImage);
1568 if (null != sliderStyle?.Track)
1570 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1573 if (null != sliderStyle?.Thumb)
1575 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1578 if (null != sliderStyle?.ValueIndicatorText)
1580 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1583 if (null != sliderStyle?.ValueIndicatorImage)
1585 CreateValueIndicatorImage().ApplyStyle(sliderStyle.ValueIndicatorImage);
1588 if (null != sliderStyle?.WarningTrack)
1590 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1593 if (null != sliderStyle?.WarningProgress)
1595 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1598 EnableControlStatePropagation = true;
1602 /// Gets minimum value for Accessibility.
1604 [EditorBrowsable(EditorBrowsableState.Never)]
1605 double IAtspiValue.AccessibilityGetMinimum()
1607 return (double)MinValue;
1611 /// Gets the current value for Accessibility.
1613 [EditorBrowsable(EditorBrowsableState.Never)]
1614 double IAtspiValue.AccessibilityGetCurrent()
1616 return (double)CurrentValue;
1620 /// Formatted current value.
1622 [EditorBrowsable(EditorBrowsableState.Never)]
1623 string IAtspiValue.AccessibilityGetValueText()
1625 return $"{CurrentValue}";
1629 /// Gets maximum value for Accessibility.
1631 [EditorBrowsable(EditorBrowsableState.Never)]
1632 double IAtspiValue.AccessibilityGetMaximum()
1634 return (double)MaxValue;
1638 /// Sets the current value using Accessibility.
1640 [EditorBrowsable(EditorBrowsableState.Never)]
1641 bool IAtspiValue.AccessibilitySetCurrent(double value)
1643 var current = (float)value;
1645 if (current >= MinValue && current <= MaxValue)
1647 CurrentValue = current;
1655 /// Gets minimum increment for Accessibility.
1657 [EditorBrowsable(EditorBrowsableState.Never)]
1658 double IAtspiValue.AccessibilityGetMinimumIncrement()
1661 return (MaxValue - MinValue) / 20.0;
1665 /// Initialize AT-SPI object.
1667 [EditorBrowsable(EditorBrowsableState.Never)]
1668 public override void OnInitialize()
1670 base.OnInitialize();
1671 AccessibilityRole = Role.Slider;
1675 /// Get Slider style.
1677 /// <returns>The default slider style.</returns>
1678 /// <since_tizen> 8 </since_tizen>
1679 protected override ViewStyle CreateViewStyle()
1681 return new SliderStyle();
1687 /// <param name="type">Dispose type.</param>
1688 /// <since_tizen> 6 </since_tizen>
1689 protected override void Dispose(DisposeTypes type)
1696 if (type == DisposeTypes.Explicit)
1698 if (null != panGestureDetector)
1700 panGestureDetector.Detach(this);
1701 panGestureDetector.Detected -= OnPanGestureDetected;
1702 panGestureDetector.Dispose();
1703 panGestureDetector = null;
1706 if (null != thumbImage)
1708 thumbImage.TouchEvent -= OnTouchEventForThumb;
1709 Utility.Dispose(thumbImage);
1711 Utility.Dispose(warningSlidedTrackImage);
1712 Utility.Dispose(warningTrackImage);
1713 Utility.Dispose(slidedTrackImage);
1714 Utility.Dispose(bgTrackImage);
1715 Utility.Dispose(lowIndicatorImage);
1716 Utility.Dispose(highIndicatorImage);
1717 Utility.Dispose(lowIndicatorText);
1718 Utility.Dispose(highIndicatorText);
1719 Utility.Dispose(valueIndicatorImage);
1720 Utility.Dispose(valueIndicatorText);
1722 this.TouchEvent -= OnTouchEventForTrack;
1724 recoverIndicator = null;
1725 if (editModeIndicator != null)
1727 editModeIndicator.Dispose();
1728 editModeIndicator = null;
1736 /// Update Slider by style.
1738 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1739 [EditorBrowsable(EditorBrowsableState.Never)]
1740 protected override void OnUpdate()
1742 RelayoutBaseComponent();
1744 UpdateComponentByIndicatorTypeChanged();
1745 UpdateBgTrackSize();
1746 UpdateBgTrackPosition();
1747 UpdateWarningTrackSize();
1748 UpdateLowIndicatorSize();
1749 UpdateHighIndicatorSize();
1754 [EditorBrowsable(EditorBrowsableState.Never)]
1755 protected override void OnEnabled(bool enabled)
1757 base.OnEnabled(enabled);
1761 private void CalculateCurrentValueByGesture(float offset)
1763 currentSlidedOffset += offset;
1765 float resultValue = this.CurrentValue;
1767 int bgTrackLength = GetBgTrackLength();
1768 if (bgTrackLength != 0)
1770 resultValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1775 this.CurrentValue = CalculateDiscreteValue(resultValue);
1779 this.CurrentValue = resultValue;
1783 private bool OnTouchEventForTrack(object source, TouchEventArgs e)
1790 if (this.FocusableInTouch == false && editMode == false)
1795 PointStateType state = e.Touch.GetState(0);
1796 if (state == PointStateType.Down)
1800 valueIndicatorImage.Show();
1803 UpdateState(isFocused, true);
1805 sliderSlidingStartedHandler?.Invoke(this, new SliderSlidingStartedEventArgs
1807 CurrentValue = curValue
1810 Vector2 pos = e.Touch.GetLocalPosition(0);
1811 CalculateCurrentValueByTouch(pos);
1814 else if (state == PointStateType.Up)
1818 valueIndicatorImage.Hide();
1821 UpdateState(isFocused, false);
1823 sliderSlidingFinishedHandler?.Invoke(this, new SliderSlidingFinishedEventArgs
1825 CurrentValue = curValue
1831 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1833 if (this.FocusableInTouch == false && editMode == false)
1838 PointStateType state = e.Touch.GetState(0);
1839 if (state == PointStateType.Down)
1841 UpdateState(isFocused, true);
1843 else if (state == PointStateType.Up)
1845 UpdateState(isFocused, false);
1850 private void CalculateCurrentValueByTouch(Vector2 pos)
1852 int bgTrackLength = GetBgTrackLength();
1853 if (direction == DirectionType.Horizontal)
1855 currentSlidedOffset = pos.X - GetBgTrackLowIndicatorOffset();
1857 else if (direction == DirectionType.Vertical)
1859 currentSlidedOffset = this.Size2D.Height - pos.Y - GetBgTrackLowIndicatorOffset();
1862 if (bgTrackLength != 0)
1864 float resultValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1868 this.CurrentValue = CalculateDiscreteValue(resultValue);
1872 this.CurrentValue = resultValue;
1877 private float CalculateDiscreteValue(float value)
1879 return ((float)Math.Round((value / discreteValue)) * discreteValue);
1882 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1884 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1888 if (thumbImage == null || Style == null)
1892 isFocused = isFocusedNew;
1893 isPressed = isPressedNew;
1895 if (!IsEnabled) // Disabled
1897 ControlState = ControlState.Disabled;
1899 else if (!isFocused && !isPressed)
1901 ControlState = ControlState.Normal;
1905 ControlState = ControlState.Pressed;
1907 else if (!isPressed && isFocused)
1909 ControlState = ControlState.Focused;
1913 private void UpdateComponentByIndicatorTypeChanged()
1915 IndicatorType type = CurrentIndicatorType();
1916 if (type == IndicatorType.None)
1918 if (lowIndicatorImage != null)
1920 lowIndicatorImage.Hide();
1922 if (highIndicatorImage != null)
1924 highIndicatorImage.Hide();
1926 if (lowIndicatorText != null)
1928 lowIndicatorText.Hide();
1930 if (highIndicatorText != null)
1932 highIndicatorText.Hide();
1935 else if (type == IndicatorType.Image)
1937 if (lowIndicatorImage != null)
1939 lowIndicatorImage.Show();
1941 if (highIndicatorImage != null)
1943 highIndicatorImage.Show();
1945 if (lowIndicatorText != null)
1947 lowIndicatorText.Hide();
1949 if (highIndicatorText != null)
1951 highIndicatorText.Hide();
1954 else if (type == IndicatorType.Text)
1956 if (lowIndicatorText != null)
1958 lowIndicatorText.Show();
1960 if (highIndicatorText != null)
1962 highIndicatorText.Show();
1964 if (lowIndicatorImage != null)
1966 lowIndicatorImage.Hide();
1968 if (highIndicatorImage != null)
1970 highIndicatorImage.Hide();