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 background thumb image object
37 private ImageView bgThumbImage = null;
38 // the low indicator image object
39 private ImageView lowIndicatorImage = null;
40 // the high indicator image object
41 private ImageView highIndicatorImage = null;
42 // the low indicator text object
43 private TextLabel lowIndicatorText = null;
44 // the high indicator text object
45 private TextLabel highIndicatorText = null;
47 private DirectionType direction = DirectionType.Horizontal;
49 private IndicatorType indicatorType = IndicatorType.None;
50 private const float round = 0.5f;
52 private float? minValue = null;
54 private float? maxValue = null;
56 private float? curValue = null;
57 // the size of the low indicator
58 private Size lowIndicatorSize = null;
59 // the size of the high indicator
60 private Size highIndicatorSize = null;
61 // the track thickness value
62 private uint? trackThickness = null;
63 // the value of the space between track and indicator object
64 private Extents _spaceBetweenTrackAndIndicator = null;
65 private Extents spaceBetweenTrackAndIndicator
69 if (null == _spaceBetweenTrackAndIndicator)
71 _spaceBetweenTrackAndIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
73 Extents extents = new Extents(start, end, top, bottom);
74 _spaceBetweenTrackAndIndicator.CopyFrom(extents);
78 return _spaceBetweenTrackAndIndicator;
83 private PanGestureDetector panGestureDetector = null;
84 private float currentSlidedOffset;
85 private EventHandler<ValueChangedArgs> valueChangedHandler;
86 private EventHandler<SlidingFinishedArgs> slidingFinishedHandler;
87 private EventHandler<StateChangedArgs> stateChangedHandler;
89 bool isFocused = false;
90 bool isPressed = false;
92 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
93 [EditorBrowsable(EditorBrowsableState.Never)]
94 public static readonly BindableProperty IndicatorTypeProperty = BindableProperty.Create("IndicatorType", typeof(IndicatorType), typeof(Slider), IndicatorType.None, propertyChanged: (bindable, oldValue, newValue) =>
96 var instance = (Slider)bindable;
99 instance.privateIndicatorType = (IndicatorType)newValue;
102 defaultValueCreator: (bindable) =>
104 var instance = (Slider)bindable;
105 return instance.privateIndicatorType;
107 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
108 [EditorBrowsable(EditorBrowsableState.Never)]
109 public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create("SpaceBetweenTrackAndIndicator", typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
111 var instance = (Slider)bindable;
112 if (newValue != null)
114 instance.privateSpaceBetweenTrackAndIndicator = (uint)newValue;
117 defaultValueCreator: (bindable) =>
119 var instance = (Slider)bindable;
120 return instance.privateSpaceBetweenTrackAndIndicator;
122 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
123 [EditorBrowsable(EditorBrowsableState.Never)]
124 public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create("TrackThickness", typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
126 var instance = (Slider)bindable;
127 if (newValue != null)
129 instance.privateTrackThickness = (uint)newValue;
132 defaultValueCreator: (bindable) =>
134 var instance = (Slider)bindable;
135 return instance.privateTrackThickness;
137 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
138 [EditorBrowsable(EditorBrowsableState.Never)]
139 public static readonly BindableProperty TrackPaddingProperty = BindableProperty.Create("TrackPadding", typeof(Extents), typeof(Slider), null, propertyChanged: (bindable, oldValue, newValue) =>
141 var instance = (Slider)bindable;
142 if (newValue != null)
144 instance.privateTrackPadding.CopyFrom((Extents)newValue);
147 defaultValueCreator: (bindable) =>
149 var instance = (Slider)bindable;
150 return instance.privateTrackPadding;
154 /// The constructor of the Slider class.
156 /// <since_tizen> 6 </since_tizen>
163 /// The constructor of the Slider class with specific style.
165 /// <param name="style">The string to initialize the Slider</param>
166 /// <since_tizen> 6 </since_tizen>
167 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
168 [EditorBrowsable(EditorBrowsableState.Never)]
169 public Slider(string style) : base(style)
175 /// The constructor of the Slider class with specific style.
177 /// <param name="style">The style object to initialize the Slider</param>
178 /// <since_tizen> 6 </since_tizen>
179 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
180 [EditorBrowsable(EditorBrowsableState.Never)]
181 public Slider(SliderStyle style) : base(style)
187 /// The value changed event handler.
189 /// <since_tizen> 6 </since_tizen>
190 public event EventHandler<ValueChangedArgs> ValueChangedEvent
194 valueChangedHandler += value;
198 valueChangedHandler -= value;
203 /// The sliding finished event handler.
205 /// <since_tizen> 6 </since_tizen>
206 public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
210 slidingFinishedHandler += value;
214 slidingFinishedHandler -= value;
219 /// The state changed event handler.
221 /// <since_tizen> 6 </since_tizen>
222 public event EventHandler<StateChangedArgs> StateChangedEvent
226 stateChangedHandler += value;
230 stateChangedHandler -= value;
235 /// The direction type of slider.
237 /// <since_tizen> 6 </since_tizen>
238 public enum DirectionType
241 /// The Horizontal type.
243 /// <since_tizen> 6 </since_tizen>
247 /// The Vertical type.
249 /// <since_tizen> 6 </since_tizen>
254 /// The indicator type of slider.
256 /// <since_tizen> 6 </since_tizen>
257 public enum IndicatorType
259 /// <summary> Only contains slider bar.</summary>
260 /// <since_tizen> 6 </since_tizen>
263 /// <summary> Contains slider bar, IndicatorImage.</summary>
264 /// <since_tizen> 6 </since_tizen>
267 /// <summary> Contains slider bar, IndicatorText.</summary>
268 /// <since_tizen> 6 </since_tizen>
272 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 public new SliderStyle Style => ViewStyle as SliderStyle;
277 /// Gets or sets the direction type of slider.
279 /// <since_tizen> 6 </since_tizen>
280 public DirectionType Direction
288 if (direction == value)
293 RelayoutBaseComponent(false);
295 UpdateBgTrackPosition();
301 /// Gets or sets the indicator type, arrow or sign.
303 /// <since_tizen> 6 </since_tizen>
304 public IndicatorType Indicator
308 return (IndicatorType)GetValue(IndicatorTypeProperty);
312 SetValue(IndicatorTypeProperty, value);
315 private IndicatorType privateIndicatorType
319 return indicatorType;
323 if (indicatorType == value)
327 indicatorType = value;
328 RelayoutBaseComponent(false);
330 UpdateBgTrackPosition();
336 /// Gets or sets the minimum value of slider.
338 /// <since_tizen> 6 </since_tizen>
339 public float MinValue
343 return minValue ?? 0;
353 /// Gets or sets the maximum value of slider.
355 /// <since_tizen> 6 </since_tizen>
356 public float MaxValue
360 return maxValue ?? 100;
370 /// Gets or sets the current value of slider.
372 /// <since_tizen> 6 </since_tizen>
373 public float CurrentValue
377 return curValue ?? 0;
387 /// Gets or sets the size of the thumb image object.
389 /// <since_tizen> 6 </since_tizen>
390 public Size ThumbSize
394 return Style.Thumb?.Size;
398 Style.Thumb.Size = value;
403 /// Gets or sets the resource url of the thumb image object.
405 /// <since_tizen> 6 </since_tizen>
406 public string ThumbImageURL
410 return Style.Thumb?.ResourceUrl?.All;
414 if (Style.Thumb.ResourceUrl == null)
416 Style.Thumb.ResourceUrl = new StringSelector();
418 if (Style.Thumb.ResourceUrl != null)
420 Style.Thumb.ResourceUrl.All = value;
426 /// Gets or sets the resource url selector of the thumb image object.
428 /// <since_tizen> 6 </since_tizen>
429 public StringSelector ThumbImageURLSelector
433 return (StringSelector)Style.Thumb?.ResourceUrl;
439 Style.Thumb.ResourceUrl = value.Clone() as StringSelector;
445 /// Gets or sets the color of the background track image object.
447 /// <since_tizen> 6 </since_tizen>
448 public Color BgTrackColor
452 return Style.Track?.BackgroundColor?.All;
456 if (Style.Track.BackgroundColor == null)
458 Style.Track.BackgroundColor = new ColorSelector();
460 if (Style.Track.BackgroundColor != null)
462 Style.Track.BackgroundColor.All = value;
468 /// Gets or sets the color of the slided track image object.
470 /// <since_tizen> 6 </since_tizen>
471 public Color SlidedTrackColor
475 return Style.Progress?.BackgroundColor?.All;
479 if (Style.Progress.BackgroundColor == null)
481 Style.Progress.BackgroundColor = new ColorSelector();
483 if (Style.Progress.BackgroundColor != null)
485 Style.Progress.BackgroundColor.All = value;
491 /// Gets or sets the thickness value of the track.
493 /// <since_tizen> 6 </since_tizen>
494 public uint TrackThickness
498 return (uint)GetValue(TrackThicknessProperty);
502 SetValue(TrackThicknessProperty, value);
505 private uint privateTrackThickness
509 return trackThickness ?? 0;
513 trackThickness = value;
514 if (bgTrackImage != null)
516 if (direction == DirectionType.Horizontal)
518 bgTrackImage.SizeHeight = (float)trackThickness.Value;
520 else if (direction == DirectionType.Vertical)
522 bgTrackImage.SizeWidth = (float)trackThickness.Value;
525 if (slidedTrackImage != null)
527 if (direction == DirectionType.Horizontal)
529 slidedTrackImage.SizeHeight = (float)trackThickness.Value;
531 else if (direction == DirectionType.Vertical)
533 slidedTrackImage.SizeWidth = (float)trackThickness.Value;
540 /// Gets or sets the resource url of the low indicator image object.
542 /// <since_tizen> 6 </since_tizen>
543 public string LowIndicatorImageURL
547 return Style.LowIndicatorImage?.ResourceUrl?.All;
551 if (Style.LowIndicatorImage.ResourceUrl == null)
553 Style.LowIndicatorImage.ResourceUrl = new StringSelector();
555 if (Style.LowIndicatorImage.ResourceUrl != null)
557 Style.LowIndicatorImage.ResourceUrl.All = value;
563 /// Gets or sets the resource url of the high indicator image object.
565 /// <since_tizen> 6 </since_tizen>
566 public string HighIndicatorImageURL
570 return Style.HighIndicatorImage?.ResourceUrl?.All;
574 if (Style.HighIndicatorImage.ResourceUrl == null)
576 Style.HighIndicatorImage.ResourceUrl = new StringSelector();
578 if (Style.HighIndicatorImage.ResourceUrl != null)
580 Style.HighIndicatorImage.ResourceUrl.All = value;
586 /// Gets or sets the text content of the low indicator text object.
588 /// <since_tizen> 6 </since_tizen>
589 public string LowIndicatorTextContent
593 return Style.LowIndicator?.Text?.All;
597 if (Style.LowIndicator.Text == null)
599 Style.LowIndicator.Text = new StringSelector();
601 if (Style.LowIndicator.Text != null)
603 Style.LowIndicator.Text.All = value;
609 /// Gets or sets the text content of the high indicator text object.
611 /// <since_tizen> 6 </since_tizen>
612 public string HighIndicatorTextContent
616 return Style.HighIndicator?.Text?.All;
620 if (Style.HighIndicator.Text == null)
622 Style.HighIndicator.Text = new StringSelector();
624 if (Style.HighIndicator.Text != null)
626 Style.HighIndicator.Text.All = value;
632 /// Gets or sets the size of the low indicator object(image or text).
634 /// <since_tizen> 6 </since_tizen>
635 public Size LowIndicatorSize
639 return lowIndicatorSize;
643 lowIndicatorSize = value;
644 UpdateLowIndicatorSize();
646 UpdateBgTrackPosition();
652 /// Gets or sets the size of the high indicator object(image or text).
654 /// <since_tizen> 6 </since_tizen>
655 public Size HighIndicatorSize
659 return Style.HighIndicator.Size;
663 Style.HighIndicator.Size = value;
668 /// Gets or sets the value of the space between track and indicator.
670 /// <since_tizen> 6 </since_tizen>
671 public uint SpaceBetweenTrackAndIndicator
675 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
679 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
682 private uint privateSpaceBetweenTrackAndIndicator
686 return TrackPadding.Start;
690 ushort val = (ushort)value;
691 TrackPadding = new Extents(val, val, val, val);
696 /// Gets or sets the value of the space between track and indicator.
698 /// <since_tizen> 6 </since_tizen>
699 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
700 [EditorBrowsable(EditorBrowsableState.Never)]
701 public Extents TrackPadding
705 return (Extents)GetValue(TrackPaddingProperty);
709 SetValue(TrackPaddingProperty, value);
712 private Extents privateTrackPadding
716 return spaceBetweenTrackAndIndicator;
720 spaceBetweenTrackAndIndicator.CopyFrom(value);
721 UpdateComponentByIndicatorTypeChanged();
723 UpdateBgTrackPosition();
729 /// Focus gained callback.
731 /// <since_tizen> 6 </since_tizen>
732 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
733 [EditorBrowsable(EditorBrowsableState.Never)]
734 public override void OnFocusGained()
736 //State = ControlStates.Focused;
737 UpdateState(true, isPressed);
738 base.OnFocusGained();
742 /// Focus Lost callback.
744 /// <since_tizen> 6 </since_tizen>
745 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
746 [EditorBrowsable(EditorBrowsableState.Never)]
747 public override void OnFocusLost()
749 //State = ControlStates.Normal;
750 UpdateState(false, isPressed);
755 /// Get Slider attribues.
757 /// <since_tizen> 6 </since_tizen>
758 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
759 [EditorBrowsable(EditorBrowsableState.Never)]
760 protected override ViewStyle GetViewStyle()
762 return new SliderStyle();
768 /// <param name="type">Dispose type.</param>
769 /// <since_tizen> 6 </since_tizen>
770 protected override void Dispose(DisposeTypes type)
777 if (type == DisposeTypes.Explicit)
779 if (null != panGestureDetector)
781 if (null != thumbImage)
783 panGestureDetector.Detach(thumbImage);
785 panGestureDetector.Detected -= OnPanGestureDetected;
786 panGestureDetector.Dispose();
787 panGestureDetector = null;
790 if (null != thumbImage)
792 thumbImage.TouchEvent -= OnTouchEventForThumb;
793 Utility.Dispose(thumbImage);
795 Utility.Dispose(bgThumbImage);
796 Utility.Dispose(slidedTrackImage);
797 if (null != bgTrackImage)
799 bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
800 Utility.Dispose(bgTrackImage);
802 Utility.Dispose(lowIndicatorImage);
803 Utility.Dispose(highIndicatorImage);
804 Utility.Dispose(lowIndicatorText);
805 Utility.Dispose(highIndicatorText);
812 /// Update Slider by attributes.
814 /// <since_tizen> 6 </since_tizen>
815 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
816 [EditorBrowsable(EditorBrowsableState.Never)]
817 protected override void OnUpdate()
819 RelayoutBaseComponent();
821 UpdateComponentByIndicatorTypeChanged();
823 UpdateBgTrackPosition();
824 UpdateLowIndicatorSize();
829 /// Theme change callback when theme is changed, this callback will be trigger.
831 /// <param name="sender">serder object</param>
832 /// <param name="e">ThemeChangeEventArgs</param>
833 /// <since_tizen> 6 </since_tizen>
834 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
835 [EditorBrowsable(EditorBrowsableState.Never)]
836 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
838 SliderStyle tempAttributes = StyleManager.Instance.GetAttributes(style) as SliderStyle;
839 if (tempAttributes != null)
841 Style.CopyFrom(tempAttributes);
846 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
847 [EditorBrowsable(EditorBrowsableState.Never)]
848 public override void ApplyStyle(ViewStyle viewStyle)
850 base.ApplyStyle(viewStyle);
852 SliderStyle sliderStyle = viewStyle as SliderStyle;
854 if (null != sliderStyle.Progress)
856 CreateSlidedTrackAttributes();
859 if (null != sliderStyle.LowIndicator)
861 CreateLowIndicatorTextAttributes();
864 if (null != sliderStyle.HighIndicator)
866 CreateHighIndicatorTextAttributes();
869 if (null != sliderStyle.Track)
871 CreateBackgroundTrackAttributes();
874 if (null != sliderStyle.Thumb)
876 CreateThumbAttributes();
879 if (null != sliderStyle.ThumbBackground)
881 CreateThumbBackgroundAttributes();
885 private void Initialize()
887 currentSlidedOffset = 0;
890 LayoutDirectionChanged += OnLayoutDirectionChanged;
893 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
898 private void CreateSlidedTrackAttributes()
900 if (null == slidedTrackImage)
902 slidedTrackImage = new ImageView()
904 WidthResizePolicy = ResizePolicyType.Fixed,
905 HeightResizePolicy = ResizePolicyType.Fixed
908 if (bgTrackImage != null)
910 bgTrackImage.Add(slidedTrackImage);
913 if (null != bgThumbImage)
915 slidedTrackImage.Add(bgThumbImage);
919 if (null == Style.Progress)
921 Style.Progress = new ImageViewStyle();
924 slidedTrackImage.ApplyStyle(Style.Progress);
927 private void CreateLowIndicatorTextAttributes()
929 if (null == lowIndicatorText)
931 lowIndicatorText = new TextLabel()
933 WidthResizePolicy = ResizePolicyType.Fixed,
934 HeightResizePolicy = ResizePolicyType.Fixed
936 this.Add(lowIndicatorText);
939 if (null == Style.LowIndicator)
941 Style.LowIndicator = new TextLabelStyle();
944 lowIndicatorText.ApplyStyle(Style.LowIndicator);
947 private void CreateHighIndicatorTextAttributes()
949 if (null == highIndicatorText)
951 highIndicatorText = new TextLabel()
953 WidthResizePolicy = ResizePolicyType.Fixed,
954 HeightResizePolicy = ResizePolicyType.Fixed
956 this.Add(highIndicatorText);
959 if (null == Style.HighIndicator)
961 Style.HighIndicator = new TextLabelStyle();
964 highIndicatorText.ApplyStyle(Style.HighIndicator);
967 private void CreateBackgroundTrackAttributes()
969 if (null == bgTrackImage)
971 bgTrackImage = new ImageView()
973 WidthResizePolicy = ResizePolicyType.Fixed,
974 HeightResizePolicy = ResizePolicyType.Fixed,
975 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
976 PivotPoint = Tizen.NUI.PivotPoint.Center,
977 PositionUsesPivotPoint = true
979 this.Add(bgTrackImage);
981 if (null != slidedTrackImage)
983 bgTrackImage.Add(slidedTrackImage);
986 bgTrackImage.TouchEvent += OnTouchEventForBgTrack;
989 if (null == Style.Track)
991 Style.Track = new ImageViewStyle();
994 bgTrackImage.ApplyStyle(Style.Track);
997 private void CreateThumbAttributes()
999 if (null == thumbImage)
1001 thumbImage = new ImageView()
1003 WidthResizePolicy = ResizePolicyType.FillToParent,
1004 HeightResizePolicy = ResizePolicyType.FillToParent,
1005 ParentOrigin = NUI.ParentOrigin.Center,
1006 PivotPoint = NUI.PivotPoint.Center,
1007 PositionUsesPivotPoint = true
1009 if (bgThumbImage != null)
1011 bgThumbImage.Add(thumbImage);
1013 thumbImage.TouchEvent += OnTouchEventForThumb;
1015 panGestureDetector = new PanGestureDetector();
1016 panGestureDetector.Attach(thumbImage);
1017 panGestureDetector.Detected += OnPanGestureDetected;
1020 if (null == Style.Thumb)
1022 Style.Thumb= new ImageViewStyle();
1025 thumbImage.ApplyStyle(Style.Thumb);
1028 private void CreateThumbBackgroundAttributes()
1030 if (null == bgThumbImage)
1032 bgThumbImage = new ImageView()
1034 WidthResizePolicy = ResizePolicyType.Fixed,
1035 HeightResizePolicy = ResizePolicyType.Fixed
1038 if (slidedTrackImage != null)
1040 slidedTrackImage.Add(bgThumbImage);
1043 if (null != thumbImage)
1045 bgThumbImage.Add(thumbImage);
1049 if (null == Style.ThumbBackground)
1051 Style.ThumbBackground= new ImageViewStyle();
1054 bgThumbImage.ApplyStyle(Style.ThumbBackground);
1057 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
1059 if (e.PanGesture.State == Gesture.StateType.Started)
1061 if (direction == DirectionType.Horizontal)
1063 currentSlidedOffset = slidedTrackImage.SizeWidth;
1065 else if (direction == DirectionType.Vertical)
1067 currentSlidedOffset = slidedTrackImage.SizeHeight;
1069 UpdateState(isFocused, true);
1072 if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
1074 if (direction == DirectionType.Horizontal)
1076 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
1078 else if (direction == DirectionType.Vertical)
1080 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
1085 if (e.PanGesture.State == Gesture.StateType.Finished)
1087 if (null != slidingFinishedHandler)
1089 SlidingFinishedArgs args = new SlidingFinishedArgs();
1090 args.CurrentValue = curValue.Value;
1091 slidingFinishedHandler(this, args);
1094 UpdateState(isFocused, false);
1098 // Relayout basic component: track, thumb and indicator
1099 private void RelayoutBaseComponent(bool isInitial = true)
1101 if (direction == DirectionType.Horizontal)
1103 if (slidedTrackImage != null)
1105 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1106 slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
1107 slidedTrackImage.PositionUsesPivotPoint = true;
1109 if (bgThumbImage != null)
1111 bgThumbImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
1112 bgThumbImage.PivotPoint = NUI.PivotPoint.Center;
1113 bgThumbImage.PositionUsesPivotPoint = true;
1115 if (lowIndicatorImage != null)
1117 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1118 lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
1119 lowIndicatorImage.PositionUsesPivotPoint = true;
1121 if (highIndicatorImage != null)
1123 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
1124 highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
1125 highIndicatorImage.PositionUsesPivotPoint = true;
1127 if (lowIndicatorText != null)
1129 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1130 lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
1131 lowIndicatorText.PositionUsesPivotPoint = true;
1133 if (highIndicatorText != null)
1135 highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1136 highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
1137 highIndicatorText.PositionUsesPivotPoint = true;
1139 if (panGestureDetector != null)
1143 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
1145 panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
1148 else if (direction == DirectionType.Vertical)
1150 if (slidedTrackImage != null)
1152 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1153 slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
1154 slidedTrackImage.PositionUsesPivotPoint = true;
1156 if (bgThumbImage != null)
1158 bgThumbImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
1159 bgThumbImage.PivotPoint = NUI.PivotPoint.Center;
1160 bgThumbImage.PositionUsesPivotPoint = true;
1162 if (lowIndicatorImage != null)
1164 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1165 lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
1166 lowIndicatorImage.PositionUsesPivotPoint = true;
1168 if (highIndicatorImage != null)
1170 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
1171 highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
1172 highIndicatorImage.PositionUsesPivotPoint = true;
1174 if (lowIndicatorText != null)
1176 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1177 lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
1178 lowIndicatorText.PositionUsesPivotPoint = true;
1180 if (highIndicatorText != null)
1182 highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
1183 highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
1184 highIndicatorText.PositionUsesPivotPoint = true;
1186 if (panGestureDetector != null)
1190 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
1192 panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
1197 private int BgTrackLength()
1199 int bgTrackLength = 0;
1200 IndicatorType type = CurrentIndicatorType();
1202 if (type == IndicatorType.None)
1204 if (direction == DirectionType.Horizontal)
1206 bgTrackLength = this.Size2D.Width;
1208 else if (direction == DirectionType.Vertical)
1210 bgTrackLength = this.Size2D.Height;
1213 else if (type == IndicatorType.Image)
1214 {// <lowIndicatorImage> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage>
1215 Size lowIndicatorImageSize = LowIndicatorImageSize();
1216 Size highIndicatorImageSize = HighIndicatorImageSize();
1217 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1218 if (direction == DirectionType.Horizontal)
1220 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
1221 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
1222 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
1224 else if (direction == DirectionType.Vertical)
1226 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
1227 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
1228 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
1231 else if (type == IndicatorType.Text)
1232 {// <lowIndicatorText> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorText>
1233 Size lowIndicatorTextSize = LowIndicatorTextSize();
1234 Size highIndicatorTextSize = HighIndicatorTextSize();
1235 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1236 if (direction == DirectionType.Horizontal)
1238 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
1239 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
1240 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
1242 else if (direction == DirectionType.Vertical)
1244 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
1245 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
1246 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
1249 return bgTrackLength;
1252 private void UpdateLowIndicatorSize()
1254 if (lowIndicatorSize != null)
1256 if (lowIndicatorImage != null)
1258 lowIndicatorImage.Size = lowIndicatorSize;
1260 if (lowIndicatorText != null)
1262 lowIndicatorText.Size = lowIndicatorSize;
1267 if (lowIndicatorImage != null && Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null)
1269 lowIndicatorImage.Size = Style.LowIndicatorImage.Size;
1271 if (lowIndicatorText != null && Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null)
1273 lowIndicatorText.Size = Style.LowIndicator.Size;
1278 private void UpdateBgTrackSize()
1280 if(bgTrackImage == null)
1284 int curTrackThickness = (int)CurrentTrackThickness();
1285 int bgTrackLength = BgTrackLength();
1286 if (direction == DirectionType.Horizontal)
1288 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
1290 else if (direction == DirectionType.Vertical)
1292 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
1296 private void UpdateBgTrackPosition()
1298 if (bgTrackImage == null)
1302 IndicatorType type = CurrentIndicatorType();
1304 if (type == IndicatorType.None)
1306 bgTrackImage.Position2D = new Position2D(0, 0);
1308 else if (type == IndicatorType.Image)
1310 Size lowIndicatorImageSize = LowIndicatorImageSize();
1311 Size highIndicatorImageSize = HighIndicatorImageSize();
1312 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1313 if (direction == DirectionType.Horizontal)
1315 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
1316 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
1317 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
1319 else if (direction == DirectionType.Vertical)
1321 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
1322 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
1323 bgTrackImage.Position2D = new Position2D(0, lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2);
1326 else if (type == IndicatorType.Text)
1328 Size lowIndicatorTextSize = LowIndicatorTextSize();
1329 Size highIndicatorTextSize = HighIndicatorTextSize();
1330 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1331 if (direction == DirectionType.Horizontal)
1333 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
1334 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
1335 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
1337 else if (direction == DirectionType.Vertical)
1339 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
1340 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
1341 bgTrackImage.Position2D = new Position2D(0, -(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2));
1346 private void UpdateValue()
1348 if (slidedTrackImage == null || curValue == null || minValue == null || maxValue == null)
1352 if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
1358 ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
1360 uint curTrackThickness = CurrentTrackThickness();
1362 if (direction == DirectionType.Horizontal)
1364 if (LayoutDirection == ViewLayoutDirectionType.RTL)
1366 ratio = 1.0f - ratio;
1368 float slidedTrackLength = (float)BgTrackLength() * ratio;
1369 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
1371 else if (direction == DirectionType.Vertical)
1373 float slidedTrackLength = (float)BgTrackLength() * ratio;
1374 slidedTrackImage.Size2D = new Size2D((int)(curTrackThickness + round), (int)slidedTrackLength); //Add const round to reach Math.Round function.
1378 private uint CurrentTrackThickness()
1380 uint curTrackThickness = 0;
1381 if (trackThickness != null)
1383 curTrackThickness = trackThickness.Value;
1387 if (Style != null && Style.TrackThickness != null)
1389 curTrackThickness = Style.TrackThickness.Value;
1392 return curTrackThickness;
1395 private uint CurrentSpaceBetweenTrackAndIndicator()
1398 if (spaceBetweenTrackAndIndicator != null)
1400 curSpace = spaceBetweenTrackAndIndicator.Start;
1404 if (Style != null && Style.TrackPadding != null)
1406 curSpace = Style.TrackPadding.Start;
1412 private IndicatorType CurrentIndicatorType()
1414 IndicatorType type = IndicatorType.None;
1417 type = (IndicatorType)Style.IndicatorType;
1422 private Size LowIndicatorImageSize()
1424 Size size = new Size(0, 0);
1425 if (lowIndicatorSize != null)
1427 size = lowIndicatorSize;
1431 if (Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null)
1433 size = Style.LowIndicatorImage.Size;
1439 private Size HighIndicatorImageSize()
1441 Size size = new Size(0, 0);
1442 if (highIndicatorSize != null)
1444 size = highIndicatorSize;
1448 if (Style != null && Style.HighIndicatorImage!= null && Style.HighIndicatorImage.Size != null)
1450 size = Style.HighIndicatorImage.Size;
1456 private Size LowIndicatorTextSize()
1458 Size size = new Size(0, 0);
1459 if (lowIndicatorSize != null)
1461 size = lowIndicatorSize;
1465 if (Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null)
1467 size = Style.LowIndicator.Size;
1473 private Size HighIndicatorTextSize()
1475 Size size = new Size(0, 0);
1476 if (highIndicatorSize != null)
1478 size = highIndicatorSize;
1482 if (Style != null && Style.HighIndicator!= null && Style.HighIndicator.Size != null)
1484 size = Style.HighIndicator.Size;
1490 private void CalculateCurrentValueByGesture(float offset)
1492 currentSlidedOffset += offset;
1494 if (currentSlidedOffset <= 0)
1496 curValue = minValue;
1498 else if (currentSlidedOffset >= BgTrackLength())
1500 curValue = maxValue;
1504 int bgTrackLength = BgTrackLength();
1505 if (bgTrackLength != 0)
1507 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1510 if (valueChangedHandler != null)
1512 ValueChangedArgs args = new ValueChangedArgs();
1513 args.CurrentValue = curValue.Value;
1514 valueChangedHandler(this, args);
1518 private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
1520 PointStateType state = e.Touch.GetState(0);
1521 if (state == PointStateType.Down)
1523 Vector2 pos = e.Touch.GetLocalPosition(0);
1524 CalculateCurrentValueByTouch(pos);
1526 if (null != slidingFinishedHandler)
1528 SlidingFinishedArgs args = new SlidingFinishedArgs();
1529 args.CurrentValue = curValue.Value;
1530 slidingFinishedHandler(this, args);
1536 private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1538 PointStateType state = e.Touch.GetState(0);
1539 if (state == PointStateType.Down)
1541 UpdateState(isFocused, true);
1543 else if (state == PointStateType.Up)
1545 UpdateState(isFocused, false);
1550 private void CalculateCurrentValueByTouch(Vector2 pos)
1552 int bgTrackLength = BgTrackLength();
1553 if (direction == DirectionType.Horizontal)
1555 currentSlidedOffset = pos.X;
1557 else if (direction == DirectionType.Vertical)
1559 currentSlidedOffset = bgTrackLength - pos.Y;
1561 if (bgTrackLength != 0)
1563 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1564 if (null != valueChangedHandler)
1566 ValueChangedArgs args = new ValueChangedArgs();
1567 args.CurrentValue = curValue.Value;
1568 valueChangedHandler(this, args);
1573 private void UpdateState(bool isFocusedNew, bool isPressedNew)
1575 if (isFocused == isFocusedNew && isPressed == isPressedNew)
1579 if (thumbImage == null || Style == null)
1583 isFocused = isFocusedNew;
1584 isPressed = isPressedNew;
1586 if (!isFocused && !isPressed)
1588 ControlState = ControlStates.Normal;
1589 if (stateChangedHandler != null)
1591 StateChangedArgs args = new StateChangedArgs();
1592 args.CurrentState = (ControlStates)ControlStates.Normal;
1593 stateChangedHandler(this, args);
1598 ControlState = ControlStates.Pressed;
1600 if (stateChangedHandler != null)
1602 StateChangedArgs args = new StateChangedArgs();
1603 args.CurrentState = (ControlStates)ControlStates.Pressed;
1604 stateChangedHandler(this, args);
1607 else if (!isPressed && isFocused)
1609 ControlState = ControlStates.Focused;
1611 if (stateChangedHandler != null)
1613 StateChangedArgs args = new StateChangedArgs();
1614 args.CurrentState = (ControlStates)ControlStates.Focused;
1615 stateChangedHandler(this, args);
1620 private void UpdateComponentByIndicatorTypeChanged()
1622 IndicatorType type = CurrentIndicatorType();
1623 if (type == IndicatorType.None)
1625 if (lowIndicatorImage != null)
1627 lowIndicatorImage.Hide();
1629 if (highIndicatorImage != null)
1631 highIndicatorImage.Hide();
1633 if (lowIndicatorText != null)
1635 lowIndicatorText.Hide();
1637 if (highIndicatorText != null)
1639 highIndicatorText.Hide();
1642 else if (type == IndicatorType.Image)
1644 if (lowIndicatorImage != null)
1646 lowIndicatorImage.Show();
1648 if (highIndicatorImage != null)
1650 highIndicatorImage.Show();
1652 if (lowIndicatorText != null)
1654 lowIndicatorText.Hide();
1656 if (highIndicatorText != null)
1658 highIndicatorText.Hide();
1661 else if (type == IndicatorType.Text)
1663 if (lowIndicatorText != null)
1665 lowIndicatorText.Show();
1667 if (highIndicatorText != null)
1669 highIndicatorText.Show();
1671 if (lowIndicatorImage != null)
1673 lowIndicatorImage.Hide();
1675 if (highIndicatorImage != null)
1677 highIndicatorImage.Hide();
1683 /// Value Changed event data.
1685 /// <since_tizen> 6 </since_tizen>
1686 public class ValueChangedArgs : EventArgs
1691 /// <since_tizen> 6 </since_tizen>
1692 public float CurrentValue;
1696 /// Value Changed event data.
1698 /// <since_tizen> 6 </since_tizen>
1699 public class SlidingFinishedArgs : EventArgs
1704 /// <since_tizen> 6 </since_tizen>
1705 public float CurrentValue;
1709 /// State Changed event data.
1711 /// <since_tizen> 6 </since_tizen>
1712 public class StateChangedArgs : EventArgs
1717 /// <since_tizen> 6 </since_tizen>
1718 public ControlStates CurrentState;