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 instance.curValue = (float)newValue;
181 if (Accessibility.Accessibility.IsEnabled && instance.IsHighlighted)
183 instance.EmitAccessibilityEvent(AccessibilityPropertyChangeEvent.Value);
185 instance.UpdateValue();
188 defaultValueCreator: (bindable) =>
190 var instance = (Slider)bindable;
191 return instance.curValue;
198 /// The constructor of the Slider class.
200 /// <since_tizen> 6 </since_tizen>
208 /// The constructor of the Slider class with specific style.
210 /// <param name="style">The string to initialize the Slider</param>
211 /// <since_tizen> 8 </since_tizen>
212 public Slider(string style) : base(style)
219 /// The constructor of the Slider class with specific style.
221 /// <param name="sliderStyle">The style object to initialize the Slider</param>
222 /// <since_tizen> 8 </since_tizen>
223 public Slider(SliderStyle sliderStyle) : base(sliderStyle)
230 /// The value changed event handler.
232 /// <since_tizen> 8 </since_tizen>
233 public event EventHandler<SliderValueChangedEventArgs> ValueChanged
237 sliderValueChangedHandler += value;
241 sliderValueChangedHandler -= value;
246 /// The sliding started event handler.
248 /// <since_tizen> 8 </since_tizen>
249 public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
253 sliderSlidingStartedHandler += value;
257 sliderSlidingStartedHandler -= value;
262 /// The sliding finished event handler.
264 /// <since_tizen> 8 </since_tizen>
265 public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
269 sliderSlidingFinishedHandler += value;
273 sliderSlidingFinishedHandler -= value;
278 /// The direction type of slider.
280 /// <since_tizen> 6 </since_tizen>
281 public enum DirectionType
284 /// The Horizontal type.
286 /// <since_tizen> 6 </since_tizen>
290 /// The Vertical type.
292 /// <since_tizen> 6 </since_tizen>
297 /// The indicator type of slider.
299 /// <since_tizen> 6 </since_tizen>
300 public enum IndicatorType
302 /// <summary> Only contains slider bar.</summary>
303 /// <since_tizen> 6 </since_tizen>
306 /// <summary> Contains slider bar, IndicatorImage.</summary>
307 /// <since_tizen> 6 </since_tizen>
310 /// <summary> Contains slider bar, IndicatorText.</summary>
311 /// <since_tizen> 6 </since_tizen>
316 /// Return currently applied style.
319 /// Modifying contents in style may cause unexpected behaviour.
321 /// <since_tizen> 8 </since_tizen>
322 public SliderStyle Style => (SliderStyle)(ViewStyle as SliderStyle)?.Clone();
325 /// Gets or sets the direction type of slider.
327 /// <since_tizen> 6 </since_tizen>
328 public DirectionType Direction
332 return (DirectionType)GetValue(DirectionProperty);
336 SetValue(DirectionProperty, value);
337 NotifyPropertyChanged();
340 private DirectionType InternalDirection
348 if (direction == value)
353 RelayoutBaseComponent(false);
355 UpdateBgTrackPosition();
356 UpdateWarningTrackSize();
362 /// Gets or sets the indicator type, arrow or sign.
364 /// <since_tizen> 6 </since_tizen>
365 public IndicatorType Indicator
369 return (IndicatorType)GetValue(IndicatorProperty);
373 SetValue(IndicatorProperty, value);
378 /// Gets or sets the minimum value of slider.
380 /// <since_tizen> 6 </since_tizen>
381 public float MinValue
385 return (float)GetValue(MinValueProperty);
389 SetValue(MinValueProperty, value);
390 NotifyPropertyChanged();
393 private float InternalMinValue
407 /// Gets or sets the maximum value of slider.
409 /// <since_tizen> 6 </since_tizen>
410 public float MaxValue
414 return (float)GetValue(MaxValueProperty);
418 SetValue(MaxValueProperty, value);
419 NotifyPropertyChanged();
422 private float InternalMaxValue
436 /// Gets or sets the current value of slider.
438 /// <since_tizen> 6 </since_tizen>
439 public float CurrentValue
443 return (float)GetValue(CurrentValueProperty);
447 SetValue(CurrentValueProperty, value);
452 /// Gets or sets the size of the thumb image object.
454 /// <since_tizen> 6 </since_tizen>
455 public Size ThumbSize
459 return GetValue(ThumbSizeProperty) as Size;
463 SetValue(ThumbSizeProperty, value);
464 NotifyPropertyChanged();
467 private Size InternalThumbSize
471 return thumbImage?.Size;
475 if (null != thumbImage)
477 thumbImage.Size = value;
484 /// Gets or sets the resource url of the thumb image object.
486 /// Please use ThumbImageUrl property.
488 /// <since_tizen> 6 </since_tizen>
489 public string ThumbImageURL
493 return GetValue(ThumbImageURLProperty) as string;
497 SetValue(ThumbImageURLProperty, value);
498 NotifyPropertyChanged();
501 private string InternalThumbImageURL
505 return thumbImage?.ResourceUrl;
509 if (null != thumbImage)
511 thumbImage.ResourceUrl = value;
512 thumbImageUrl = value;
518 /// Gets or sets the resource url selector of the thumb image object.
519 /// Getter returns copied selector value if exist, null otherwise.
521 /// Please use ThumbImageUrl property.
523 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
524 /// <since_tizen> 6 </since_tizen>
525 public StringSelector ThumbImageURLSelector
529 return GetValue(ThumbImageURLSelectorProperty) as StringSelector;
533 SetValue(ThumbImageURLSelectorProperty, value);
534 NotifyPropertyChanged();
537 private StringSelector InternalThumbImageURLSelector
539 get => thumbImage?.ResourceUrlSelector == null ? null : new StringSelector(thumbImage.ResourceUrlSelector);
542 if (value == null || thumbImage == null)
544 throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
548 thumbImage.ResourceUrlSelector = value;
554 /// Gets or sets the Url of the thumb image.
556 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
557 /// <since_tizen> 9 </since_tizen>
558 public Selector<string> ThumbImageUrl
562 return GetValue(ThumbImageUrlProperty) as Selector<string>;
566 SetValue(ThumbImageUrlProperty, value);
567 NotifyPropertyChanged();
570 private Selector<string> InternalThumbImageUrl
574 if (thumbImage == null)
580 return thumbImage.ResourceUrlSelector;
585 if (value == null || thumbImage == null)
587 throw new NullReferenceException("Slider.ThumbImageUrl is null");
591 thumbImage.ResourceUrlSelector = value;
597 /// Gets or sets the color of the thumb image object.
599 /// <since_tizen> 8 </since_tizen>
600 public Color ThumbColor
604 return GetValue(ThumbColorProperty) as Color;
608 SetValue(ThumbColorProperty, value);
609 NotifyPropertyChanged();
612 private Color InternalThumbColor
620 if (null != thumbImage)
624 if (thumbImage.ResourceUrl != null)
626 thumbImage.ResourceUrl = null;
629 using (PropertyMap map = new PropertyMap())
631 // To remove CA2000 warning messages, use `using` statement.
632 using (PropertyValue type = new PropertyValue((int)Visual.Type.Color))
634 map.Insert((int)Visual.Property.Type, type);
636 using (PropertyValue color = new PropertyValue(thumbColor))
638 map.Insert((int)ColorVisualProperty.MixColor, color);
640 using (PropertyValue radius = new PropertyValue(0.5f))
642 map.Insert((int)Visual.Property.CornerRadius, radius);
644 using (PropertyValue policyType = new PropertyValue((int)VisualTransformPolicyType.Relative))
646 map.Insert((int)Visual.Property.CornerRadiusPolicy, policyType);
648 thumbImage.Image = map;
655 /// Gets or sets the color of the background track image object.
657 /// <since_tizen> 6 </since_tizen>
658 public Color BgTrackColor
662 return GetValue(BgTrackColorProperty) as Color;
666 SetValue(BgTrackColorProperty, value);
667 NotifyPropertyChanged();
670 private Color InternalBgTrackColor
674 return bgTrackImage?.BackgroundColor;
678 if (null != bgTrackImage)
680 bgTrackImage.BackgroundColor = value;
686 /// Gets or sets the color of the slided track image object.
688 /// <since_tizen> 6 </since_tizen>
689 public Color SlidedTrackColor
693 return GetValue(SlidedTrackColorProperty) as Color;
697 SetValue(SlidedTrackColorProperty, value);
698 NotifyPropertyChanged();
701 private Color InternalSlidedTrackColor
705 return slidedTrackImage?.BackgroundColor;
709 if (null != slidedTrackImage)
711 slidedTrackImage.BackgroundColor = value;
717 /// Gets or sets the thickness value of the track.
719 /// <since_tizen> 6 </since_tizen>
720 public uint TrackThickness
724 return (uint)GetValue(TrackThicknessProperty);
728 SetValue(TrackThicknessProperty, value);
733 /// Gets or sets the warning start value between minimum value and maximum value of slider.
735 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
736 [EditorBrowsable(EditorBrowsableState.Never)]
737 public float WarningStartValue
741 return (float)GetValue(WarningStartValueProperty);
745 SetValue(WarningStartValueProperty, value);
746 NotifyPropertyChanged();
749 private float InternalWarningStartValue
753 return warningStartValue;
757 warningStartValue = value;
763 /// Gets or sets the color of the warning track image object.
765 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
766 [EditorBrowsable(EditorBrowsableState.Never)]
767 public Color WarningTrackColor
771 return GetValue(WarningTrackColorProperty) as Color;
775 SetValue(WarningTrackColorProperty, value);
776 NotifyPropertyChanged();
779 private Color InternalWarningTrackColor
783 return warningTrackImage?.BackgroundColor;
787 if (null != warningTrackImage)
789 warningTrackImage.BackgroundColor = value;
795 /// Gets or sets the color of the warning slided track image object.
797 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
798 [EditorBrowsable(EditorBrowsableState.Never)]
799 public Color WarningSlidedTrackColor
803 return GetValue(WarningSlidedTrackColorProperty) as Color;
807 SetValue(WarningSlidedTrackColorProperty, value);
808 NotifyPropertyChanged();
811 private Color InternalWarningSlidedTrackColor
815 return warningSlidedTrackImage?.BackgroundColor;
819 if (null != warningSlidedTrackImage)
821 warningSlidedTrackImage.BackgroundColor = value;
827 /// Gets or sets the Url of the warning thumb image.
829 /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
830 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
831 [EditorBrowsable(EditorBrowsableState.Never)]
832 public Selector<string> WarningThumbImageUrl
836 return GetValue(WarningThumbImageUrlProperty) as Selector<string>;
840 SetValue(WarningThumbImageUrlProperty, value);
841 NotifyPropertyChanged();
844 private Selector<string> InternalWarningThumbImageUrl
848 return warningThumbImageUrlSelector;
852 if (value == null || thumbImage == null)
854 throw new NullReferenceException("Slider.WarningThumbImageUrl is null");
858 warningThumbImageUrlSelector = value;
864 /// Gets or sets the color of the warning thumb image object.
866 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
867 [EditorBrowsable(EditorBrowsableState.Never)]
868 public Color WarningThumbColor
872 return GetValue(WarningThumbColorProperty) as Color;
876 SetValue(WarningThumbColorProperty, value);
877 NotifyPropertyChanged();
880 private Color InternalWarningThumbColor
884 return warningThumbColor;
888 warningThumbColor = value;
893 /// Gets or sets the resource url of the low indicator image object.
895 /// <since_tizen> 6 </since_tizen>
896 public string LowIndicatorImageURL
900 return GetValue(LowIndicatorImageURLProperty) as string;
904 SetValue(LowIndicatorImageURLProperty, value);
905 NotifyPropertyChanged();
908 private string InternalLowIndicatorImageURL
912 return lowIndicatorImage?.ResourceUrl;
916 if (null == lowIndicatorImage)
918 lowIndicatorImage = new ImageView
920 AccessibilityHidden = true,
924 lowIndicatorImage.ResourceUrl = value;
929 /// Gets or sets the resource url of the high indicator image object.
931 /// <since_tizen> 6 </since_tizen>
932 public string HighIndicatorImageURL
936 return GetValue(HighIndicatorImageURLProperty) as string;
940 SetValue(HighIndicatorImageURLProperty, value);
941 NotifyPropertyChanged();
944 private string InternalHighIndicatorImageURL
948 return highIndicatorImage?.ResourceUrl;
952 if (null == highIndicatorImage)
954 highIndicatorImage = new ImageView
956 AccessibilityHidden = true,
960 highIndicatorImage.ResourceUrl = value;
965 /// Gets or sets the text content of the low indicator text object.
967 /// <since_tizen> 6 </since_tizen>
968 public string LowIndicatorTextContent
972 return GetValue(LowIndicatorTextContentProperty) as string;
976 SetValue(LowIndicatorTextContentProperty, value);
977 NotifyPropertyChanged();
980 private string InternalLowIndicatorTextContent
984 return lowIndicatorText?.Text;
988 if (null != lowIndicatorText)
990 lowIndicatorText.Text = value;
996 /// Gets or sets the text content of the high indicator text object.
998 /// <since_tizen> 6 </since_tizen>
999 public string HighIndicatorTextContent
1003 return GetValue(HighIndicatorTextContentProperty) as string;
1007 SetValue(HighIndicatorTextContentProperty, value);
1008 NotifyPropertyChanged();
1011 private string InternalHighIndicatorTextContent
1015 return highIndicatorText?.Text;
1019 if (null != highIndicatorText)
1021 highIndicatorText.Text = value;
1027 /// Gets or sets the size of the low indicator object(image or text).
1029 /// <since_tizen> 6 </since_tizen>
1030 public Size LowIndicatorSize
1034 return GetValue(LowIndicatorSizeProperty) as Size;
1038 SetValue(LowIndicatorSizeProperty, value);
1039 NotifyPropertyChanged();
1042 private Size InternalLowIndicatorSize
1046 return lowIndicatorSize;
1050 lowIndicatorSize = value;
1051 UpdateLowIndicatorSize();
1052 UpdateBgTrackSize();
1053 UpdateBgTrackPosition();
1059 /// Gets or sets the size of the high indicator object(image or text).
1061 /// <since_tizen> 6 </since_tizen>
1062 public Size HighIndicatorSize
1066 return GetValue(HighIndicatorSizeProperty) as Size;
1070 SetValue(HighIndicatorSizeProperty, value);
1071 NotifyPropertyChanged();
1074 private Size InternalHighIndicatorSize
1078 return highIndicatorText?.Size;
1082 if (null != highIndicatorText)
1084 highIndicatorText.Size = value;
1090 /// Gets or sets the value of the space between track and indicator.
1092 /// <since_tizen> 6 </since_tizen>
1093 public uint SpaceBetweenTrackAndIndicator
1097 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
1101 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
1106 /// Flag to decide whether the value indicator is shown
1108 /// <since_tizen> 9 </since_tizen>
1109 public bool IsValueShown
1113 return (bool)GetValue(IsValueShownProperty);
1117 SetValue(IsValueShownProperty, value);
1122 /// Gets or sets the text of value indicator.
1124 /// <since_tizen> 9 </since_tizen>
1125 public string ValueIndicatorText
1129 return (string)GetValue(ValueIndicatorTextProperty);
1133 SetValue(ValueIndicatorTextProperty, value);
1138 /// Gets or sets the size of the value indicator image object.
1140 /// <since_tizen> 9 </since_tizen>
1141 public Size ValueIndicatorSize
1145 return GetValue(ValueIndicatorSizeProperty) as Size;
1149 SetValue(ValueIndicatorSizeProperty, value);
1150 NotifyPropertyChanged();
1153 private Size InternalValueIndicatorSize
1157 return valueIndicatorImage?.Size;
1161 if (null != valueIndicatorImage)
1163 valueIndicatorImage.Size = value;
1169 /// Gets or sets the resource url of the value indicator image object.
1171 /// <since_tizen> 9 </since_tizen>
1172 public string ValueIndicatorUrl
1176 return GetValue(ValueIndicatorUrlProperty) as string;
1180 SetValue(ValueIndicatorUrlProperty, value);
1181 NotifyPropertyChanged();
1184 private string InternalValueIndicatorUrl
1188 return valueIndicatorImage?.ResourceUrl;
1192 if (null != valueIndicatorImage)
1194 valueIndicatorImage.ResourceUrl = value;
1200 /// Flag to decide whether the thumb snaps to the nearest discrete value when the user drags the thumb or taps.
1202 /// The default value is false.
1204 /// <since_tizen> 9 </since_tizen>
1205 public bool IsDiscrete
1209 return (bool)GetValue(IsDiscreteProperty);
1213 SetValue(IsDiscreteProperty, value);
1214 NotifyPropertyChanged();
1217 private bool InternalIsDiscrete { get; set; } = false;
1220 /// Gets or sets the discrete value of slider.
1223 /// The discrete value is evenly spaced between MinValue and MaxValue.
1224 /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
1225 /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
1226 /// The default is 0.
1228 /// <since_tizen> 9 </since_tizen>
1229 public float DiscreteValue
1233 return (float)GetValue(DiscreteValueProperty);
1237 SetValue(DiscreteValueProperty, value);
1238 NotifyPropertyChanged();
1241 private float InternalDiscreteValue
1245 return discreteValue;
1249 discreteValue = value;
1254 private Extents spaceBetweenTrackAndIndicator
1258 if (null == spaceTrackIndicator)
1260 spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
1262 Extents extents = new Extents(start, end, top, bottom);
1263 spaceTrackIndicator.CopyFrom(extents);
1267 return spaceTrackIndicator;
1271 private IndicatorType privateIndicatorType
1275 return indicatorType;
1279 if (indicatorType == value)
1283 indicatorType = value;
1284 RelayoutBaseComponent(false);
1285 UpdateBgTrackSize();
1286 UpdateBgTrackPosition();
1291 private uint privateTrackThickness
1295 return trackThickness ?? 0;
1299 trackThickness = value;
1300 if (bgTrackImage != null)
1302 if (direction == DirectionType.Horizontal)
1304 bgTrackImage.SizeHeight = (float)trackThickness.Value;
1306 else if (direction == DirectionType.Vertical)
1308 bgTrackImage.SizeWidth = (float)trackThickness.Value;
1311 if (slidedTrackImage != null)
1313 if (direction == DirectionType.Horizontal)
1315 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1317 else if (direction == DirectionType.Vertical)
1319 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1322 if (warningTrackImage != null)
1324 if (direction == DirectionType.Horizontal)
1326 warningTrackImage.SizeHeight = (float)trackThickness.Value;
1328 else if (direction == DirectionType.Vertical)
1330 warningTrackImage.SizeWidth = (float)trackThickness.Value;
1333 if (warningSlidedTrackImage != null)
1335 if (direction == DirectionType.Horizontal)
1337 warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1339 else if (direction == DirectionType.Vertical)
1341 warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1347 private uint privateSpaceBetweenTrackAndIndicator
1351 return privateTrackPadding.Start;
1355 ushort val = (ushort)value;
1356 privateTrackPadding = new Extents(val, val, val, val);
1360 private Extents privateTrackPadding
1364 return spaceBetweenTrackAndIndicator;
1368 spaceBetweenTrackAndIndicator.CopyFrom(value);
1369 UpdateComponentByIndicatorTypeChanged();
1370 UpdateBgTrackSize();
1371 UpdateBgTrackPosition();
1377 /// Focus gained callback.
1379 /// <since_tizen> 8 </since_tizen>
1380 public override void OnFocusGained()
1382 //State = ControlStates.Focused;
1383 UpdateState(true, isPressed);
1384 base.OnFocusGained();
1388 /// Focus Lost callback.
1390 /// <since_tizen> 8 </since_tizen>
1391 public override void OnFocusLost()
1393 //State = ControlStates.Normal;
1394 UpdateState(false, isPressed);
1398 private bool editMode = false;
1399 private View recoverIndicator;
1400 private View editModeIndicator;
1403 [EditorBrowsable(EditorBrowsableState.Never)]
1404 public override bool OnKeyboardEnter()
1412 //set editMode false (toggle the mode)
1414 FocusManager.Instance.FocusIndicator = recoverIndicator;
1418 //set editMode true (toggle the mode)
1420 if (editModeIndicator == null)
1422 editModeIndicator = new View()
1424 PositionUsesPivotPoint = true,
1425 PivotPoint = new Position(0, 0, 0),
1426 WidthResizePolicy = ResizePolicyType.FillToParent,
1427 HeightResizePolicy = ResizePolicyType.FillToParent,
1428 BorderlineColor = Color.Red,
1429 BorderlineWidth = 6.0f,
1430 BorderlineOffset = -1f,
1431 BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.4f),
1432 AccessibilityHidden = true,
1435 recoverIndicator = FocusManager.Instance.FocusIndicator;
1436 FocusManager.Instance.FocusIndicator = editModeIndicator;
1442 [EditorBrowsable(EditorBrowsableState.Never)]
1443 public override bool OnKey(Key key)
1445 if (!IsEnabled || null == key)
1450 if (key.State == Key.StateType.Down)
1452 if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Left") ||
1453 (direction == DirectionType.Vertical && key.KeyPressedName == "Down"))
1457 if (MinValue < CurrentValue)
1462 float value = CurrentValue - discreteValue;
1463 CurrentValue = value < MinValue ? MinValue : value;
1470 return true; // Consumed
1473 else if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Right") ||
1474 (direction == DirectionType.Vertical && key.KeyPressedName == "Up"))
1478 if (MaxValue > CurrentValue)
1483 float value = CurrentValue + discreteValue;
1484 CurrentValue = value > MaxValue ? MaxValue : value;
1491 return true; // Consumed
1495 else if (key.State == Key.StateType.Up)
1500 if (key.KeyPressedName == "Up" || key.KeyPressedName == "Right" || key.KeyPressedName == "Down" || key.KeyPressedName == "Left")
1511 /// Apply style to scrollbar.
1513 /// <param name="viewStyle">The style to apply.</param>
1514 /// <since_tizen> 8 </since_tizen>
1515 public override void ApplyStyle(ViewStyle viewStyle)
1517 base.ApplyStyle(viewStyle);
1519 SliderStyle sliderStyle = viewStyle as SliderStyle;
1521 if (null != sliderStyle?.Progress)
1523 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1526 if (null != sliderStyle?.LowIndicator)
1528 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1531 if (null != sliderStyle?.HighIndicator)
1533 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1536 if (null != sliderStyle?.Track)
1538 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1541 if (null != sliderStyle?.Thumb)
1543 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1546 if (null != sliderStyle?.ValueIndicatorText)
1548 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1551 if (null != sliderStyle?.ValueIndicatorImage)
1553 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1556 if (null != sliderStyle?.WarningTrack)
1558 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1561 if (null != sliderStyle?.WarningProgress)
1563 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1566 EnableControlStatePropagation = true;
1570 /// Gets minimum value for Accessibility.
1572 [EditorBrowsable(EditorBrowsableState.Never)]
1573 double IAtspiValue.AccessibilityGetMinimum()
1575 return (double)MinValue;
1579 /// Gets the current value for Accessibility.
1581 [EditorBrowsable(EditorBrowsableState.Never)]
1582 double IAtspiValue.AccessibilityGetCurrent()
1584 return (double)CurrentValue;
1588 /// Gets maximum value for Accessibility.
1590 [EditorBrowsable(EditorBrowsableState.Never)]
1591 double IAtspiValue.AccessibilityGetMaximum()
1593 return (double)MaxValue;
1597 /// Sets the current value using Accessibility.
1599 [EditorBrowsable(EditorBrowsableState.Never)]
1600 bool IAtspiValue.AccessibilitySetCurrent(double value)
1602 var current = (float)value;
1604 if (current >= MinValue && current <= MaxValue)
1606 CurrentValue = current;
1607 if (sliderValueChangedHandler != null)
1609 sliderValueChangedHandler(this, new SliderValueChangedEventArgs { CurrentValue = current });
1618 /// Gets minimum increment for Accessibility.
1620 [EditorBrowsable(EditorBrowsableState.Never)]
1621 double IAtspiValue.AccessibilityGetMinimumIncrement()
1624 return (MaxValue - MinValue) / 20.0;
1628 /// Initialize AT-SPI object.
1630 [EditorBrowsable(EditorBrowsableState.Never)]
1631 public override void OnInitialize()
1633 base.OnInitialize();
1634 AccessibilityRole = Role.Slider;
1638 /// Get Slider style.
1640 /// <returns>The default slider style.</returns>
1641 /// <since_tizen> 8 </since_tizen>
1642 protected override ViewStyle CreateViewStyle()
1644 return new SliderStyle();
1650 /// <param name="type">Dispose type.</param>
1651 /// <since_tizen> 6 </since_tizen>
1652 protected override void Dispose(DisposeTypes type)
1659 if (type == DisposeTypes.Explicit)
1661 if (null != panGestureDetector)
1663 panGestureDetector.Detach(this);
1664 panGestureDetector.Detected -= OnPanGestureDetected;
1665 panGestureDetector.Dispose();
1666 panGestureDetector = null;
1669 if (null != thumbImage)
1671 thumbImage.TouchEvent -= OnTouchEventForThumb;
1672 Utility.Dispose(thumbImage);
1674 Utility.Dispose(warningSlidedTrackImage);
1675 Utility.Dispose(warningTrackImage);
1676 Utility.Dispose(slidedTrackImage);
1677 Utility.Dispose(bgTrackImage);
1678 Utility.Dispose(lowIndicatorImage);
1679 Utility.Dispose(highIndicatorImage);
1680 Utility.Dispose(lowIndicatorText);
1681 Utility.Dispose(highIndicatorText);
1682 Utility.Dispose(valueIndicatorImage);
1683 Utility.Dispose(valueIndicatorText);
1685 this.TouchEvent -= OnTouchEventForTrack;
1687 recoverIndicator = null;
1688 if (editModeIndicator != null)
1690 editModeIndicator.Dispose();
1691 editModeIndicator = null;
1699 /// Update Slider by style.
1701 /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1702 [EditorBrowsable(EditorBrowsableState.Never)]
1703 protected override void OnUpdate()
1705 RelayoutBaseComponent();
1707 UpdateComponentByIndicatorTypeChanged();
1708 UpdateBgTrackSize();
1709 UpdateBgTrackPosition();
1710 UpdateWarningTrackSize();
1711 UpdateLowIndicatorSize();
1716 [EditorBrowsable(EditorBrowsableState.Never)]
1717 protected override void OnEnabled(bool enabled)
1719 base.OnEnabled(enabled);
1723 private void CalculateCurrentValueByGesture(float offset)
1725 currentSlidedOffset += offset;
1727 if (currentSlidedOffset <= 0)
1729 this.CurrentValue = minValue;
1731 else if (currentSlidedOffset >= BgTrackLength())
1733 this.CurrentValue = maxValue;
1737 int bgTrackLength = BgTrackLength();
1738 if (bgTrackLength != 0)
1740 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1746 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1749 if (sliderValueChangedHandler != null)
1751 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1752 args.CurrentValue = this.CurrentValue;
1753 sliderValueChangedHandler(this, args);
1757 private bool OnTouchEventForTrack(object source, TouchEventArgs e)
1764 PointStateType state = e.Touch.GetState(0);
1765 if (state == PointStateType.Down)
1769 valueIndicatorImage.Show();
1772 UpdateState(isFocused, true);
1774 sliderSlidingStartedHandler?.Invoke(this, new SliderSlidingStartedEventArgs {
1775 CurrentValue = curValue
1778 Vector2 pos = e.Touch.GetLocalPosition(0);
1779 CalculateCurrentValueByTouch(pos);
1782 else if (state == PointStateType.Up)
1786 valueIndicatorImage.Hide();
1789 UpdateState(isFocused, false);
1791 sliderSlidingFinishedHandler?.Invoke(this, new SliderSlidingFinishedEventArgs {
1792 CurrentValue = curValue
1798 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1800 PointStateType state = e.Touch.GetState(0);
1801 if (state == PointStateType.Down)
1803 UpdateState(isFocused, true);
1805 else if (state == PointStateType.Up)
1807 UpdateState(isFocused, false);
1812 private void CalculateCurrentValueByTouch(Vector2 pos)
1814 int bgTrackLength = BgTrackLength();
1815 if (direction == DirectionType.Horizontal)
1817 currentSlidedOffset = pos.X;
1819 else if (direction == DirectionType.Vertical)
1821 currentSlidedOffset = bgTrackLength - pos.Y;
1824 if (bgTrackLength != 0)
1826 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1830 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1833 if (null != sliderValueChangedHandler)
1835 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1836 args.CurrentValue = this.CurrentValue;
1837 sliderValueChangedHandler(this, args);
1842 private float CalculateDiscreteValue(float value)
1844 return ((float)Math.Round((value / discreteValue)) * discreteValue);
1847 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1849 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1853 if (thumbImage == null || Style == null)
1857 isFocused = isFocusedNew;
1858 isPressed = isPressedNew;
1860 if (!IsEnabled) // Disabled
1862 ControlState = ControlState.Disabled;
1864 else if (!isFocused && !isPressed)
1866 ControlState = ControlState.Normal;
1870 ControlState = ControlState.Pressed;
1872 else if (!isPressed && isFocused)
1874 ControlState = ControlState.Focused;
1878 private void UpdateComponentByIndicatorTypeChanged()
1880 IndicatorType type = CurrentIndicatorType();
1881 if (type == IndicatorType.None)
1883 if (lowIndicatorImage != null)
1885 lowIndicatorImage.Hide();
1887 if (highIndicatorImage != null)
1889 highIndicatorImage.Hide();
1891 if (lowIndicatorText != null)
1893 lowIndicatorText.Hide();
1895 if (highIndicatorText != null)
1897 highIndicatorText.Hide();
1900 else if (type == IndicatorType.Image)
1902 if (lowIndicatorImage != null)
1904 lowIndicatorImage.Show();
1906 if (highIndicatorImage != null)
1908 highIndicatorImage.Show();
1910 if (lowIndicatorText != null)
1912 lowIndicatorText.Hide();
1914 if (highIndicatorText != null)
1916 highIndicatorText.Hide();
1919 else if (type == IndicatorType.Text)
1921 if (lowIndicatorText != null)
1923 lowIndicatorText.Show();
1925 if (highIndicatorText != null)
1927 highIndicatorText.Show();
1929 if (lowIndicatorImage != null)
1931 lowIndicatorImage.Hide();
1933 if (highIndicatorImage != null)
1935 highIndicatorImage.Hide();