2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Tizen.NUI.BaseComponents;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.Components
25 /// A slider lets users select a value from a continuous or discrete range of values by moving the slider thumb.
27 /// <since_tizen> 6 </since_tizen>
28 public class Slider : Control
30 // the background track image object
31 private ImageView bgTrackImage = null;
32 // the slided track image object
33 private ImageView slidedTrackImage = null;
34 // the thumb image object
35 private ImageView thumbImage = null;
36 // the low indicator image object
37 private ImageView lowIndicatorImage = null;
38 // the high indicator image object
39 private ImageView highIndicatorImage = null;
40 // the low indicator text object
41 private TextLabel lowIndicatorText = null;
42 // the high indicator text object
43 private TextLabel highIndicatorText = null;
45 private DirectionType direction = DirectionType.Horizontal;
47 private IndicatorType indicatorType = IndicatorType.None;
48 private const float round = 0.5f;
50 private float? minValue = null;
52 private float? maxValue = null;
54 private float? curValue = null;
55 // the size of the low indicator
56 private Size lowIndicatorSize = null;
57 // the size of the high indicator
58 private Size highIndicatorSize = null;
59 // the track thickness value
60 private uint? trackThickness = null;
61 // the value of the space between track and indicator object
62 private Extents _spaceBetweenTrackAndIndicator = null;
63 private Extents spaceBetweenTrackAndIndicator
67 if (null == _spaceBetweenTrackAndIndicator)
69 _spaceBetweenTrackAndIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
71 Extents extents = new Extents(start, end, top, bottom);
72 _spaceBetweenTrackAndIndicator.CopyFrom(extents);
76 return _spaceBetweenTrackAndIndicator;
81 private PanGestureDetector panGestureDetector = null;
82 private float currentSlidedOffset;
83 private EventHandler<ValueChangedArgs> valueChangedHandler;
84 private EventHandler<SlidingFinishedArgs> slidingFinishedHandler;
85 private EventHandler<StateChangedArgs> stateChangedHandler;
87 bool isFocused = false;
88 bool isPressed = false;
90 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
91 [EditorBrowsable(EditorBrowsableState.Never)]
92 public static readonly BindableProperty IndicatorTypeProperty = BindableProperty.Create("IndicatorType", typeof(IndicatorType), typeof(Slider), IndicatorType.None, propertyChanged: (bindable, oldValue, newValue) =>
94 var instance = (Slider)bindable;
97 instance.privateIndicatorType = (IndicatorType)newValue;
100 defaultValueCreator: (bindable) =>
102 var instance = (Slider)bindable;
103 return instance.privateIndicatorType;
105 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
106 [EditorBrowsable(EditorBrowsableState.Never)]
107 public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create("SpaceBetweenTrackAndIndicator", typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
109 var instance = (Slider)bindable;
110 if (newValue != null)
112 instance.privateSpaceBetweenTrackAndIndicator = (uint)newValue;
115 defaultValueCreator: (bindable) =>
117 var instance = (Slider)bindable;
118 return instance.privateSpaceBetweenTrackAndIndicator;
120 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
121 [EditorBrowsable(EditorBrowsableState.Never)]
122 public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create("TrackThickness", typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
124 var instance = (Slider)bindable;
125 if (newValue != null)
127 instance.privateTrackThickness = (uint)newValue;
130 defaultValueCreator: (bindable) =>
132 var instance = (Slider)bindable;
133 return instance.privateTrackThickness;
135 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
136 [EditorBrowsable(EditorBrowsableState.Never)]
137 public static readonly BindableProperty TrackPaddingProperty = BindableProperty.Create("TrackPadding", typeof(Extents), typeof(Slider), null, propertyChanged: (bindable, oldValue, newValue) =>
139 var instance = (Slider)bindable;
140 if (newValue != null)
142 instance.privateTrackPadding.CopyFrom((Extents)newValue);
145 defaultValueCreator: (bindable) =>
147 var instance = (Slider)bindable;
148 return instance.privateTrackPadding;
152 /// The constructor of the Slider class.
154 /// <since_tizen> 6 </since_tizen>
161 /// The constructor of the Slider class with specific style.
163 /// <param name="style">The string to initialize the Slider</param>
164 /// <since_tizen> 6 </since_tizen>
165 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
166 [EditorBrowsable(EditorBrowsableState.Never)]
167 public Slider(string style) : base(style)
173 /// The constructor of the Slider class with specific style.
175 /// <param name="style">The style object to initialize the Slider</param>
176 /// <since_tizen> 6 </since_tizen>
177 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
178 [EditorBrowsable(EditorBrowsableState.Never)]
179 public Slider(SliderStyle style) : base(style)
185 /// The value changed event handler.
187 /// <since_tizen> 6 </since_tizen>
188 public event EventHandler<ValueChangedArgs> ValueChangedEvent
192 valueChangedHandler += value;
196 valueChangedHandler -= value;
201 /// The sliding finished event handler.
203 /// <since_tizen> 6 </since_tizen>
204 public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
208 slidingFinishedHandler += value;
212 slidingFinishedHandler -= value;
217 /// The state changed event handler.
219 /// <since_tizen> 6 </since_tizen>
220 public event EventHandler<StateChangedArgs> StateChangedEvent
224 stateChangedHandler += value;
228 stateChangedHandler -= value;
233 /// The direction type of slider.
235 /// <since_tizen> 6 </since_tizen>
236 public enum DirectionType
239 /// The Horizontal type.
241 /// <since_tizen> 6 </since_tizen>
245 /// The Vertical type.
247 /// <since_tizen> 6 </since_tizen>
252 /// The indicator type of slider.
254 /// <since_tizen> 6 </since_tizen>
255 public enum IndicatorType
257 /// <summary> Only contains slider bar.</summary>
258 /// <since_tizen> 6 </since_tizen>
261 /// <summary> Contains slider bar, IndicatorImage.</summary>
262 /// <since_tizen> 6 </since_tizen>
265 /// <summary> Contains slider bar, IndicatorText.</summary>
266 /// <since_tizen> 6 </since_tizen>
270 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
271 [EditorBrowsable(EditorBrowsableState.Never)]
272 public new SliderStyle Style => ViewStyle as SliderStyle;
275 /// Gets or sets the direction type of slider.
277 /// <since_tizen> 6 </since_tizen>
278 public DirectionType Direction
286 if (direction == value)
291 RelayoutBaseComponent(false);
293 UpdateBgTrackPosition();
299 /// Gets or sets the indicator type, arrow or sign.
301 /// <since_tizen> 6 </since_tizen>
302 public IndicatorType Indicator
306 return (IndicatorType)GetValue(IndicatorTypeProperty);
310 SetValue(IndicatorTypeProperty, value);
313 private IndicatorType privateIndicatorType
317 return indicatorType;
321 if (indicatorType == value)
325 indicatorType = value;
326 RelayoutBaseComponent(false);
328 UpdateBgTrackPosition();
334 /// Gets or sets the minimum value of slider.
336 /// <since_tizen> 6 </since_tizen>
337 public float MinValue
341 return minValue ?? 0;
351 /// Gets or sets the maximum value of slider.
353 /// <since_tizen> 6 </since_tizen>
354 public float MaxValue
358 return maxValue ?? 100;
368 /// Gets or sets the current value of slider.
370 /// <since_tizen> 6 </since_tizen>
371 public float CurrentValue
375 return curValue ?? 0;
385 /// Gets or sets the size of the thumb image object.
387 /// <since_tizen> 6 </since_tizen>
388 public Size ThumbSize
392 return Style.Thumb?.Size;
396 Style.Thumb.Size = value;
401 /// Gets or sets the resource url of the thumb image object.
403 /// <since_tizen> 6 </since_tizen>
404 public string ThumbImageURL
408 return Style?.Thumb?.ResourceUrl?.All;
412 if (null != Style?.Thumb)
414 Style.Thumb.ResourceUrl = value;
419 private StringSelector thumbImageURLSelector = new StringSelector();
421 /// Gets or sets the resource url selector of the thumb image object.
423 /// <since_tizen> 6 </since_tizen>
424 public StringSelector ThumbImageURLSelector
428 return thumbImageURLSelector;
432 thumbImageURLSelector.Clone(value);
437 /// Gets or sets the color of the background track image object.
439 /// <since_tizen> 6 </since_tizen>
440 public Color BgTrackColor
444 return Style?.Track?.BackgroundColor?.All;
448 if (null != Style?.Track)
450 Style.Track.BackgroundColor = value;
456 /// Gets or sets the color of the slided track image object.
458 /// <since_tizen> 6 </since_tizen>
459 public Color SlidedTrackColor
463 return Style?.Progress?.BackgroundColor?.All;
467 if (null != Style?.Progress)
469 Style.Progress.BackgroundColor = value;
475 /// Gets or sets the thickness value of the track.
477 /// <since_tizen> 6 </since_tizen>
478 public uint TrackThickness
482 return (uint)GetValue(TrackThicknessProperty);
486 SetValue(TrackThicknessProperty, value);
489 private uint privateTrackThickness
493 return trackThickness ?? 0;
497 trackThickness = value;
498 if (bgTrackImage != null)
500 if (direction == DirectionType.Horizontal)
502 bgTrackImage.SizeHeight = (float)trackThickness.Value;
504 else if (direction == DirectionType.Vertical)
506 bgTrackImage.SizeWidth = (float)trackThickness.Value;
509 if (slidedTrackImage != null)
511 if (direction == DirectionType.Horizontal)
513 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
515 else if (direction == DirectionType.Vertical)
517 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
524 /// Gets or sets the resource url of the low indicator image object.
526 /// <since_tizen> 6 </since_tizen>
527 public string LowIndicatorImageURL
531 return Style?.LowIndicatorImage?.ResourceUrl?.All;
535 if (null != Style?.LowIndicatorImage)
537 Style.LowIndicatorImage.ResourceUrl = value;
543 /// Gets or sets the resource url of the high indicator image object.
545 /// <since_tizen> 6 </since_tizen>
546 public string HighIndicatorImageURL
550 return Style?.HighIndicatorImage?.ResourceUrl?.All;
554 if (null != Style?.HighIndicatorImage)
556 Style.HighIndicatorImage.ResourceUrl = value;
562 /// Gets or sets the text content of the low indicator text object.
564 /// <since_tizen> 6 </since_tizen>
565 public string LowIndicatorTextContent
569 return Style?.LowIndicator?.Text?.All;
573 if (null != Style?.LowIndicator)
575 Style.LowIndicator.Text= value;
581 /// Gets or sets the text content of the high indicator text object.
583 /// <since_tizen> 6 </since_tizen>
584 public string HighIndicatorTextContent
588 return Style?.HighIndicator?.Text?.All;
592 if (null != Style?.HighIndicator)
594 Style.HighIndicator.Text = value;
600 /// Gets or sets the size of the low indicator object(image or text).
602 /// <since_tizen> 6 </since_tizen>
603 public Size LowIndicatorSize
607 return lowIndicatorSize;
611 lowIndicatorSize = value;
612 UpdateLowIndicatorSize();
614 UpdateBgTrackPosition();
620 /// Gets or sets the size of the high indicator object(image or text).
622 /// <since_tizen> 6 </since_tizen>
623 public Size HighIndicatorSize
627 return Style.HighIndicator.Size;
631 Style.HighIndicator.Size = value;
636 /// Gets or sets the value of the space between track and indicator.
638 /// <since_tizen> 6 </since_tizen>
639 public uint SpaceBetweenTrackAndIndicator
643 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
647 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
650 private uint privateSpaceBetweenTrackAndIndicator
654 return TrackPadding.Start;
658 ushort val = (ushort)value;
659 TrackPadding = new Extents(val, val, val, val);
664 /// Gets or sets the value of the space between track and indicator.
666 /// <since_tizen> 6 </since_tizen>
667 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
668 [EditorBrowsable(EditorBrowsableState.Never)]
669 public Extents TrackPadding
673 return (Extents)GetValue(TrackPaddingProperty);
677 SetValue(TrackPaddingProperty, value);
680 private Extents privateTrackPadding
684 return spaceBetweenTrackAndIndicator;
688 spaceBetweenTrackAndIndicator.CopyFrom(value);
689 UpdateComponentByIndicatorTypeChanged();
691 UpdateBgTrackPosition();
697 /// Focus gained callback.
699 /// <since_tizen> 6 </since_tizen>
700 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
701 [EditorBrowsable(EditorBrowsableState.Never)]
702 public override void OnFocusGained()
704 //State = ControlStates.Focused;
705 UpdateState(true, isPressed);
706 base.OnFocusGained();
710 /// Focus Lost callback.
712 /// <since_tizen> 6 </since_tizen>
713 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
714 [EditorBrowsable(EditorBrowsableState.Never)]
715 public override void OnFocusLost()
717 //State = ControlStates.Normal;
718 UpdateState(false, isPressed);
723 /// Get Slider attribues.
725 /// <since_tizen> 6 </since_tizen>
726 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
727 [EditorBrowsable(EditorBrowsableState.Never)]
728 protected override ViewStyle GetViewStyle()
730 return new SliderStyle();
736 /// <param name="type">Dispose type.</param>
737 /// <since_tizen> 6 </since_tizen>
738 protected override void Dispose(DisposeTypes type)
745 if (type == DisposeTypes.Explicit)
747 if (null != panGestureDetector)
749 if (null != thumbImage)
751 panGestureDetector.Detach(thumbImage);
753 panGestureDetector.Detected -= OnPanGestureDetected;
754 panGestureDetector.Dispose();
755 panGestureDetector = null;
758 if (null != thumbImage)
760 thumbImage.TouchEvent -= OnTouchEventForThumb;
761 Utility.Dispose(thumbImage);
763 Utility.Dispose(slidedTrackImage);
764 if (null != bgTrackImage)
766 bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
767 Utility.Dispose(bgTrackImage);
769 Utility.Dispose(lowIndicatorImage);
770 Utility.Dispose(highIndicatorImage);
771 Utility.Dispose(lowIndicatorText);
772 Utility.Dispose(highIndicatorText);
779 /// Update Slider by attributes.
781 /// <since_tizen> 6 </since_tizen>
782 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
783 [EditorBrowsable(EditorBrowsableState.Never)]
784 protected override void OnUpdate()
786 RelayoutBaseComponent();
788 UpdateComponentByIndicatorTypeChanged();
790 UpdateBgTrackPosition();
791 UpdateLowIndicatorSize();
796 /// Theme change callback when theme is changed, this callback will be trigger.
798 /// <param name="sender">serder object</param>
799 /// <param name="e">ThemeChangeEventArgs</param>
800 /// <since_tizen> 6 </since_tizen>
801 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
802 [EditorBrowsable(EditorBrowsableState.Never)]
803 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
805 SliderStyle sliderStyle = StyleManager.Instance.GetAttributes(style) as SliderStyle;
806 if (sliderStyle != null)
808 Style?.CopyFrom(sliderStyle);
813 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
814 [EditorBrowsable(EditorBrowsableState.Never)]
815 public override void ApplyStyle(ViewStyle viewStyle)
817 base.ApplyStyle(viewStyle);
819 SliderStyle sliderStyle = viewStyle as SliderStyle;
821 if (null != sliderStyle.Progress)
823 CreateSlidedTrackAttributes();
826 if (null != sliderStyle.LowIndicator)
828 CreateLowIndicatorTextAttributes();
831 if (null != sliderStyle.HighIndicator)
833 CreateHighIndicatorTextAttributes();
836 if (null != sliderStyle.Track)
838 CreateBackgroundTrackAttributes();
841 if (null != sliderStyle.Thumb)
843 CreateThumbAttributes();
847 private void Initialize()
849 currentSlidedOffset = 0;
852 LayoutDirectionChanged += OnLayoutDirectionChanged;
855 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
860 private void CreateSlidedTrackAttributes()
862 if (null == slidedTrackImage)
864 slidedTrackImage = new ImageView()
866 WidthResizePolicy = ResizePolicyType.Fixed,
867 HeightResizePolicy = ResizePolicyType.Fixed
870 if (bgTrackImage != null)
872 bgTrackImage.Add(slidedTrackImage);
875 if (null != thumbImage)
877 slidedTrackImage.Add(thumbImage);
881 if (null == Style.Progress)
883 Style.Progress = new ImageViewStyle();
886 slidedTrackImage.ApplyStyle(Style.Progress);
889 private void CreateLowIndicatorTextAttributes()
891 if (null == lowIndicatorText)
893 lowIndicatorText = new TextLabel()
895 WidthResizePolicy = ResizePolicyType.Fixed,
896 HeightResizePolicy = ResizePolicyType.Fixed
898 this.Add(lowIndicatorText);
901 if (null == Style.LowIndicator)
903 Style.LowIndicator = new TextLabelStyle();
906 lowIndicatorText.ApplyStyle(Style.LowIndicator);
909 private void CreateHighIndicatorTextAttributes()
911 if (null == highIndicatorText)
913 highIndicatorText = new TextLabel()
915 WidthResizePolicy = ResizePolicyType.Fixed,
916 HeightResizePolicy = ResizePolicyType.Fixed
918 this.Add(highIndicatorText);
921 if (null == Style.HighIndicator)
923 Style.HighIndicator = new TextLabelStyle();
926 highIndicatorText.ApplyStyle(Style.HighIndicator);
929 private void CreateBackgroundTrackAttributes()
931 if (null == bgTrackImage)
933 bgTrackImage = new ImageView()
935 WidthResizePolicy = ResizePolicyType.Fixed,
936 HeightResizePolicy = ResizePolicyType.Fixed,
937 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
938 PivotPoint = Tizen.NUI.PivotPoint.Center,
939 PositionUsesPivotPoint = true
941 this.Add(bgTrackImage);
943 if (null != slidedTrackImage)
945 bgTrackImage.Add(slidedTrackImage);
948 bgTrackImage.TouchEvent += OnTouchEventForBgTrack;
951 if (null == Style.Track)
953 Style.Track = new ImageViewStyle();
956 bgTrackImage.ApplyStyle(Style.Track);
959 private void CreateThumbAttributes()
961 if (null == thumbImage)
963 thumbImage = new ImageView()
965 WidthResizePolicy = ResizePolicyType.Fixed,
966 HeightResizePolicy = ResizePolicyType.Fixed,
967 ParentOrigin = NUI.ParentOrigin.Center,
968 PivotPoint = NUI.PivotPoint.Center,
969 PositionUsesPivotPoint = true
971 if (slidedTrackImage != null)
973 slidedTrackImage.Add(thumbImage);
975 thumbImage.TouchEvent += OnTouchEventForThumb;
977 panGestureDetector = new PanGestureDetector();
978 panGestureDetector.Attach(thumbImage);
979 panGestureDetector.Detected += OnPanGestureDetected;
982 if (null == Style.Thumb)
984 Style.Thumb= new ImageViewStyle();
987 thumbImage.ApplyStyle(Style.Thumb);
990 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
992 if (e.PanGesture.State == Gesture.StateType.Started)
994 if (direction == DirectionType.Horizontal)
996 currentSlidedOffset = slidedTrackImage.SizeWidth;
998 else if (direction == DirectionType.Vertical)
1000 currentSlidedOffset = slidedTrackImage.SizeHeight;
1002 UpdateState(isFocused, true);
1005 if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
1007 if (direction == DirectionType.Horizontal)
1009 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
1011 else if (direction == DirectionType.Vertical)
1013 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
1018 if (e.PanGesture.State == Gesture.StateType.Finished)
1020 if (null != slidingFinishedHandler)
1022 SlidingFinishedArgs args = new SlidingFinishedArgs();
1023 args.CurrentValue = curValue.Value;
1024 slidingFinishedHandler(this, args);
1027 UpdateState(isFocused, false);
1031 // Relayout basic component: track, thumb and indicator
1032 private void RelayoutBaseComponent(bool isInitial = true)
1034 if (direction == DirectionType.Horizontal)
1036 if (slidedTrackImage != null)
1038 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1039 slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
1040 slidedTrackImage.PositionUsesPivotPoint = true;
1042 if (thumbImage != null)
1044 thumbImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
1045 thumbImage.PivotPoint = NUI.PivotPoint.Center;
1046 thumbImage.PositionUsesPivotPoint = true;
1048 if (lowIndicatorImage != null)
1050 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1051 lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
1052 lowIndicatorImage.PositionUsesPivotPoint = true;
1054 if (highIndicatorImage != null)
1056 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
1057 highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
1058 highIndicatorImage.PositionUsesPivotPoint = true;
1060 if (lowIndicatorText != null)
1062 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1063 lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
1064 lowIndicatorText.PositionUsesPivotPoint = true;
1066 if (highIndicatorText != null)
1068 highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1069 highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
1070 highIndicatorText.PositionUsesPivotPoint = true;
1072 if (panGestureDetector != null)
1076 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
1078 panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
1081 else if (direction == DirectionType.Vertical)
1083 if (slidedTrackImage != null)
1085 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1086 slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
1087 slidedTrackImage.PositionUsesPivotPoint = true;
1089 if (thumbImage != null)
1091 thumbImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
1092 thumbImage.PivotPoint = NUI.PivotPoint.Center;
1093 thumbImage.PositionUsesPivotPoint = true;
1095 if (lowIndicatorImage != null)
1097 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1098 lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
1099 lowIndicatorImage.PositionUsesPivotPoint = true;
1101 if (highIndicatorImage != null)
1103 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
1104 highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
1105 highIndicatorImage.PositionUsesPivotPoint = true;
1107 if (lowIndicatorText != null)
1109 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1110 lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
1111 lowIndicatorText.PositionUsesPivotPoint = true;
1113 if (highIndicatorText != null)
1115 highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
1116 highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
1117 highIndicatorText.PositionUsesPivotPoint = true;
1119 if (panGestureDetector != null)
1123 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
1125 panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
1130 private int BgTrackLength()
1132 int bgTrackLength = 0;
1133 IndicatorType type = CurrentIndicatorType();
1135 if (type == IndicatorType.None)
1137 if (direction == DirectionType.Horizontal)
1139 bgTrackLength = this.Size2D.Width;
1141 else if (direction == DirectionType.Vertical)
1143 bgTrackLength = this.Size2D.Height;
1146 else if (type == IndicatorType.Image)
1147 {// <lowIndicatorImage> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage>
1148 Size lowIndicatorImageSize = LowIndicatorImageSize();
1149 Size highIndicatorImageSize = HighIndicatorImageSize();
1150 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1151 if (direction == DirectionType.Horizontal)
1153 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
1154 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
1155 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
1157 else if (direction == DirectionType.Vertical)
1159 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
1160 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
1161 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
1164 else if (type == IndicatorType.Text)
1165 {// <lowIndicatorText> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorText>
1166 Size lowIndicatorTextSize = LowIndicatorTextSize();
1167 Size highIndicatorTextSize = HighIndicatorTextSize();
1168 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1169 if (direction == DirectionType.Horizontal)
1171 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
1172 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
1173 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
1175 else if (direction == DirectionType.Vertical)
1177 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
1178 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
1179 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
1182 return bgTrackLength;
1185 private void UpdateLowIndicatorSize()
1187 if (lowIndicatorSize != null)
1189 if (lowIndicatorImage != null)
1191 lowIndicatorImage.Size = lowIndicatorSize;
1193 if (lowIndicatorText != null)
1195 lowIndicatorText.Size = lowIndicatorSize;
1200 if (lowIndicatorImage != null && Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null)
1202 lowIndicatorImage.Size = Style.LowIndicatorImage.Size;
1204 if (lowIndicatorText != null && Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null)
1206 lowIndicatorText.Size = Style.LowIndicator.Size;
1211 private void UpdateBgTrackSize()
1213 if(bgTrackImage == null)
1217 int curTrackThickness = (int)CurrentTrackThickness();
1218 int bgTrackLength = BgTrackLength();
1219 if (direction == DirectionType.Horizontal)
1221 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
1223 else if (direction == DirectionType.Vertical)
1225 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
1229 private void UpdateBgTrackPosition()
1231 if (bgTrackImage == null)
1235 IndicatorType type = CurrentIndicatorType();
1237 if (type == IndicatorType.None)
1239 bgTrackImage.Position2D = new Position2D(0, 0);
1241 else if (type == IndicatorType.Image)
1243 Size lowIndicatorImageSize = LowIndicatorImageSize();
1244 Size highIndicatorImageSize = HighIndicatorImageSize();
1245 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1246 if (direction == DirectionType.Horizontal)
1248 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
1249 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
1250 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
1252 else if (direction == DirectionType.Vertical)
1254 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
1255 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
1256 bgTrackImage.Position2D = new Position2D(0, lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2);
1259 else if (type == IndicatorType.Text)
1261 Size lowIndicatorTextSize = LowIndicatorTextSize();
1262 Size highIndicatorTextSize = HighIndicatorTextSize();
1263 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1264 if (direction == DirectionType.Horizontal)
1266 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
1267 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
1268 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
1270 else if (direction == DirectionType.Vertical)
1272 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
1273 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
1274 bgTrackImage.Position2D = new Position2D(0, -(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2));
1279 private void UpdateValue()
1281 if (slidedTrackImage == null || curValue == null || minValue == null || maxValue == null)
1285 if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
1291 ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
1293 uint curTrackThickness = CurrentTrackThickness();
1295 if (direction == DirectionType.Horizontal)
1297 if (LayoutDirection == ViewLayoutDirectionType.RTL)
1299 ratio = 1.0f - ratio;
1301 float slidedTrackLength = (float)BgTrackLength() * ratio;
1302 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
1304 else if (direction == DirectionType.Vertical)
1306 float slidedTrackLength = (float)BgTrackLength() * ratio;
1307 slidedTrackImage.Size2D = new Size2D((int)(curTrackThickness + round), (int)slidedTrackLength); //Add const round to reach Math.Round function.
1311 private uint CurrentTrackThickness()
1313 uint curTrackThickness = 0;
1314 if (trackThickness != null)
1316 curTrackThickness = trackThickness.Value;
1320 if (Style != null && Style.TrackThickness != null)
1322 curTrackThickness = Style.TrackThickness.Value;
1325 return curTrackThickness;
1328 private uint CurrentSpaceBetweenTrackAndIndicator()
1331 if (spaceBetweenTrackAndIndicator != null)
1333 curSpace = spaceBetweenTrackAndIndicator.Start;
1337 if (Style != null && Style.TrackPadding != null)
1339 curSpace = Style.TrackPadding.Start;
1345 private IndicatorType CurrentIndicatorType()
1347 IndicatorType type = IndicatorType.None;
1350 type = (IndicatorType)Style.IndicatorType;
1355 private Size LowIndicatorImageSize()
1357 Size size = new Size(0, 0);
1358 if (lowIndicatorSize != null)
1360 size = lowIndicatorSize;
1364 if (Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null)
1366 size = Style.LowIndicatorImage.Size;
1372 private Size HighIndicatorImageSize()
1374 Size size = new Size(0, 0);
1375 if (highIndicatorSize != null)
1377 size = highIndicatorSize;
1381 if (Style != null && Style.HighIndicatorImage!= null && Style.HighIndicatorImage.Size != null)
1383 size = Style.HighIndicatorImage.Size;
1389 private Size LowIndicatorTextSize()
1391 Size size = new Size(0, 0);
1392 if (lowIndicatorSize != null)
1394 size = lowIndicatorSize;
1398 if (Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null)
1400 size = Style.LowIndicator.Size;
1406 private Size HighIndicatorTextSize()
1408 Size size = new Size(0, 0);
1409 if (highIndicatorSize != null)
1411 size = highIndicatorSize;
1415 if (Style != null && Style.HighIndicator!= null && Style.HighIndicator.Size != null)
1417 size = Style.HighIndicator.Size;
1423 private void CalculateCurrentValueByGesture(float offset)
1425 currentSlidedOffset += offset;
1427 if (currentSlidedOffset <= 0)
1429 curValue = minValue;
1431 else if (currentSlidedOffset >= BgTrackLength())
1433 curValue = maxValue;
1437 int bgTrackLength = BgTrackLength();
1438 if (bgTrackLength != 0)
1440 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1443 if (valueChangedHandler != null)
1445 ValueChangedArgs args = new ValueChangedArgs();
1446 args.CurrentValue = curValue.Value;
1447 valueChangedHandler(this, args);
1451 private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
1453 PointStateType state = e.Touch.GetState(0);
1454 if (state == PointStateType.Down)
1456 Vector2 pos = e.Touch.GetLocalPosition(0);
1457 CalculateCurrentValueByTouch(pos);
1459 if (null != slidingFinishedHandler)
1461 SlidingFinishedArgs args = new SlidingFinishedArgs();
1462 args.CurrentValue = curValue.Value;
1463 slidingFinishedHandler(this, args);
1469 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1471 PointStateType state = e.Touch.GetState(0);
1472 if (state == PointStateType.Down)
1474 UpdateState(isFocused, true);
1476 else if (state == PointStateType.Up)
1478 UpdateState(isFocused, false);
1483 private void CalculateCurrentValueByTouch(Vector2 pos)
1485 int bgTrackLength = BgTrackLength();
1486 if (direction == DirectionType.Horizontal)
1488 currentSlidedOffset = pos.X;
1490 else if (direction == DirectionType.Vertical)
1492 currentSlidedOffset = bgTrackLength - pos.Y;
1494 if (bgTrackLength != 0)
1496 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1497 if (null != valueChangedHandler)
1499 ValueChangedArgs args = new ValueChangedArgs();
1500 args.CurrentValue = curValue.Value;
1501 valueChangedHandler(this, args);
1506 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1508 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1512 if (thumbImage == null || Style == null)
1516 isFocused = isFocusedNew;
1517 isPressed = isPressedNew;
1519 if (!isFocused && !isPressed)
1521 ControlState = ControlStates.Normal;
1522 if (stateChangedHandler != null)
1524 StateChangedArgs args = new StateChangedArgs();
1525 args.CurrentState = (ControlStates)ControlStates.Normal;
1526 stateChangedHandler(this, args);
1531 ControlState = ControlStates.Pressed;
1533 if (stateChangedHandler != null)
1535 StateChangedArgs args = new StateChangedArgs();
1536 args.CurrentState = (ControlStates)ControlStates.Pressed;
1537 stateChangedHandler(this, args);
1540 else if (!isPressed && isFocused)
1542 ControlState = ControlStates.Focused;
1544 if (stateChangedHandler != null)
1546 StateChangedArgs args = new StateChangedArgs();
1547 args.CurrentState = (ControlStates)ControlStates.Focused;
1548 stateChangedHandler(this, args);
1553 private void UpdateComponentByIndicatorTypeChanged()
1555 IndicatorType type = CurrentIndicatorType();
1556 if (type == IndicatorType.None)
1558 if (lowIndicatorImage != null)
1560 lowIndicatorImage.Hide();
1562 if (highIndicatorImage != null)
1564 highIndicatorImage.Hide();
1566 if (lowIndicatorText != null)
1568 lowIndicatorText.Hide();
1570 if (highIndicatorText != null)
1572 highIndicatorText.Hide();
1575 else if (type == IndicatorType.Image)
1577 if (lowIndicatorImage != null)
1579 lowIndicatorImage.Show();
1581 if (highIndicatorImage != null)
1583 highIndicatorImage.Show();
1585 if (lowIndicatorText != null)
1587 lowIndicatorText.Hide();
1589 if (highIndicatorText != null)
1591 highIndicatorText.Hide();
1594 else if (type == IndicatorType.Text)
1596 if (lowIndicatorText != null)
1598 lowIndicatorText.Show();
1600 if (highIndicatorText != null)
1602 highIndicatorText.Show();
1604 if (lowIndicatorImage != null)
1606 lowIndicatorImage.Hide();
1608 if (highIndicatorImage != null)
1610 highIndicatorImage.Hide();
1616 /// Value Changed event data.
1618 /// <since_tizen> 6 </since_tizen>
1619 public class ValueChangedArgs : EventArgs
1624 /// <since_tizen> 6 </since_tizen>
1625 public float CurrentValue;
1629 /// Value Changed event data.
1631 /// <since_tizen> 6 </since_tizen>
1632 public class SlidingFinishedArgs : EventArgs
1637 /// <since_tizen> 6 </since_tizen>
1638 public float CurrentValue;
1642 /// State Changed event data.
1644 /// <since_tizen> 6 </since_tizen>
1645 public class StateChangedArgs : EventArgs
1650 /// <since_tizen> 6 </since_tizen>
1651 public ControlStates CurrentState;