2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
22 namespace Tizen.NUI.Components
24 public partial class Slider
26 // the background track image object
27 private ImageView bgTrackImage = null;
28 // the slided track image object
29 private ImageView slidedTrackImage = null;
30 // the warning track image object
31 private ImageView warningTrackImage = null;
32 // the warning slided track image object
33 private ImageView warningSlidedTrackImage = 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 = 0;
52 private float maxValue = 100;
54 private float curValue = 0;
55 // the warning start value
56 private float warningStartValue = 100;
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 spaceTrackIndicator = null;
65 // Whether the value indicator is shown or not
66 private bool isValueShown = false;
67 // the value indicator text
68 private TextLabel valueIndicatorText = null;
69 // the value indicator image object
70 private ImageView valueIndicatorImage = null;
72 // To store the thumb size of normal state
73 private Size thumbSize = null;
74 // To store the thumb image url of normal state
75 private string thumbImageUrl = null;
76 // To store the thumb color of normal state
77 private Color thumbColor = Color.White;
78 // To store the thumb image url of warning state
79 private string warningThumbImageUrl = null;
80 // To store the thumb image url selector of warning state
81 private Selector<string> warningThumbImageUrlSelector = null;
82 // To store the thumb color of warning state
83 private Color warningThumbColor = null;
85 private float discreteValue = 0;
87 private PanGestureDetector panGestureDetector = null;
88 private readonly uint panGestureMotionEventAge = 16; // TODO : Can't we get this value from system configure?
89 private float currentSlidedOffset;
90 private EventHandler<SliderValueChangedEventArgs> sliderValueChangedHandler;
91 private EventHandler<SliderSlidingStartedEventArgs> sliderSlidingStartedHandler;
92 private EventHandler<SliderSlidingFinishedEventArgs> sliderSlidingFinishedHandler;
94 bool isFocused = false;
95 bool isPressed = false;
97 private void Initialize()
99 AccessibilityHighlightable = true;
101 currentSlidedOffset = 0;
104 LayoutDirectionChanged += OnLayoutDirectionChanged;
106 this.TouchEvent += OnTouchEventForTrack;
107 this.GrabTouchAfterLeave = true;
109 panGestureDetector = new PanGestureDetector();
110 panGestureDetector.Attach(this);
111 panGestureDetector.SetMaximumMotionEventAge(panGestureMotionEventAge);
112 panGestureDetector.Detected += OnPanGestureDetected;
114 this.Layout = new LinearLayout()
116 LinearOrientation = LinearLayout.Orientation.Horizontal,
120 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
125 private ImageView CreateSlidedTrack()
127 if (null == slidedTrackImage)
129 slidedTrackImage = new ImageView()
131 WidthResizePolicy = ResizePolicyType.Fixed,
132 HeightResizePolicy = ResizePolicyType.Fixed,
133 AccessibilityHidden = true,
136 if (bgTrackImage != null)
138 bgTrackImage.Add(slidedTrackImage);
142 return slidedTrackImage;
145 private ImageView CreateWarningTrack()
147 if (null == warningTrackImage)
149 warningTrackImage = new ImageView()
151 WidthResizePolicy = ResizePolicyType.Fixed,
152 HeightResizePolicy = ResizePolicyType.Fixed,
153 AccessibilityHidden = true,
156 if (bgTrackImage != null)
158 bgTrackImage.Add(warningTrackImage);
161 if (warningSlidedTrackImage != null)
163 warningTrackImage.Add(warningSlidedTrackImage);
166 if (slidedTrackImage != null)
168 warningTrackImage.RaiseAbove(slidedTrackImage);
172 return warningTrackImage;
175 private ImageView CreateWarningSlidedTrack()
177 if (null == warningSlidedTrackImage)
179 warningSlidedTrackImage = new ImageView()
181 WidthResizePolicy = ResizePolicyType.Fixed,
182 HeightResizePolicy = ResizePolicyType.Fixed,
183 AccessibilityHidden = true,
186 if (warningTrackImage != null)
188 warningTrackImage.Add(warningSlidedTrackImage);
192 return warningSlidedTrackImage;
195 private TextLabel CreateLowIndicatorText()
197 if (null == lowIndicatorText)
199 lowIndicatorText = new TextLabel()
201 WidthResizePolicy = ResizePolicyType.Fixed,
202 HeightResizePolicy = ResizePolicyType.Fixed,
203 AccessibilityHidden = true,
205 this.Add(lowIndicatorText);
208 return lowIndicatorText;
211 private TextLabel CreateHighIndicatorText()
213 if (null == highIndicatorText)
215 highIndicatorText = new TextLabel()
217 WidthResizePolicy = ResizePolicyType.Fixed,
218 HeightResizePolicy = ResizePolicyType.Fixed,
219 AccessibilityHidden = true,
221 this.Add(highIndicatorText);
224 return highIndicatorText;
227 private ImageView CreateLowIndicatorImage()
229 if (lowIndicatorImage == null)
231 lowIndicatorImage = new ImageView()
233 WidthResizePolicy = ResizePolicyType.Fixed,
234 HeightResizePolicy = ResizePolicyType.Fixed,
235 AccessibilityHidden = true,
237 this.Add(lowIndicatorImage);
240 return lowIndicatorImage;
243 private ImageView CreateHighIndicatorImage()
245 if (highIndicatorImage == null)
247 highIndicatorImage = new ImageView()
249 WidthResizePolicy = ResizePolicyType.Fixed,
250 HeightResizePolicy = ResizePolicyType.Fixed,
251 AccessibilityHidden = true,
253 this.Add(highIndicatorImage);
256 return highIndicatorImage;
261 private ImageView CreateBackgroundTrack()
263 if (null == bgTrackImage)
265 bgTrackImage = new ImageView()
267 WidthResizePolicy = ResizePolicyType.Fixed,
268 HeightResizePolicy = ResizePolicyType.Fixed,
269 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
270 PivotPoint = Tizen.NUI.PivotPoint.Center,
271 PositionUsesPivotPoint = true,
272 GrabTouchAfterLeave = true,
273 AccessibilityHidden = true,
275 this.Add(bgTrackImage);
277 if (null != slidedTrackImage)
279 bgTrackImage.Add(slidedTrackImage);
281 if (null != warningTrackImage)
283 bgTrackImage.Add(warningTrackImage);
285 if (null != thumbImage)
287 bgTrackImage.Add(thumbImage);
288 thumbImage.RaiseToTop();
295 private ImageView CreateThumb()
297 if (null == thumbImage)
299 thumbImage = new ImageView()
301 WidthResizePolicy = ResizePolicyType.Fixed,
302 HeightResizePolicy = ResizePolicyType.Fixed,
303 EnableControlState = true,
304 GrabTouchAfterLeave = true,
305 AccessibilityHidden = true,
307 if (valueIndicatorImage != null)
309 thumbImage.Add(valueIndicatorImage);
311 if (bgTrackImage != null)
313 bgTrackImage.Add(thumbImage);
315 thumbImage.RaiseToTop();
316 thumbImage.TouchEvent += OnTouchEventForThumb;
322 private ImageView CreateValueIndicatorImage()
324 if (valueIndicatorImage == null)
326 valueIndicatorImage = new ImageView()
328 WidthResizePolicy = ResizePolicyType.FitToChildren,
329 HeightResizePolicy = ResizePolicyType.Fixed,
330 AccessibilityHidden = true,
332 if (thumbImage != null)
334 thumbImage.Add(valueIndicatorImage);
336 if (valueIndicatorText != null)
338 valueIndicatorImage.Add(valueIndicatorText);
339 valueIndicatorText.RaiseToTop();
343 valueIndicatorImage.Hide();
344 return valueIndicatorImage;
347 private TextLabel CreateValueIndicatorText()
349 if (null == valueIndicatorText)
351 valueIndicatorText = new TextLabel()
353 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
354 HeightResizePolicy = ResizePolicyType.Fixed,
355 AccessibilityHidden = true,
357 if (valueIndicatorImage != null)
359 valueIndicatorImage.Add(valueIndicatorText);
361 valueIndicatorText.RaiseToTop();
364 return valueIndicatorText;
367 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
369 if (e.PanGesture.State == Gesture.StateType.Started)
371 if (direction == DirectionType.Horizontal)
373 currentSlidedOffset = slidedTrackImage.SizeWidth;
375 else if (direction == DirectionType.Vertical)
377 currentSlidedOffset = slidedTrackImage.SizeHeight;
382 valueIndicatorImage.Show();
385 if (null != sliderSlidingStartedHandler)
387 SliderSlidingStartedEventArgs args = new SliderSlidingStartedEventArgs();
388 args.CurrentValue = curValue;
389 sliderSlidingStartedHandler(this, args);
391 UpdateState(isFocused, true);
394 if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
396 if (direction == DirectionType.Horizontal)
398 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
400 else if (direction == DirectionType.Vertical)
402 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
404 UpdateState(isFocused, true);
408 if (e.PanGesture.State == Gesture.StateType.Finished)
410 // Update as finished position value
411 if (direction == DirectionType.Horizontal)
413 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
415 else if (direction == DirectionType.Vertical)
417 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
423 valueIndicatorImage.Hide();
426 if (null != sliderSlidingFinishedHandler)
428 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
429 args.CurrentValue = curValue;
430 sliderSlidingFinishedHandler(this, args);
433 UpdateState(isFocused, false);
437 // Relayout basic component: track, thumb and indicator
438 private void RelayoutBaseComponent(bool isInitial = true)
440 if (direction == DirectionType.Horizontal)
442 if (slidedTrackImage != null)
444 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
445 slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
446 slidedTrackImage.PositionUsesPivotPoint = true;
448 if (warningTrackImage != null)
450 warningTrackImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
451 warningTrackImage.PivotPoint = NUI.PivotPoint.CenterRight;
452 warningTrackImage.PositionUsesPivotPoint = true;
454 if (warningSlidedTrackImage != null)
456 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
457 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
458 warningSlidedTrackImage.PositionUsesPivotPoint = true;
460 if (thumbImage != null)
462 thumbImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
463 thumbImage.PivotPoint = NUI.PivotPoint.Center;
464 thumbImage.PositionUsesPivotPoint = true;
466 if (lowIndicatorImage != null)
468 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
469 lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
470 lowIndicatorImage.PositionUsesPivotPoint = true;
472 if (highIndicatorImage != null)
474 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
475 highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
476 highIndicatorImage.PositionUsesPivotPoint = true;
478 if (lowIndicatorText != null)
480 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
481 lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
482 lowIndicatorText.PositionUsesPivotPoint = true;
484 if (highIndicatorText != null)
486 highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
487 highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
488 highIndicatorText.PositionUsesPivotPoint = true;
490 if (valueIndicatorImage != null)
492 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
493 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
494 valueIndicatorImage.PositionUsesPivotPoint = true;
495 valueIndicatorImage.PositionY = -10.0f;
497 if (valueIndicatorText != null)
499 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.Center;
500 valueIndicatorText.PivotPoint = NUI.PivotPoint.Center;
501 valueIndicatorText.PositionUsesPivotPoint = true;
503 if (panGestureDetector != null)
507 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
509 panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
512 else if (direction == DirectionType.Vertical)
514 if (slidedTrackImage != null)
516 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
517 slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
518 slidedTrackImage.PositionUsesPivotPoint = true;
520 if (warningTrackImage != null)
522 warningTrackImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
523 warningTrackImage.PivotPoint = NUI.PivotPoint.TopCenter;
524 warningTrackImage.PositionUsesPivotPoint = true;
526 if (warningSlidedTrackImage != null)
528 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
529 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
530 warningSlidedTrackImage.PositionUsesPivotPoint = true;
532 if (thumbImage != null)
534 thumbImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
535 thumbImage.PivotPoint = NUI.PivotPoint.Center;
536 thumbImage.PositionUsesPivotPoint = true;
538 if (lowIndicatorImage != null)
540 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
541 lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
542 lowIndicatorImage.PositionUsesPivotPoint = true;
544 if (highIndicatorImage != null)
546 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
547 highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
548 highIndicatorImage.PositionUsesPivotPoint = true;
550 if (lowIndicatorText != null)
552 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
553 lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
554 lowIndicatorText.PositionUsesPivotPoint = true;
556 if (highIndicatorText != null)
558 highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
559 highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
560 highIndicatorText.PositionUsesPivotPoint = true;
562 if (valueIndicatorImage != null)
564 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
565 valueIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
566 valueIndicatorImage.PositionUsesPivotPoint = true;
567 valueIndicatorImage.PositionX = -14.0f;
569 if (valueIndicatorText != null)
571 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.Center;
572 valueIndicatorText.PivotPoint = NUI.PivotPoint.Center;
573 valueIndicatorText.PositionUsesPivotPoint = true;
575 if (panGestureDetector != null)
579 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
581 panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
586 private int GetBgTrackLength()
588 int bgTrackLength = 0;
590 int lowIndicatorOffset = GetBgTrackLowIndicatorOffset();
591 int highIndicatorOffet = GetBgTrackHighIndicatorOffset();
593 if (direction == DirectionType.Horizontal)
595 bgTrackLength = this.Size2D.Width - lowIndicatorOffset - highIndicatorOffet;
597 else if (direction == DirectionType.Vertical)
599 bgTrackLength = this.Size2D.Height - lowIndicatorOffset - highIndicatorOffet;
602 return bgTrackLength;
606 /// Get offset value of bgtrack's low indicator side.
608 private int GetBgTrackLowIndicatorOffset()
610 int bgTrackLowIndicatorOffset = 0;
611 IndicatorType type = CurrentIndicatorType();
613 if (type == IndicatorType.None)
615 if (direction == DirectionType.Horizontal)
617 bgTrackLowIndicatorOffset = (int)(thumbImage.Size.Width * 0.5f);
619 else if (direction == DirectionType.Vertical)
621 bgTrackLowIndicatorOffset = (int)(thumbImage.Size.Height * 0.5f);
624 else if (type == IndicatorType.Image || type == IndicatorType.Text)
625 {// <lowIndicatorImage or Text> <spaceBetweenTrackAndIndicator> <bgTrack>
626 Size lowIndicatorSize = (type == IndicatorType.Image) ? LowIndicatorImageSize() : LowIndicatorTextSize();
627 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
628 if (direction == DirectionType.Horizontal)
630 bgTrackLowIndicatorOffset = ((lowIndicatorSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorSize.Width)));
632 else if (direction == DirectionType.Vertical)
634 bgTrackLowIndicatorOffset = ((lowIndicatorSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorSize.Height)));
637 return bgTrackLowIndicatorOffset;
641 /// Get offset value of bgtrack's high indicator side.
643 private int GetBgTrackHighIndicatorOffset()
645 int bgTrackHighIndicatorOffset = 0;
646 IndicatorType type = CurrentIndicatorType();
648 if (type == IndicatorType.None)
650 if (direction == DirectionType.Horizontal)
652 bgTrackHighIndicatorOffset = (int)(thumbImage.Size.Width * 0.5f);
654 else if (direction == DirectionType.Vertical)
656 bgTrackHighIndicatorOffset = (int)(thumbImage.Size.Height * 0.5f);
659 else if (type == IndicatorType.Image || type == IndicatorType.Text)
660 {// <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage or Text>
661 Size highIndicatorSize = (type == IndicatorType.Image) ? HighIndicatorImageSize() : HighIndicatorTextSize();
662 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
663 if (direction == DirectionType.Horizontal)
665 bgTrackHighIndicatorOffset = ((highIndicatorSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorSize.Width)));
667 else if (direction == DirectionType.Vertical)
669 bgTrackHighIndicatorOffset = ((highIndicatorSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorSize.Height)));
672 return bgTrackHighIndicatorOffset;
675 private void UpdateLowIndicatorSize()
677 if (lowIndicatorSize != null)
679 if (lowIndicatorImage != null)
681 lowIndicatorImage.Size = lowIndicatorSize;
683 if (lowIndicatorText != null)
685 lowIndicatorText.Size = lowIndicatorSize;
690 if (lowIndicatorImage != null && lowIndicatorImage.Size != null)
692 lowIndicatorImage.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicatorImage.Size;
694 if (lowIndicatorText != null && lowIndicatorText.Size != null)
696 lowIndicatorText.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicator.Size;
701 private void UpdateHighIndicatorSize()
703 if (highIndicatorSize != null)
705 if (highIndicatorImage != null)
707 highIndicatorImage.Size = highIndicatorSize;
709 if (highIndicatorText != null)
711 highIndicatorText.Size = highIndicatorSize;
716 if (highIndicatorImage != null && highIndicatorImage.Size != null)
718 highIndicatorImage.Size = highIndicatorSize ?? (ViewStyle as SliderStyle)?.HighIndicatorImage.Size;
720 if (highIndicatorText != null && highIndicatorText.Size != null)
722 highIndicatorText.Size = highIndicatorSize ?? (ViewStyle as SliderStyle)?.HighIndicator.Size;
727 private void UpdateBgTrackSize()
729 if (bgTrackImage == null)
733 int curTrackThickness = (int)CurrentTrackThickness();
734 int bgTrackLength = GetBgTrackLength();
735 if (direction == DirectionType.Horizontal)
737 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
739 else if (direction == DirectionType.Vertical)
741 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
745 private void UpdateBgTrackPosition()
747 if (bgTrackImage == null)
752 int lowIndicatorOffset = GetBgTrackLowIndicatorOffset();
753 int highIndicatorOffet = GetBgTrackHighIndicatorOffset();
755 if (direction == DirectionType.Horizontal)
757 bgTrackImage.Position2D = new Position2D((lowIndicatorOffset - highIndicatorOffet) / 2, 0);
759 else if (direction == DirectionType.Vertical)
761 bgTrackImage.Position2D = new Position2D(0, (highIndicatorOffet - lowIndicatorOffset) / 2);
765 private void UpdateValue()
767 if (slidedTrackImage == null)
771 if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
777 ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
779 uint curTrackThickness = CurrentTrackThickness();
781 if (direction == DirectionType.Horizontal)
783 if (LayoutDirection == ViewLayoutDirectionType.RTL)
785 ratio = 1.0f - ratio;
787 float slidedTrackLength = (float)GetBgTrackLength() * ratio;
788 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
789 thumbImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
790 thumbImage.RaiseToTop();
792 else if (direction == DirectionType.Vertical)
794 float slidedTrackLength = (float)GetBgTrackLength() * ratio;
795 slidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(slidedTrackLength + round)); //Add const round to reach Math.Round function.
796 thumbImage.Position = new Position(0, -slidedTrackImage.Size2D.Height);
797 thumbImage.RaiseToTop();
800 // Update the track and thumb when the value is over warning value.
801 if (curValue >= warningStartValue)
803 if (direction == DirectionType.Horizontal)
805 warningSlidedTrackImage.Size2D = new Size2D((int)(((curValue - warningStartValue) / 100) * this.Size2D.Width), (int)curTrackThickness);
807 else if (direction == DirectionType.Vertical)
809 warningSlidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(((curValue - warningStartValue) / 100) * this.Size2D.Height));
812 if (warningThumbColor != null && thumbImage.Color.NotEqualTo(warningThumbColor))
814 thumbImage.Color = warningThumbColor;
816 if (warningThumbImageUrl != null && !thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
818 thumbImage.ResourceUrl = warningThumbImageUrl;
823 warningSlidedTrackImage.Size2D = new Size2D(0, 0);
824 if (warningThumbColor != null && thumbImage.Color.EqualTo(warningThumbColor))
826 thumbImage.Color = thumbColor;
828 if (warningThumbImageUrl != null && thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
830 thumbImage.ResourceUrl = thumbImageUrl;
835 private uint CurrentTrackThickness()
837 uint curTrackThickness = 0;
838 if (trackThickness != null)
840 curTrackThickness = trackThickness.Value;
844 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackThickness != null)
846 curTrackThickness = sliderStyle.TrackThickness.Value;
849 return curTrackThickness;
852 private uint CurrentSpaceBetweenTrackAndIndicator()
855 if (spaceBetweenTrackAndIndicator != null)
857 curSpace = spaceBetweenTrackAndIndicator.Start;
861 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackPadding != null)
863 curSpace = sliderStyle.TrackPadding.Start;
869 private void UpdateWarningTrackSize()
871 if (warningTrackImage == null)
876 int curTrackThickness = (int)CurrentTrackThickness();
877 float warningTrackLength = maxValue - warningStartValue;
878 if (direction == DirectionType.Horizontal)
880 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Width;
881 warningTrackImage.Size2D = new Size2D((int)warningTrackLength, curTrackThickness);
883 else if (direction == DirectionType.Vertical)
885 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Height;
886 warningTrackImage.Size2D = new Size2D(curTrackThickness, (int)warningTrackLength);
890 private IndicatorType CurrentIndicatorType()
892 IndicatorType type = IndicatorType.None;
893 if (ViewStyle is SliderStyle sliderStyle)
895 type = (IndicatorType)sliderStyle.IndicatorType;
900 private Size LowIndicatorImageSize()
902 Size size = new Size(0, 0);
903 if (lowIndicatorSize != null)
905 size = lowIndicatorSize;
909 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null)
911 size = sliderStyle.LowIndicatorImage.Size;
917 private Size HighIndicatorImageSize()
919 Size size = new Size(0, 0);
920 if (highIndicatorSize != null)
922 size = highIndicatorSize;
926 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null)
928 size = sliderStyle.HighIndicatorImage.Size;
934 private Size LowIndicatorTextSize()
936 Size size = new Size(0, 0);
937 if (lowIndicatorSize != null)
939 size = lowIndicatorSize;
943 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null)
945 size = sliderStyle.LowIndicator.Size;
951 private Size HighIndicatorTextSize()
953 Size size = new Size(0, 0);
954 if (highIndicatorSize != null)
956 size = highIndicatorSize;
960 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null)
962 size = sliderStyle.HighIndicator.Size;