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 {
195 CurrentValue = instance.curValue
197 if (Accessibility.Accessibility.IsEnabled && instance.IsHighlighted)
199 instance.EmitAccessibilityEvent(AccessibilityPropertyChangeEvent.Value);
201 instance.UpdateValue();
204 defaultValueCreator: (bindable) =>
206 var instance = (Slider)bindable;
207 return instance.curValue;
214 /// The constructor of the Slider class.
216 /// <since_tizen> 6 </since_tizen>
224 /// The constructor of the Slider class with specific style.
226 /// <param name="style">The string to initialize the Slider</param>
227 /// <since_tizen> 8 </since_tizen>
228 public Slider(string style) : base(style)
235 /// The constructor of the Slider class with specific style.
237 /// <param name="sliderStyle">The style object to initialize the Slider</param>
238 /// <since_tizen> 8 </since_tizen>
239 public Slider(SliderStyle sliderStyle) : base(sliderStyle)
246 /// The value changed event handler.
248 /// <since_tizen> 8 </since_tizen>
249 public event EventHandler<SliderValueChangedEventArgs> ValueChanged
253 sliderValueChangedHandler += value;
257 sliderValueChangedHandler -= value;
262 /// The sliding started event handler.
264 /// <since_tizen> 8 </since_tizen>
265 public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
269 sliderSlidingStartedHandler += value;
273 sliderSlidingStartedHandler -= value;
278 /// The sliding finished event handler.
280 /// <since_tizen> 8 </since_tizen>
281 public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
285 sliderSlidingFinishedHandler += value;
289 sliderSlidingFinishedHandler -= value;
294 /// The direction type of slider.
296 /// <since_tizen> 6 </since_tizen>
297 public enum DirectionType
300 /// The Horizontal type.
302 /// <since_tizen> 6 </since_tizen>
306 /// The Vertical type.
308 /// <since_tizen> 6 </since_tizen>
313 /// The indicator type of slider.
315 /// <since_tizen> 6 </since_tizen>
316 public enum IndicatorType
318 /// <summary> Only contains slider bar.</summary>
319 /// <since_tizen> 6 </since_tizen>
322 /// <summary> Contains slider bar, IndicatorImage.</summary>
323 /// <since_tizen> 6 </since_tizen>
326 /// <summary> Contains slider bar, IndicatorText.</summary>
327 /// <since_tizen> 6 </since_tizen>
332 /// Return currently applied style.
335 /// Modifying contents in style may cause unexpected behaviour.
337 /// <since_tizen> 8 </since_tizen>
338 public SliderStyle Style => (SliderStyle)(ViewStyle as SliderStyle)?.Clone();
341 /// Gets or sets the direction type of slider.
343 /// <since_tizen> 6 </since_tizen>
344 public DirectionType Direction
348 return (DirectionType)GetValue(DirectionProperty);
352 SetValue(DirectionProperty, value);
353 NotifyPropertyChanged();
356 private DirectionType InternalDirection
364 if (direction == value)
369 RelayoutBaseComponent(false);
371 UpdateBgTrackPosition();
372 UpdateWarningTrackSize();
378 /// Gets or sets the indicator type, arrow or sign.
380 /// <since_tizen> 6 </since_tizen>
381 public IndicatorType Indicator
385 return (IndicatorType)GetValue(IndicatorProperty);
389 SetValue(IndicatorProperty, value);
394 /// Gets or sets the minimum value of slider.
396 /// <since_tizen> 6 </since_tizen>
397 public float MinValue
401 return (float)GetValue(MinValueProperty);
405 SetValue(MinValueProperty, value);
406 NotifyPropertyChanged();
409 private float InternalMinValue
423 /// Gets or sets the maximum value of slider.
425 /// <since_tizen> 6 </since_tizen>
426 public float MaxValue
430 return (float)GetValue(MaxValueProperty);
434 SetValue(MaxValueProperty, value);
435 NotifyPropertyChanged();
438 private float InternalMaxValue
452 /// Gets or sets the current value of slider.
454 /// <since_tizen> 6 </since_tizen>
455 public float CurrentValue
459 return (float)GetValue(CurrentValueProperty);
463 SetValue(CurrentValueProperty, value);
468 /// Gets or sets the size of the thumb image object.
470 /// <since_tizen> 6 </since_tizen>
471 public Size ThumbSize
475 return GetValue(ThumbSizeProperty) as Size;
479 SetValue(ThumbSizeProperty, value);
480 NotifyPropertyChanged();
483 private Size InternalThumbSize
487 return thumbImage?.Size;
491 if (null != thumbImage)
493 thumbImage.Size = value;
500 /// Gets or sets the resource url of the thumb image object.
502 /// Please use ThumbImageUrl property.
504 /// <since_tizen> 6 </since_tizen>
505 public string ThumbImageURL
509 return GetValue(ThumbImageURLProperty) as string;
513 SetValue(ThumbImageURLProperty, value);
514 NotifyPropertyChanged();
517 private string InternalThumbImageURL
521 return thumbImage?.ResourceUrl;
525 if (null != thumbImage)
527 thumbImage.ResourceUrl = value;
528 thumbImageUrl = value;
534 /// Gets or sets the resource url selector of the thumb image object.
535 /// Getter returns copied selector value if exist, null otherwise.
537 /// Please use ThumbImageUrl property.
539 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
540 /// <since_tizen> 6 </since_tizen>
541 public StringSelector ThumbImageURLSelector
545 return GetValue(ThumbImageURLSelectorProperty) as StringSelector;
549 SetValue(ThumbImageURLSelectorProperty, value);
550 NotifyPropertyChanged();
553 private StringSelector InternalThumbImageURLSelector
555 get => thumbImage?.ResourceUrlSelector == null ? null : new StringSelector(thumbImage.ResourceUrlSelector);
558 if (value == null || thumbImage == null)
560 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
564 thumbImage.ResourceUrlSelector = value;
570 /// Gets or sets the Url of the thumb image.
572 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
573 /// <since_tizen> 9 </since_tizen>
574 public Selector<string> ThumbImageUrl
578 return GetValue(ThumbImageUrlProperty) as Selector<string>;
582 SetValue(ThumbImageUrlProperty, value);
583 NotifyPropertyChanged();
586 private Selector<string> InternalThumbImageUrl
590 if (thumbImage == null)
596 return thumbImage.ResourceUrlSelector;
601 if (value == null || thumbImage == null)
603 throw new NullReferenceException("Slider.ThumbImageUrl is null");
607 thumbImage.ResourceUrlSelector = value;
613 /// Gets or sets the color of the thumb image object.
615 /// <since_tizen> 8 </since_tizen>
616 public Color ThumbColor
620 return GetValue(ThumbColorProperty) as Color;
624 SetValue(ThumbColorProperty, value);
625 NotifyPropertyChanged();
628 private Color InternalThumbColor
636 if (null != thumbImage)
640 if (thumbImage.ResourceUrl != null)
642 thumbImage.ResourceUrl = null;
645 using (PropertyMap map = new PropertyMap())
647 // To remove CA2000 warning messages, use `using` statement.
648 using (PropertyValue type = new PropertyValue((int)Visual.Type.Color))
650 map.Insert((int)Visual.Property.Type, type);
652 using (PropertyValue color = new PropertyValue(thumbColor))
654 map.Insert((int)ColorVisualProperty.MixColor, color);
656 using (PropertyValue radius = new PropertyValue(0.5f))
658 map.Insert((int)Visual.Property.CornerRadius, radius);
660 using (PropertyValue policyType = new PropertyValue((int)VisualTransformPolicyType.Relative))
662 map.Insert((int)Visual.Property.CornerRadiusPolicy, policyType);
664 thumbImage.Image = map;
671 /// Gets or sets the color of the background track image object.
673 /// <since_tizen> 6 </since_tizen>
674 public Color BgTrackColor
678 return GetValue(BgTrackColorProperty) as Color;
682 SetValue(BgTrackColorProperty, value);
683 NotifyPropertyChanged();
686 private Color InternalBgTrackColor
690 return bgTrackImage?.BackgroundColor;
694 if (null != bgTrackImage)
696 bgTrackImage.BackgroundColor = value;
702 /// Gets or sets the color of the slided track image object.
704 /// <since_tizen> 6 </since_tizen>
705 public Color SlidedTrackColor
709 return GetValue(SlidedTrackColorProperty) as Color;
713 SetValue(SlidedTrackColorProperty, value);
714 NotifyPropertyChanged();
717 private Color InternalSlidedTrackColor
721 return slidedTrackImage?.BackgroundColor;
725 if (null != slidedTrackImage)
727 slidedTrackImage.BackgroundColor = value;
733 /// Gets or sets the thickness value of the track.
735 /// <since_tizen> 6 </since_tizen>
736 public uint TrackThickness
740 return (uint)GetValue(TrackThicknessProperty);
744 SetValue(TrackThicknessProperty, value);
749 /// Gets or sets the warning start value between minimum value and maximum value of slider.
751 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
752 [EditorBrowsable(EditorBrowsableState.Never)]
753 public float WarningStartValue
757 return (float)GetValue(WarningStartValueProperty);
761 SetValue(WarningStartValueProperty, value);
762 NotifyPropertyChanged();
765 private float InternalWarningStartValue
769 return warningStartValue;
773 warningStartValue = value;
779 /// Gets or sets the color of the warning track image object.
781 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
782 [EditorBrowsable(EditorBrowsableState.Never)]
783 public Color WarningTrackColor
787 return GetValue(WarningTrackColorProperty) as Color;
791 SetValue(WarningTrackColorProperty, value);
792 NotifyPropertyChanged();
795 private Color InternalWarningTrackColor
799 return warningTrackImage?.BackgroundColor;
803 if (null != warningTrackImage)
805 warningTrackImage.BackgroundColor = value;
811 /// Gets or sets the color of the warning slided track image object.
813 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
814 [EditorBrowsable(EditorBrowsableState.Never)]
815 public Color WarningSlidedTrackColor
819 return GetValue(WarningSlidedTrackColorProperty) as Color;
823 SetValue(WarningSlidedTrackColorProperty, value);
824 NotifyPropertyChanged();
827 private Color InternalWarningSlidedTrackColor
831 return warningSlidedTrackImage?.BackgroundColor;
835 if (null != warningSlidedTrackImage)
837 warningSlidedTrackImage.BackgroundColor = value;
843 /// Gets or sets the Url of the warning thumb image.
845 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
846 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
847 [EditorBrowsable(EditorBrowsableState.Never)]
848 public Selector<string> WarningThumbImageUrl
852 return GetValue(WarningThumbImageUrlProperty) as Selector<string>;
856 SetValue(WarningThumbImageUrlProperty, value);
857 NotifyPropertyChanged();
860 private Selector<string> InternalWarningThumbImageUrl
864 return warningThumbImageUrlSelector;
868 if (value == null || thumbImage == null)
870 throw new NullReferenceException("Slider.WarningThumbImageUrl is null");
874 warningThumbImageUrlSelector = value;
880 /// Gets or sets the color of the warning thumb image object.
882 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
883 [EditorBrowsable(EditorBrowsableState.Never)]
884 public Color WarningThumbColor
888 return GetValue(WarningThumbColorProperty) as Color;
892 SetValue(WarningThumbColorProperty, value);
893 NotifyPropertyChanged();
896 private Color InternalWarningThumbColor
900 return warningThumbColor;
904 warningThumbColor = value;
909 /// Gets or sets the resource url of the low indicator image object.
911 /// <since_tizen> 6 </since_tizen>
912 public string LowIndicatorImageURL
916 return GetValue(LowIndicatorImageURLProperty) as string;
920 SetValue(LowIndicatorImageURLProperty, value);
921 NotifyPropertyChanged();
924 private string InternalLowIndicatorImageURL
928 return lowIndicatorImage?.ResourceUrl;
932 if (null == lowIndicatorImage)
934 lowIndicatorImage = new ImageView
936 AccessibilityHidden = true,
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)
970 highIndicatorImage = new ImageView
972 AccessibilityHidden = true,
976 highIndicatorImage.ResourceUrl = value;
981 /// Gets or sets the text content of the low indicator text object.
983 /// <since_tizen> 6 </since_tizen>
984 public string LowIndicatorTextContent
988 return GetValue(LowIndicatorTextContentProperty) as string;
992 SetValue(LowIndicatorTextContentProperty, value);
993 NotifyPropertyChanged();
996 private string InternalLowIndicatorTextContent
1000 return lowIndicatorText?.Text;
1004 if (null != lowIndicatorText)
1006 lowIndicatorText.Text = value;
1012 /// Gets or sets the text content of the high indicator text object.
1014 /// <since_tizen> 6 </since_tizen>
1015 public string HighIndicatorTextContent
1019 return GetValue(HighIndicatorTextContentProperty) as string;
1023 SetValue(HighIndicatorTextContentProperty, value);
1024 NotifyPropertyChanged();
1027 private string InternalHighIndicatorTextContent
1031 return highIndicatorText?.Text;
1035 if (null != highIndicatorText)
1037 highIndicatorText.Text = value;
1043 /// Gets or sets the size of the low indicator object(image or text).
1045 /// <since_tizen> 6 </since_tizen>
1046 public Size LowIndicatorSize
1050 return GetValue(LowIndicatorSizeProperty) as Size;
1054 SetValue(LowIndicatorSizeProperty, value);
1055 NotifyPropertyChanged();
1058 private Size InternalLowIndicatorSize
1062 return lowIndicatorSize;
1066 lowIndicatorSize = value;
1067 UpdateLowIndicatorSize();
1068 UpdateBgTrackSize();
1069 UpdateBgTrackPosition();
1075 /// Gets or sets the size of the high indicator object(image or text).
1077 /// <since_tizen> 6 </since_tizen>
1078 public Size HighIndicatorSize
1082 return GetValue(HighIndicatorSizeProperty) as Size;
1086 SetValue(HighIndicatorSizeProperty, value);
1087 NotifyPropertyChanged();
1090 private Size InternalHighIndicatorSize
1094 return highIndicatorSize;
1098 highIndicatorSize = value;
1099 UpdateHighIndicatorSize();
1100 UpdateBgTrackSize();
1101 UpdateBgTrackPosition();
1107 /// Gets or sets the value of the space between track and indicator.
1109 /// <since_tizen> 6 </since_tizen>
1110 public uint SpaceBetweenTrackAndIndicator
1114 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
1118 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
1123 /// Flag to decide whether the value indicator is shown
1125 /// <since_tizen> 9 </since_tizen>
1126 public bool IsValueShown
1130 return (bool)GetValue(IsValueShownProperty);
1134 SetValue(IsValueShownProperty, value);
1139 /// Gets or sets the text of value indicator.
1141 /// <since_tizen> 9 </since_tizen>
1142 public string ValueIndicatorText
1146 return (string)GetValue(ValueIndicatorTextProperty);
1150 SetValue(ValueIndicatorTextProperty, value);
1155 /// Gets or sets the size of the value indicator image object.
1157 /// <since_tizen> 9 </since_tizen>
1158 public Size ValueIndicatorSize
1162 return GetValue(ValueIndicatorSizeProperty) as Size;
1166 SetValue(ValueIndicatorSizeProperty, value);
1167 NotifyPropertyChanged();
1170 private Size InternalValueIndicatorSize
1174 return valueIndicatorImage?.Size;
1178 if (null != valueIndicatorImage)
1180 valueIndicatorImage.Size = value;
1186 /// Gets or sets the resource url of the value indicator image object.
1188 /// <since_tizen> 9 </since_tizen>
1189 public string ValueIndicatorUrl
1193 return GetValue(ValueIndicatorUrlProperty) as string;
1197 SetValue(ValueIndicatorUrlProperty, value);
1198 NotifyPropertyChanged();
1201 private string InternalValueIndicatorUrl
1205 return valueIndicatorImage?.ResourceUrl;
1209 if (null != valueIndicatorImage)
1211 valueIndicatorImage.ResourceUrl = value;
1217 /// Flag to decide whether the thumb snaps to the nearest discrete value when the user drags the thumb or taps.
1219 /// The default value is false.
1221 /// <since_tizen> 9 </since_tizen>
1222 public bool IsDiscrete
1226 return (bool)GetValue(IsDiscreteProperty);
1230 SetValue(IsDiscreteProperty, value);
1231 NotifyPropertyChanged();
1234 private bool InternalIsDiscrete { get; set; } = false;
1237 /// Gets or sets the discrete value of slider.
1240 /// The discrete value is evenly spaced between MinValue and MaxValue.
1241 /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
1242 /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
1243 /// The default is 0.
1245 /// <since_tizen> 9 </since_tizen>
1246 public float DiscreteValue
1250 return (float)GetValue(DiscreteValueProperty);
1254 SetValue(DiscreteValueProperty, value);
1255 NotifyPropertyChanged();
1258 private float InternalDiscreteValue
1262 return discreteValue;
1266 discreteValue = value;
1271 private Extents spaceBetweenTrackAndIndicator
1275 if (null == spaceTrackIndicator)
1277 spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
1279 Extents extents = new Extents(start, end, top, bottom);
1280 spaceTrackIndicator.CopyFrom(extents);
1284 return spaceTrackIndicator;
1288 private IndicatorType privateIndicatorType
1292 return indicatorType;
1296 if (indicatorType == value)
1300 indicatorType = value;
1301 RelayoutBaseComponent(false);
1302 UpdateBgTrackSize();
1303 UpdateBgTrackPosition();
1308 private uint privateTrackThickness
1312 return trackThickness ?? 0;
1316 trackThickness = value;
1317 if (bgTrackImage != null)
1319 if (direction == DirectionType.Horizontal)
1321 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1323 else if (direction == DirectionType.Vertical)
1325 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1328 if (slidedTrackImage != null)
1330 if (direction == DirectionType.Horizontal)
1332 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1334 else if (direction == DirectionType.Vertical)
1336 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1339 if (warningTrackImage != null)
1341 if (direction == DirectionType.Horizontal)
1343 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1345 else if (direction == DirectionType.Vertical)
1347 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1350 if (warningSlidedTrackImage != null)
1352 if (direction == DirectionType.Horizontal)
1354 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1356 else if (direction == DirectionType.Vertical)
1358 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1364 private uint privateSpaceBetweenTrackAndIndicator
1368 return privateTrackPadding.Start;
1372 ushort val = (ushort)value;
1373 privateTrackPadding = new Extents(val, val, val, val);
1377 private Extents privateTrackPadding
1381 return spaceBetweenTrackAndIndicator;
1385 spaceBetweenTrackAndIndicator.CopyFrom(value);
1386 UpdateComponentByIndicatorTypeChanged();
1387 UpdateBgTrackSize();
1388 UpdateBgTrackPosition();
1394 /// Focus gained callback.
1396 /// <since_tizen> 8 </since_tizen>
1397 public override void OnFocusGained()
1399 //State = ControlStates.Focused;
1400 UpdateState(true, isPressed);
1401 base.OnFocusGained();
1405 /// Focus Lost callback.
1407 /// <since_tizen> 8 </since_tizen>
1408 public override void OnFocusLost()
1410 //State = ControlStates.Normal;
1411 UpdateState(false, isPressed);
1415 private bool editMode = false;
1416 private View recoverIndicator;
1417 private View editModeIndicator;
1420 [EditorBrowsable(EditorBrowsableState.Never)]
1421 public override bool OnKeyboardEnter()
1429 //set editMode false (toggle the mode)
1431 FocusManager.Instance.FocusIndicator = recoverIndicator;
1435 //set editMode true (toggle the mode)
1437 if (editModeIndicator == null)
1439 editModeIndicator = new View()
1441 PositionUsesPivotPoint = true,
1442 PivotPoint = new Position(0, 0, 0),
1443 WidthResizePolicy = ResizePolicyType.FillToParent,
1444 HeightResizePolicy = ResizePolicyType.FillToParent,
1445 BorderlineColor = Color.Red,
1446 BorderlineWidth = 6.0f,
1447 BorderlineOffset = -1f,
1448 BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.4f),
1449 AccessibilityHidden = true,
1452 recoverIndicator = FocusManager.Instance.FocusIndicator;
1453 FocusManager.Instance.FocusIndicator = editModeIndicator;
1455 UpdateState(true, isPressed);
1460 [EditorBrowsable(EditorBrowsableState.Never)]
1461 public override bool OnKey(Key key)
1463 if (!IsEnabled || null == key)
1468 if (key.State == Key.StateType.Down)
1470 if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Left") ||
1471 (direction == DirectionType.Vertical && key.KeyPressedName == "Down"))
1475 if (MinValue < CurrentValue)
1480 float value = curValue - discreteValue;
1481 CurrentValue = value;
1488 return true; // Consumed
1491 else if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Right") ||
1492 (direction == DirectionType.Vertical && key.KeyPressedName == "Up"))
1496 if (MaxValue > CurrentValue)
1501 float value = curValue + discreteValue;
1502 CurrentValue = value;
1509 return true; // Consumed
1513 else if (key.State == Key.StateType.Up)
1518 if (key.KeyPressedName == "Up" || key.KeyPressedName == "Right" || key.KeyPressedName == "Down" || key.KeyPressedName == "Left")
1529 /// Apply style to scrollbar.
1531 /// <param name="viewStyle">The style to apply.</param>
1532 /// <since_tizen> 8 </since_tizen>
1533 public override void ApplyStyle(ViewStyle viewStyle)
1535 base.ApplyStyle(viewStyle);
1537 SliderStyle sliderStyle = viewStyle as SliderStyle;
1539 if (null != sliderStyle?.Progress)
1541 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1544 if (null != sliderStyle?.LowIndicator)
1546 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1549 if (null != sliderStyle?.HighIndicator)
1551 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1554 if (null != sliderStyle?.LowIndicatorImage)
1556 CreateLowIndicatorImage().ApplyStyle(sliderStyle.LowIndicatorImage);
1559 if (null != sliderStyle?.HighIndicatorImage)
1561 CreateHighIndicatorImage().ApplyStyle(sliderStyle.HighIndicatorImage);
1564 if (null != sliderStyle?.Track)
1566 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1569 if (null != sliderStyle?.Thumb)
1571 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1574 if (null != sliderStyle?.ValueIndicatorText)
1576 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1579 if (null != sliderStyle?.ValueIndicatorImage)
1581 CreateValueIndicatorImage().ApplyStyle(sliderStyle.ValueIndicatorImage);
1584 if (null != sliderStyle?.WarningTrack)
1586 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1589 if (null != sliderStyle?.WarningProgress)
1591 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1594 EnableControlStatePropagation = true;
1598 /// Gets minimum value for Accessibility.
1600 [EditorBrowsable(EditorBrowsableState.Never)]
1601 double IAtspiValue.AccessibilityGetMinimum()
1603 return (double)MinValue;
1607 /// Gets the current value for Accessibility.
1609 [EditorBrowsable(EditorBrowsableState.Never)]
1610 double IAtspiValue.AccessibilityGetCurrent()
1612 return (double)CurrentValue;
1616 /// Gets maximum value for Accessibility.
1618 [EditorBrowsable(EditorBrowsableState.Never)]
1619 double IAtspiValue.AccessibilityGetMaximum()
1621 return (double)MaxValue;
1625 /// Sets the current value using Accessibility.
1627 [EditorBrowsable(EditorBrowsableState.Never)]
1628 bool IAtspiValue.AccessibilitySetCurrent(double value)
1630 var current = (float)value;
1632 if (current >= MinValue && current <= MaxValue)
1634 CurrentValue = current;
1642 /// Gets minimum increment for Accessibility.
1644 [EditorBrowsable(EditorBrowsableState.Never)]
1645 double IAtspiValue.AccessibilityGetMinimumIncrement()
1648 return (MaxValue - MinValue) / 20.0;
1652 /// Initialize AT-SPI object.
1654 [EditorBrowsable(EditorBrowsableState.Never)]
1655 public override void OnInitialize()
1657 base.OnInitialize();
1658 AccessibilityRole = Role.Slider;
1662 /// Get Slider style.
1664 /// <returns>The default slider style.</returns>
1665 /// <since_tizen> 8 </since_tizen>
1666 protected override ViewStyle CreateViewStyle()
1668 return new SliderStyle();
1674 /// <param name="type">Dispose type.</param>
1675 /// <since_tizen> 6 </since_tizen>
1676 protected override void Dispose(DisposeTypes type)
1683 if (type == DisposeTypes.Explicit)
1685 if (null != panGestureDetector)
1687 panGestureDetector.Detach(this);
1688 panGestureDetector.Detected -= OnPanGestureDetected;
1689 panGestureDetector.Dispose();
1690 panGestureDetector = null;
1693 if (null != thumbImage)
1695 thumbImage.TouchEvent -= OnTouchEventForThumb;
1696 Utility.Dispose(thumbImage);
1698 Utility.Dispose(warningSlidedTrackImage);
1699 Utility.Dispose(warningTrackImage);
1700 Utility.Dispose(slidedTrackImage);
1701 Utility.Dispose(bgTrackImage);
1702 Utility.Dispose(lowIndicatorImage);
1703 Utility.Dispose(highIndicatorImage);
1704 Utility.Dispose(lowIndicatorText);
1705 Utility.Dispose(highIndicatorText);
1706 Utility.Dispose(valueIndicatorImage);
1707 Utility.Dispose(valueIndicatorText);
1709 this.TouchEvent -= OnTouchEventForTrack;
1711 recoverIndicator = null;
1712 if (editModeIndicator != null)
1714 editModeIndicator.Dispose();
1715 editModeIndicator = null;
1723 /// Update Slider by style.
1725 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1726 [EditorBrowsable(EditorBrowsableState.Never)]
1727 protected override void OnUpdate()
1729 RelayoutBaseComponent();
1731 UpdateComponentByIndicatorTypeChanged();
1732 UpdateBgTrackSize();
1733 UpdateBgTrackPosition();
1734 UpdateWarningTrackSize();
1735 UpdateLowIndicatorSize();
1736 UpdateHighIndicatorSize();
1741 [EditorBrowsable(EditorBrowsableState.Never)]
1742 protected override void OnEnabled(bool enabled)
1744 base.OnEnabled(enabled);
1748 private void CalculateCurrentValueByGesture(float offset)
1750 currentSlidedOffset += offset;
1752 if (currentSlidedOffset <= 0)
1754 this.CurrentValue = minValue;
1756 else if (currentSlidedOffset >= GetBgTrackLength())
1758 this.CurrentValue = maxValue;
1762 int bgTrackLength = GetBgTrackLength();
1763 if (bgTrackLength != 0)
1765 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1771 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1775 private bool OnTouchEventForTrack(object source, TouchEventArgs e)
1782 if (this.FocusableInTouch == false && editMode == false)
1787 PointStateType state = e.Touch.GetState(0);
1788 if (state == PointStateType.Down)
1792 valueIndicatorImage.Show();
1795 UpdateState(isFocused, true);
1797 sliderSlidingStartedHandler?.Invoke(this, new SliderSlidingStartedEventArgs {
1798 CurrentValue = curValue
1801 Vector2 pos = e.Touch.GetLocalPosition(0);
1802 CalculateCurrentValueByTouch(pos);
1805 else if (state == PointStateType.Up)
1809 valueIndicatorImage.Hide();
1812 UpdateState(isFocused, false);
1814 sliderSlidingFinishedHandler?.Invoke(this, new SliderSlidingFinishedEventArgs {
1815 CurrentValue = curValue
1821 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1823 if (this.FocusableInTouch == false && editMode == false)
1828 PointStateType state = e.Touch.GetState(0);
1829 if (state == PointStateType.Down)
1831 UpdateState(isFocused, true);
1833 else if (state == PointStateType.Up)
1835 UpdateState(isFocused, false);
1840 private void CalculateCurrentValueByTouch(Vector2 pos)
1842 int bgTrackLength = GetBgTrackLength();
1843 if (direction == DirectionType.Horizontal)
1845 currentSlidedOffset = pos.X - GetBgTrackLowIndicatorOffset();
1847 else if (direction == DirectionType.Vertical)
1849 currentSlidedOffset = this.Size2D.Height - pos.Y - GetBgTrackLowIndicatorOffset();
1852 if (bgTrackLength != 0)
1854 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1858 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1863 private float CalculateDiscreteValue(float value)
1865 return ((float)Math.Round((value / discreteValue)) * discreteValue);
1868 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1870 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1874 if (thumbImage == null || Style == null)
1878 isFocused = isFocusedNew;
1879 isPressed = isPressedNew;
1881 if (!IsEnabled) // Disabled
1883 ControlState = ControlState.Disabled;
1885 else if (!isFocused && !isPressed)
1887 ControlState = ControlState.Normal;
1891 ControlState = ControlState.Pressed;
1893 else if (!isPressed && isFocused)
1895 ControlState = ControlState.Focused;
1899 private void UpdateComponentByIndicatorTypeChanged()
1901 IndicatorType type = CurrentIndicatorType();
1902 if (type == IndicatorType.None)
1904 if (lowIndicatorImage != null)
1906 lowIndicatorImage.Hide();
1908 if (highIndicatorImage != null)
1910 highIndicatorImage.Hide();
1912 if (lowIndicatorText != null)
1914 lowIndicatorText.Hide();
1916 if (highIndicatorText != null)
1918 highIndicatorText.Hide();
1921 else if (type == IndicatorType.Image)
1923 if (lowIndicatorImage != null)
1925 lowIndicatorImage.Show();
1927 if (highIndicatorImage != null)
1929 highIndicatorImage.Show();
1931 if (lowIndicatorText != null)
1933 lowIndicatorText.Hide();
1935 if (highIndicatorText != null)
1937 highIndicatorText.Hide();
1940 else if (type == IndicatorType.Text)
1942 if (lowIndicatorText != null)
1944 lowIndicatorText.Show();
1946 if (highIndicatorText != null)
1948 highIndicatorText.Show();
1950 if (lowIndicatorImage != null)
1952 lowIndicatorImage.Hide();
1954 if (highIndicatorImage != null)
1956 highIndicatorImage.Hide();