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(nameof(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(nameof(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(nameof(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;
153 /// The constructor of the Slider class.
155 /// <since_tizen> 6 </since_tizen>
162 /// The constructor of the Slider class with specific style.
164 /// <param name="style">The string to initialize the Slider</param>
165 /// <since_tizen> 6 </since_tizen>
166 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public Slider(string style) : base(style)
174 /// The constructor of the Slider class with specific style.
176 /// <param name="style">The style object to initialize the Slider</param>
177 /// <since_tizen> 6 </since_tizen>
178 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
179 [EditorBrowsable(EditorBrowsableState.Never)]
180 public Slider(SliderStyle style) : base(style)
186 /// The value changed event handler.
188 /// <since_tizen> 6 </since_tizen>
189 public event EventHandler<ValueChangedArgs> ValueChangedEvent
193 valueChangedHandler += value;
197 valueChangedHandler -= value;
202 /// The sliding finished event handler.
204 /// <since_tizen> 6 </since_tizen>
205 public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
209 slidingFinishedHandler += value;
213 slidingFinishedHandler -= value;
218 /// The state changed event handler.
220 /// <since_tizen> 6 </since_tizen>
221 public event EventHandler<StateChangedArgs> StateChangedEvent
225 stateChangedHandler += value;
229 stateChangedHandler -= value;
234 /// The direction type of slider.
236 /// <since_tizen> 6 </since_tizen>
237 public enum DirectionType
240 /// The Horizontal type.
242 /// <since_tizen> 6 </since_tizen>
246 /// The Vertical type.
248 /// <since_tizen> 6 </since_tizen>
253 /// The indicator type of slider.
255 /// <since_tizen> 6 </since_tizen>
256 public enum IndicatorType
258 /// <summary> Only contains slider bar.</summary>
259 /// <since_tizen> 6 </since_tizen>
262 /// <summary> Contains slider bar, IndicatorImage.</summary>
263 /// <since_tizen> 6 </since_tizen>
266 /// <summary> Contains slider bar, IndicatorText.</summary>
267 /// <since_tizen> 6 </since_tizen>
271 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
272 [EditorBrowsable(EditorBrowsableState.Never)]
273 public new SliderStyle Style => ViewStyle as SliderStyle;
276 /// Gets or sets the direction type of slider.
278 /// <since_tizen> 6 </since_tizen>
279 public DirectionType Direction
287 if (direction == value)
292 RelayoutBaseComponent(false);
294 UpdateBgTrackPosition();
300 /// Gets or sets the indicator type, arrow or sign.
302 /// <since_tizen> 6 </since_tizen>
303 public IndicatorType Indicator
307 return (IndicatorType)GetValue(IndicatorTypeProperty);
311 SetValue(IndicatorTypeProperty, value);
314 private IndicatorType privateIndicatorType
318 return indicatorType;
322 if (indicatorType == value)
326 indicatorType = value;
327 RelayoutBaseComponent(false);
329 UpdateBgTrackPosition();
335 /// Gets or sets the minimum value of slider.
337 /// <since_tizen> 6 </since_tizen>
338 public float MinValue
342 return minValue ?? 0;
352 /// Gets or sets the maximum value of slider.
354 /// <since_tizen> 6 </since_tizen>
355 public float MaxValue
359 return maxValue ?? 100;
369 /// Gets or sets the current value of slider.
371 /// <since_tizen> 6 </since_tizen>
372 public float CurrentValue
376 return curValue ?? 0;
386 /// Gets or sets the size of the thumb image object.
388 /// <since_tizen> 6 </since_tizen>
389 public Size ThumbSize
393 return Style.Thumb?.Size;
397 Style.Thumb.Size = value;
402 /// Gets or sets the resource url of the thumb image object.
404 /// <since_tizen> 6 </since_tizen>
405 public string ThumbImageURL
409 return Style?.Thumb?.ResourceUrl?.All;
413 if (null != Style?.Thumb)
415 Style.Thumb.ResourceUrl = value;
420 private StringSelector thumbImageURLSelector = new StringSelector();
422 /// Gets or sets the resource url selector of the thumb image object.
424 /// <since_tizen> 6 </since_tizen>
425 public StringSelector ThumbImageURLSelector
429 return thumbImageURLSelector;
433 thumbImageURLSelector.Clone(value);
438 /// Gets or sets the color of the background track image object.
440 /// <since_tizen> 6 </since_tizen>
441 public Color BgTrackColor
445 return Style?.Track?.BackgroundColor?.All;
449 if (null != Style?.Track)
451 Style.Track.BackgroundColor = value;
457 /// Gets or sets the color of the slided track image object.
459 /// <since_tizen> 6 </since_tizen>
460 public Color SlidedTrackColor
464 return Style?.Progress?.BackgroundColor?.All;
468 if (null != Style?.Progress)
470 Style.Progress.BackgroundColor = value;
476 /// Gets or sets the thickness value of the track.
478 /// <since_tizen> 6 </since_tizen>
479 public uint TrackThickness
483 return (uint)GetValue(TrackThicknessProperty);
487 SetValue(TrackThicknessProperty, value);
490 private uint privateTrackThickness
494 return trackThickness ?? 0;
498 trackThickness = value;
499 if (bgTrackImage != null)
501 if (direction == DirectionType.Horizontal)
503 bgTrackImage.SizeHeight = (float)trackThickness.Value;
505 else if (direction == DirectionType.Vertical)
507 bgTrackImage.SizeWidth = (float)trackThickness.Value;
510 if (slidedTrackImage != null)
512 if (direction == DirectionType.Horizontal)
514 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
516 else if (direction == DirectionType.Vertical)
518 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
525 /// Gets or sets the resource url of the low indicator image object.
527 /// <since_tizen> 6 </since_tizen>
528 public string LowIndicatorImageURL
532 return Style?.LowIndicatorImage?.ResourceUrl?.All;
536 if (null != Style?.LowIndicatorImage)
538 Style.LowIndicatorImage.ResourceUrl = value;
544 /// Gets or sets the resource url of the high indicator image object.
546 /// <since_tizen> 6 </since_tizen>
547 public string HighIndicatorImageURL
551 return Style?.HighIndicatorImage?.ResourceUrl?.All;
555 if (null != Style?.HighIndicatorImage)
557 Style.HighIndicatorImage.ResourceUrl = value;
563 /// Gets or sets the text content of the low indicator text object.
565 /// <since_tizen> 6 </since_tizen>
566 public string LowIndicatorTextContent
570 return Style?.LowIndicator?.Text?.All;
574 if (null != Style?.LowIndicator)
576 Style.LowIndicator.Text= value;
582 /// Gets or sets the text content of the high indicator text object.
584 /// <since_tizen> 6 </since_tizen>
585 public string HighIndicatorTextContent
589 return Style?.HighIndicator?.Text?.All;
593 if (null != Style?.HighIndicator)
595 Style.HighIndicator.Text = value;
601 /// Gets or sets the size of the low indicator object(image or text).
603 /// <since_tizen> 6 </since_tizen>
604 public Size LowIndicatorSize
608 return lowIndicatorSize;
612 lowIndicatorSize = value;
613 UpdateLowIndicatorSize();
615 UpdateBgTrackPosition();
621 /// Gets or sets the size of the high indicator object(image or text).
623 /// <since_tizen> 6 </since_tizen>
624 public Size HighIndicatorSize
628 return Style.HighIndicator.Size;
632 Style.HighIndicator.Size = value;
637 /// Gets or sets the value of the space between track and indicator.
639 /// <since_tizen> 6 </since_tizen>
640 public uint SpaceBetweenTrackAndIndicator
644 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
648 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
651 private uint privateSpaceBetweenTrackAndIndicator
655 return TrackPadding.Start;
659 ushort val = (ushort)value;
660 TrackPadding = new Extents(val, val, val, val);
665 /// Gets or sets the value of the space between track and indicator.
667 /// <since_tizen> 6 </since_tizen>
668 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
669 [EditorBrowsable(EditorBrowsableState.Never)]
670 public Extents TrackPadding
674 return (Extents)GetValue(TrackPaddingProperty);
678 SetValue(TrackPaddingProperty, value);
681 private Extents privateTrackPadding
685 return spaceBetweenTrackAndIndicator;
689 spaceBetweenTrackAndIndicator.CopyFrom(value);
690 UpdateComponentByIndicatorTypeChanged();
692 UpdateBgTrackPosition();
698 /// Focus gained callback.
700 /// <since_tizen> 6 </since_tizen>
701 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
702 [EditorBrowsable(EditorBrowsableState.Never)]
703 public override void OnFocusGained()
705 //State = ControlStates.Focused;
706 UpdateState(true, isPressed);
707 base.OnFocusGained();
711 /// Focus Lost callback.
713 /// <since_tizen> 6 </since_tizen>
714 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
715 [EditorBrowsable(EditorBrowsableState.Never)]
716 public override void OnFocusLost()
718 //State = ControlStates.Normal;
719 UpdateState(false, isPressed);
724 /// Get Slider attribues.
726 /// <since_tizen> 6 </since_tizen>
727 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
728 [EditorBrowsable(EditorBrowsableState.Never)]
729 protected override ViewStyle GetViewStyle()
731 return new SliderStyle();
737 /// <param name="type">Dispose type.</param>
738 /// <since_tizen> 6 </since_tizen>
739 protected override void Dispose(DisposeTypes type)
746 if (type == DisposeTypes.Explicit)
748 if (null != panGestureDetector)
750 if (null != thumbImage)
752 panGestureDetector.Detach(thumbImage);
754 panGestureDetector.Detected -= OnPanGestureDetected;
755 panGestureDetector.Dispose();
756 panGestureDetector = null;
759 if (null != thumbImage)
761 thumbImage.TouchEvent -= OnTouchEventForThumb;
762 Utility.Dispose(thumbImage);
764 Utility.Dispose(slidedTrackImage);
765 if (null != bgTrackImage)
767 bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
768 Utility.Dispose(bgTrackImage);
770 Utility.Dispose(lowIndicatorImage);
771 Utility.Dispose(highIndicatorImage);
772 Utility.Dispose(lowIndicatorText);
773 Utility.Dispose(highIndicatorText);
780 /// Update Slider by attributes.
782 /// <since_tizen> 6 </since_tizen>
783 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
784 [EditorBrowsable(EditorBrowsableState.Never)]
785 protected override void OnUpdate()
787 RelayoutBaseComponent();
789 UpdateComponentByIndicatorTypeChanged();
791 UpdateBgTrackPosition();
792 UpdateLowIndicatorSize();
797 /// Theme change callback when theme is changed, this callback will be trigger.
799 /// <param name="sender">serder object</param>
800 /// <param name="e">ThemeChangeEventArgs</param>
801 /// <since_tizen> 6 </since_tizen>
802 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
803 [EditorBrowsable(EditorBrowsableState.Never)]
804 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
806 SliderStyle sliderStyle = StyleManager.Instance.GetViewStyle(style) as SliderStyle;
807 if (sliderStyle != null)
809 Style?.CopyFrom(sliderStyle);
814 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
815 [EditorBrowsable(EditorBrowsableState.Never)]
816 public override void ApplyStyle(ViewStyle viewStyle)
818 base.ApplyStyle(viewStyle);
820 SliderStyle sliderStyle = viewStyle as SliderStyle;
822 if (null != sliderStyle?.Progress)
824 CreateSlidedTrackAttributes();
827 if (null != sliderStyle?.LowIndicator)
829 CreateLowIndicatorTextAttributes();
832 if (null != sliderStyle?.HighIndicator)
834 CreateHighIndicatorTextAttributes();
837 if (null != sliderStyle?.Track)
839 CreateBackgroundTrackAttributes();
842 if (null != sliderStyle?.Thumb)
844 CreateThumbAttributes();
848 private void Initialize()
850 currentSlidedOffset = 0;
853 LayoutDirectionChanged += OnLayoutDirectionChanged;
856 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
861 private void CreateSlidedTrackAttributes()
863 if (null == slidedTrackImage)
865 slidedTrackImage = new ImageView()
867 WidthResizePolicy = ResizePolicyType.Fixed,
868 HeightResizePolicy = ResizePolicyType.Fixed
871 if (bgTrackImage != null)
873 bgTrackImage.Add(slidedTrackImage);
876 if (null != thumbImage)
878 slidedTrackImage.Add(thumbImage);
882 if (null == Style.Progress)
884 Style.Progress = new ImageViewStyle();
887 slidedTrackImage.ApplyStyle(Style.Progress);
890 private void CreateLowIndicatorTextAttributes()
892 if (null == lowIndicatorText)
894 lowIndicatorText = new TextLabel()
896 WidthResizePolicy = ResizePolicyType.Fixed,
897 HeightResizePolicy = ResizePolicyType.Fixed
899 this.Add(lowIndicatorText);
902 if (null == Style.LowIndicator)
904 Style.LowIndicator = new TextLabelStyle();
907 lowIndicatorText.ApplyStyle(Style.LowIndicator);
910 private void CreateHighIndicatorTextAttributes()
912 if (null == highIndicatorText)
914 highIndicatorText = new TextLabel()
916 WidthResizePolicy = ResizePolicyType.Fixed,
917 HeightResizePolicy = ResizePolicyType.Fixed
919 this.Add(highIndicatorText);
922 if (null == Style.HighIndicator)
924 Style.HighIndicator = new TextLabelStyle();
927 highIndicatorText.ApplyStyle(Style.HighIndicator);
930 private void CreateBackgroundTrackAttributes()
932 if (null == bgTrackImage)
934 bgTrackImage = new ImageView()
936 WidthResizePolicy = ResizePolicyType.Fixed,
937 HeightResizePolicy = ResizePolicyType.Fixed,
938 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
939 PivotPoint = Tizen.NUI.PivotPoint.Center,
940 PositionUsesPivotPoint = true
942 this.Add(bgTrackImage);
944 if (null != slidedTrackImage)
946 bgTrackImage.Add(slidedTrackImage);
949 bgTrackImage.TouchEvent += OnTouchEventForBgTrack;
952 if (null == Style.Track)
954 Style.Track = new ImageViewStyle();
957 bgTrackImage.ApplyStyle(Style.Track);
960 private void CreateThumbAttributes()
962 if (null == thumbImage)
964 thumbImage = new ImageView()
966 WidthResizePolicy = ResizePolicyType.Fixed,
967 HeightResizePolicy = ResizePolicyType.Fixed,
968 ParentOrigin = NUI.ParentOrigin.Center,
969 PivotPoint = NUI.PivotPoint.Center,
970 PositionUsesPivotPoint = true
972 if (slidedTrackImage != null)
974 slidedTrackImage.Add(thumbImage);
976 thumbImage.TouchEvent += OnTouchEventForThumb;
978 panGestureDetector = new PanGestureDetector();
979 panGestureDetector.Attach(thumbImage);
980 panGestureDetector.Detected += OnPanGestureDetected;
983 if (null == Style.Thumb)
985 Style.Thumb= new ImageViewStyle();
988 thumbImage.ApplyStyle(Style.Thumb);
991 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
993 if (e.PanGesture.State == Gesture.StateType.Started)
995 if (direction == DirectionType.Horizontal)
997 currentSlidedOffset = slidedTrackImage.SizeWidth;
999 else if (direction == DirectionType.Vertical)
1001 currentSlidedOffset = slidedTrackImage.SizeHeight;
1003 UpdateState(isFocused, true);
1006 if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
1008 if (direction == DirectionType.Horizontal)
1010 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
1012 else if (direction == DirectionType.Vertical)
1014 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
1019 if (e.PanGesture.State == Gesture.StateType.Finished)
1021 if (null != slidingFinishedHandler)
1023 SlidingFinishedArgs args = new SlidingFinishedArgs();
1024 args.CurrentValue = curValue.Value;
1025 slidingFinishedHandler(this, args);
1028 UpdateState(isFocused, false);
1032 // Relayout basic component: track, thumb and indicator
1033 private void RelayoutBaseComponent(bool isInitial = true)
1035 if (direction == DirectionType.Horizontal)
1037 if (slidedTrackImage != null)
1039 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1040 slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
1041 slidedTrackImage.PositionUsesPivotPoint = true;
1043 if (thumbImage != null)
1045 thumbImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
1046 thumbImage.PivotPoint = NUI.PivotPoint.Center;
1047 thumbImage.PositionUsesPivotPoint = true;
1049 if (lowIndicatorImage != null)
1051 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1052 lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
1053 lowIndicatorImage.PositionUsesPivotPoint = true;
1055 if (highIndicatorImage != null)
1057 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
1058 highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
1059 highIndicatorImage.PositionUsesPivotPoint = true;
1061 if (lowIndicatorText != null)
1063 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1064 lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
1065 lowIndicatorText.PositionUsesPivotPoint = true;
1067 if (highIndicatorText != null)
1069 highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1070 highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
1071 highIndicatorText.PositionUsesPivotPoint = true;
1073 if (panGestureDetector != null)
1077 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
1079 panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
1082 else if (direction == DirectionType.Vertical)
1084 if (slidedTrackImage != null)
1086 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1087 slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
1088 slidedTrackImage.PositionUsesPivotPoint = true;
1090 if (thumbImage != null)
1092 thumbImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
1093 thumbImage.PivotPoint = NUI.PivotPoint.Center;
1094 thumbImage.PositionUsesPivotPoint = true;
1096 if (lowIndicatorImage != null)
1098 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1099 lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
1100 lowIndicatorImage.PositionUsesPivotPoint = true;
1102 if (highIndicatorImage != null)
1104 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
1105 highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
1106 highIndicatorImage.PositionUsesPivotPoint = true;
1108 if (lowIndicatorText != null)
1110 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1111 lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
1112 lowIndicatorText.PositionUsesPivotPoint = true;
1114 if (highIndicatorText != null)
1116 highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
1117 highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
1118 highIndicatorText.PositionUsesPivotPoint = true;
1120 if (panGestureDetector != null)
1124 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
1126 panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
1131 private int BgTrackLength()
1133 int bgTrackLength = 0;
1134 IndicatorType type = CurrentIndicatorType();
1136 if (type == IndicatorType.None)
1138 if (direction == DirectionType.Horizontal)
1140 bgTrackLength = this.Size2D.Width;
1142 else if (direction == DirectionType.Vertical)
1144 bgTrackLength = this.Size2D.Height;
1147 else if (type == IndicatorType.Image)
1148 {// <lowIndicatorImage> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage>
1149 Size lowIndicatorImageSize = LowIndicatorImageSize();
1150 Size highIndicatorImageSize = HighIndicatorImageSize();
1151 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1152 if (direction == DirectionType.Horizontal)
1154 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
1155 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
1156 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
1158 else if (direction == DirectionType.Vertical)
1160 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
1161 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
1162 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
1165 else if (type == IndicatorType.Text)
1166 {// <lowIndicatorText> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorText>
1167 Size lowIndicatorTextSize = LowIndicatorTextSize();
1168 Size highIndicatorTextSize = HighIndicatorTextSize();
1169 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1170 if (direction == DirectionType.Horizontal)
1172 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
1173 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
1174 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
1176 else if (direction == DirectionType.Vertical)
1178 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
1179 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
1180 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
1183 return bgTrackLength;
1186 private void UpdateLowIndicatorSize()
1188 if (lowIndicatorSize != null)
1190 if (lowIndicatorImage != null)
1192 lowIndicatorImage.Size = lowIndicatorSize;
1194 if (lowIndicatorText != null)
1196 lowIndicatorText.Size = lowIndicatorSize;
1201 if (lowIndicatorImage != null && Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null)
1203 lowIndicatorImage.Size = Style.LowIndicatorImage.Size;
1205 if (lowIndicatorText != null && Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null)
1207 lowIndicatorText.Size = Style.LowIndicator.Size;
1212 private void UpdateBgTrackSize()
1214 if(bgTrackImage == null)
1218 int curTrackThickness = (int)CurrentTrackThickness();
1219 int bgTrackLength = BgTrackLength();
1220 if (direction == DirectionType.Horizontal)
1222 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
1224 else if (direction == DirectionType.Vertical)
1226 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
1230 private void UpdateBgTrackPosition()
1232 if (bgTrackImage == null)
1236 IndicatorType type = CurrentIndicatorType();
1238 if (type == IndicatorType.None)
1240 bgTrackImage.Position2D = new Position2D(0, 0);
1242 else if (type == IndicatorType.Image)
1244 Size lowIndicatorImageSize = LowIndicatorImageSize();
1245 Size highIndicatorImageSize = HighIndicatorImageSize();
1246 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1247 if (direction == DirectionType.Horizontal)
1249 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
1250 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
1251 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
1253 else if (direction == DirectionType.Vertical)
1255 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
1256 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
1257 bgTrackImage.Position2D = new Position2D(0, lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2);
1260 else if (type == IndicatorType.Text)
1262 Size lowIndicatorTextSize = LowIndicatorTextSize();
1263 Size highIndicatorTextSize = HighIndicatorTextSize();
1264 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1265 if (direction == DirectionType.Horizontal)
1267 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
1268 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
1269 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
1271 else if (direction == DirectionType.Vertical)
1273 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
1274 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
1275 bgTrackImage.Position2D = new Position2D(0, -(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2));
1280 private void UpdateValue()
1282 if (slidedTrackImage == null || curValue == null || minValue == null || maxValue == null)
1286 if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
1292 ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
1294 uint curTrackThickness = CurrentTrackThickness();
1296 if (direction == DirectionType.Horizontal)
1298 if (LayoutDirection == ViewLayoutDirectionType.RTL)
1300 ratio = 1.0f - ratio;
1302 float slidedTrackLength = (float)BgTrackLength() * ratio;
1303 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
1305 else if (direction == DirectionType.Vertical)
1307 float slidedTrackLength = (float)BgTrackLength() * ratio;
1308 slidedTrackImage.Size2D = new Size2D((int)(curTrackThickness + round), (int)slidedTrackLength); //Add const round to reach Math.Round function.
1312 private uint CurrentTrackThickness()
1314 uint curTrackThickness = 0;
1315 if (trackThickness != null)
1317 curTrackThickness = trackThickness.Value;
1321 if (Style != null && Style.TrackThickness != null)
1323 curTrackThickness = Style.TrackThickness.Value;
1326 return curTrackThickness;
1329 private uint CurrentSpaceBetweenTrackAndIndicator()
1332 if (spaceBetweenTrackAndIndicator != null)
1334 curSpace = spaceBetweenTrackAndIndicator.Start;
1338 if (Style != null && Style.TrackPadding != null)
1340 curSpace = Style.TrackPadding.Start;
1346 private IndicatorType CurrentIndicatorType()
1348 IndicatorType type = IndicatorType.None;
1351 type = (IndicatorType)Style.IndicatorType;
1356 private Size LowIndicatorImageSize()
1358 Size size = new Size(0, 0);
1359 if (lowIndicatorSize != null)
1361 size = lowIndicatorSize;
1365 if (Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null)
1367 size = Style.LowIndicatorImage.Size;
1373 private Size HighIndicatorImageSize()
1375 Size size = new Size(0, 0);
1376 if (highIndicatorSize != null)
1378 size = highIndicatorSize;
1382 if (Style != null && Style.HighIndicatorImage!= null && Style.HighIndicatorImage.Size != null)
1384 size = Style.HighIndicatorImage.Size;
1390 private Size LowIndicatorTextSize()
1392 Size size = new Size(0, 0);
1393 if (lowIndicatorSize != null)
1395 size = lowIndicatorSize;
1399 if (Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null)
1401 size = Style.LowIndicator.Size;
1407 private Size HighIndicatorTextSize()
1409 Size size = new Size(0, 0);
1410 if (highIndicatorSize != null)
1412 size = highIndicatorSize;
1416 if (Style != null && Style.HighIndicator!= null && Style.HighIndicator.Size != null)
1418 size = Style.HighIndicator.Size;
1424 private void CalculateCurrentValueByGesture(float offset)
1426 currentSlidedOffset += offset;
1428 if (currentSlidedOffset <= 0)
1430 curValue = minValue;
1432 else if (currentSlidedOffset >= BgTrackLength())
1434 curValue = maxValue;
1438 int bgTrackLength = BgTrackLength();
1439 if (bgTrackLength != 0)
1441 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1444 if (valueChangedHandler != null)
1446 ValueChangedArgs args = new ValueChangedArgs();
1447 args.CurrentValue = curValue.Value;
1448 valueChangedHandler(this, args);
1452 private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
1454 PointStateType state = e.Touch.GetState(0);
1455 if (state == PointStateType.Down)
1457 Vector2 pos = e.Touch.GetLocalPosition(0);
1458 CalculateCurrentValueByTouch(pos);
1460 if (null != slidingFinishedHandler)
1462 SlidingFinishedArgs args = new SlidingFinishedArgs();
1463 args.CurrentValue = curValue.Value;
1464 slidingFinishedHandler(this, args);
1470 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1472 PointStateType state = e.Touch.GetState(0);
1473 if (state == PointStateType.Down)
1475 UpdateState(isFocused, true);
1477 else if (state == PointStateType.Up)
1479 UpdateState(isFocused, false);
1484 private void CalculateCurrentValueByTouch(Vector2 pos)
1486 int bgTrackLength = BgTrackLength();
1487 if (direction == DirectionType.Horizontal)
1489 currentSlidedOffset = pos.X;
1491 else if (direction == DirectionType.Vertical)
1493 currentSlidedOffset = bgTrackLength - pos.Y;
1495 if (bgTrackLength != 0)
1497 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1498 if (null != valueChangedHandler)
1500 ValueChangedArgs args = new ValueChangedArgs();
1501 args.CurrentValue = curValue.Value;
1502 valueChangedHandler(this, args);
1507 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1509 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1513 if (thumbImage == null || Style == null)
1517 isFocused = isFocusedNew;
1518 isPressed = isPressedNew;
1520 if (!isFocused && !isPressed)
1522 ControlState = ControlStates.Normal;
1523 if (stateChangedHandler != null)
1525 StateChangedArgs args = new StateChangedArgs();
1526 args.CurrentState = (ControlStates)ControlStates.Normal;
1527 stateChangedHandler(this, args);
1532 ControlState = ControlStates.Pressed;
1534 if (stateChangedHandler != null)
1536 StateChangedArgs args = new StateChangedArgs();
1537 args.CurrentState = (ControlStates)ControlStates.Pressed;
1538 stateChangedHandler(this, args);
1541 else if (!isPressed && isFocused)
1543 ControlState = ControlStates.Focused;
1545 if (stateChangedHandler != null)
1547 StateChangedArgs args = new StateChangedArgs();
1548 args.CurrentState = (ControlStates)ControlStates.Focused;
1549 stateChangedHandler(this, args);
1554 private void UpdateComponentByIndicatorTypeChanged()
1556 IndicatorType type = CurrentIndicatorType();
1557 if (type == IndicatorType.None)
1559 if (lowIndicatorImage != null)
1561 lowIndicatorImage.Hide();
1563 if (highIndicatorImage != null)
1565 highIndicatorImage.Hide();
1567 if (lowIndicatorText != null)
1569 lowIndicatorText.Hide();
1571 if (highIndicatorText != null)
1573 highIndicatorText.Hide();
1576 else if (type == IndicatorType.Image)
1578 if (lowIndicatorImage != null)
1580 lowIndicatorImage.Show();
1582 if (highIndicatorImage != null)
1584 highIndicatorImage.Show();
1586 if (lowIndicatorText != null)
1588 lowIndicatorText.Hide();
1590 if (highIndicatorText != null)
1592 highIndicatorText.Hide();
1595 else if (type == IndicatorType.Text)
1597 if (lowIndicatorText != null)
1599 lowIndicatorText.Show();
1601 if (highIndicatorText != null)
1603 highIndicatorText.Show();
1605 if (lowIndicatorImage != null)
1607 lowIndicatorImage.Hide();
1609 if (highIndicatorImage != null)
1611 highIndicatorImage.Hide();
1617 /// Value Changed event data.
1619 /// <since_tizen> 6 </since_tizen>
1620 public class ValueChangedArgs : EventArgs
1625 /// <since_tizen> 6 </since_tizen>
1626 public float CurrentValue;
1630 /// Value Changed event data.
1632 /// <since_tizen> 6 </since_tizen>
1633 public class SlidingFinishedArgs : EventArgs
1638 /// <since_tizen> 6 </since_tizen>
1639 public float CurrentValue;
1643 /// State Changed event data.
1645 /// <since_tizen> 6 </since_tizen>
1646 public class StateChangedArgs : EventArgs
1651 /// <since_tizen> 6 </since_tizen>
1652 public ControlStates CurrentState;