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 ParentOrigin = NUI.ParentOrigin.Center,
304 PivotPoint = NUI.PivotPoint.Center,
305 PositionUsesPivotPoint = true,
306 EnableControlState = true,
307 GrabTouchAfterLeave = true,
308 AccessibilityHidden = true,
310 if (bgTrackImage != null)
312 bgTrackImage.Add(thumbImage);
314 thumbImage.RaiseToTop();
315 thumbImage.TouchEvent += OnTouchEventForThumb;
321 private ImageView CreateValueIndicatorImage()
323 if (valueIndicatorImage == null)
325 valueIndicatorImage = new ImageView()
327 PositionUsesPivotPoint = true,
328 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
329 PivotPoint = Tizen.NUI.PivotPoint.Center,
330 WidthResizePolicy = ResizePolicyType.Fixed,
331 HeightResizePolicy = ResizePolicyType.Fixed,
332 AccessibilityHidden = true,
334 if (valueIndicatorText != null)
336 valueIndicatorImage.Add(valueIndicatorText);
338 // TODO : ValueIndicator can be a child of Thumb
339 this.Add(valueIndicatorImage);
342 valueIndicatorImage.Hide();
343 return valueIndicatorImage;
346 private TextLabel CreateValueIndicatorText()
348 if (null == valueIndicatorText)
350 valueIndicatorText = new TextLabel()
352 WidthResizePolicy = ResizePolicyType.Fixed,
353 HeightResizePolicy = ResizePolicyType.Fixed,
354 AccessibilityHidden = true,
356 if (valueIndicatorImage != null)
358 valueIndicatorImage.Add(valueIndicatorText);
362 return valueIndicatorText;
365 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
367 if (e.PanGesture.State == Gesture.StateType.Started)
369 if (direction == DirectionType.Horizontal)
371 currentSlidedOffset = slidedTrackImage.SizeWidth;
373 else if (direction == DirectionType.Vertical)
375 currentSlidedOffset = slidedTrackImage.SizeHeight;
380 valueIndicatorImage.Show();
383 if (null != sliderSlidingStartedHandler)
385 SliderSlidingStartedEventArgs args = new SliderSlidingStartedEventArgs();
386 args.CurrentValue = curValue;
387 sliderSlidingStartedHandler(this, args);
389 UpdateState(isFocused, true);
392 if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
394 if (direction == DirectionType.Horizontal)
396 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
398 else if (direction == DirectionType.Vertical)
400 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
402 UpdateState(isFocused, true);
406 if (e.PanGesture.State == Gesture.StateType.Finished)
408 // Update as finished position value
409 if (direction == DirectionType.Horizontal)
411 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
413 else if (direction == DirectionType.Vertical)
415 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
421 valueIndicatorImage.Hide();
424 if (null != sliderSlidingFinishedHandler)
426 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
427 args.CurrentValue = curValue;
428 sliderSlidingFinishedHandler(this, args);
431 UpdateState(isFocused, false);
435 // Relayout basic component: track, thumb and indicator
436 private void RelayoutBaseComponent(bool isInitial = true)
438 if (direction == DirectionType.Horizontal)
440 if (slidedTrackImage != null)
442 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
443 slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
444 slidedTrackImage.PositionUsesPivotPoint = true;
446 if (warningTrackImage != null)
448 warningTrackImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
449 warningTrackImage.PivotPoint = NUI.PivotPoint.CenterRight;
450 warningTrackImage.PositionUsesPivotPoint = true;
452 if (warningSlidedTrackImage != null)
454 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
455 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
456 warningSlidedTrackImage.PositionUsesPivotPoint = true;
458 if (thumbImage != null)
460 thumbImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
461 thumbImage.PivotPoint = NUI.PivotPoint.Center;
462 thumbImage.PositionUsesPivotPoint = true;
464 if (lowIndicatorImage != null)
466 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
467 lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
468 lowIndicatorImage.PositionUsesPivotPoint = true;
470 if (highIndicatorImage != null)
472 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
473 highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
474 highIndicatorImage.PositionUsesPivotPoint = true;
476 if (lowIndicatorText != null)
478 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
479 lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
480 lowIndicatorText.PositionUsesPivotPoint = true;
482 if (highIndicatorText != null)
484 highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
485 highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
486 highIndicatorText.PositionUsesPivotPoint = true;
488 if (valueIndicatorImage != null)
490 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopLeft;
491 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
492 valueIndicatorImage.PositionUsesPivotPoint = true;
494 if (valueIndicatorText != null)
496 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
497 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
498 valueIndicatorText.PositionUsesPivotPoint = true;
499 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
501 if (panGestureDetector != null)
505 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
507 panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
510 else if (direction == DirectionType.Vertical)
512 if (slidedTrackImage != null)
514 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
515 slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
516 slidedTrackImage.PositionUsesPivotPoint = true;
518 if (warningTrackImage != null)
520 warningTrackImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
521 warningTrackImage.PivotPoint = NUI.PivotPoint.TopCenter;
522 warningTrackImage.PositionUsesPivotPoint = true;
524 if (warningSlidedTrackImage != null)
526 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
527 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
528 warningSlidedTrackImage.PositionUsesPivotPoint = true;
530 if (thumbImage != null)
532 thumbImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
533 thumbImage.PivotPoint = NUI.PivotPoint.Center;
534 thumbImage.PositionUsesPivotPoint = true;
536 if (lowIndicatorImage != null)
538 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
539 lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
540 lowIndicatorImage.PositionUsesPivotPoint = true;
542 if (highIndicatorImage != null)
544 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
545 highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
546 highIndicatorImage.PositionUsesPivotPoint = true;
548 if (lowIndicatorText != null)
550 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
551 lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
552 lowIndicatorText.PositionUsesPivotPoint = true;
554 if (highIndicatorText != null)
556 highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
557 highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
558 highIndicatorText.PositionUsesPivotPoint = true;
560 if (valueIndicatorImage != null)
562 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
563 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
564 valueIndicatorImage.PositionUsesPivotPoint = true;
566 if (valueIndicatorText != null)
568 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
569 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
570 valueIndicatorText.PositionUsesPivotPoint = true;
571 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
573 if (panGestureDetector != null)
577 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
579 panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
584 private int GetBgTrackLength()
586 int bgTrackLength = 0;
588 int lowIndicatorOffset = GetBgTrackLowIndicatorOffset();
589 int highIndicatorOffet = GetBgTrackHighIndicatorOffset();
591 if (direction == DirectionType.Horizontal)
593 bgTrackLength = this.Size2D.Width - lowIndicatorOffset - highIndicatorOffet;
595 else if (direction == DirectionType.Vertical)
597 bgTrackLength = this.Size2D.Height - lowIndicatorOffset - highIndicatorOffet;
600 return bgTrackLength;
604 /// Get offset value of bgtrack's low indicator side.
606 private int GetBgTrackLowIndicatorOffset()
608 int bgTrackLowIndicatorOffset = 0;
609 IndicatorType type = CurrentIndicatorType();
611 if (type == IndicatorType.None)
613 if (direction == DirectionType.Horizontal)
615 bgTrackLowIndicatorOffset = (int)(thumbImage.Size.Width * 0.5f);
617 else if (direction == DirectionType.Vertical)
619 bgTrackLowIndicatorOffset = (int)(thumbImage.Size.Height * 0.5f);
622 else if (type == IndicatorType.Image || type == IndicatorType.Text)
623 {// <lowIndicatorImage or Text> <spaceBetweenTrackAndIndicator> <bgTrack>
624 Size lowIndicatorSize = (type == IndicatorType.Image) ? LowIndicatorImageSize() : LowIndicatorTextSize();
625 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
626 if (direction == DirectionType.Horizontal)
628 bgTrackLowIndicatorOffset = ((lowIndicatorSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorSize.Width)));
630 else if (direction == DirectionType.Vertical)
632 bgTrackLowIndicatorOffset = ((lowIndicatorSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorSize.Height)));
635 return bgTrackLowIndicatorOffset;
639 /// Get offset value of bgtrack's high indicator side.
641 private int GetBgTrackHighIndicatorOffset()
643 int bgTrackHighIndicatorOffset = 0;
644 IndicatorType type = CurrentIndicatorType();
646 if (type == IndicatorType.None)
648 if (direction == DirectionType.Horizontal)
650 bgTrackHighIndicatorOffset = (int)(thumbImage.Size.Width * 0.5f);
652 else if (direction == DirectionType.Vertical)
654 bgTrackHighIndicatorOffset = (int)(thumbImage.Size.Height * 0.5f);
657 else if (type == IndicatorType.Image || type == IndicatorType.Text)
658 {// <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage or Text>
659 Size highIndicatorSize = (type == IndicatorType.Image) ? HighIndicatorImageSize() : HighIndicatorTextSize();
660 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
661 if (direction == DirectionType.Horizontal)
663 bgTrackHighIndicatorOffset = ((highIndicatorSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorSize.Width)));
665 else if (direction == DirectionType.Vertical)
667 bgTrackHighIndicatorOffset = ((highIndicatorSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorSize.Height)));
670 return bgTrackHighIndicatorOffset;
673 private void UpdateLowIndicatorSize()
675 if (lowIndicatorSize != null)
677 if (lowIndicatorImage != null)
679 lowIndicatorImage.Size = lowIndicatorSize;
681 if (lowIndicatorText != null)
683 lowIndicatorText.Size = lowIndicatorSize;
688 if (lowIndicatorImage != null && lowIndicatorImage.Size != null)
690 lowIndicatorImage.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicatorImage.Size;
692 if (lowIndicatorText != null && lowIndicatorText.Size != null)
694 lowIndicatorText.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicator.Size;
699 private void UpdateHighIndicatorSize()
701 if (highIndicatorSize != null)
703 if (highIndicatorImage != null)
705 highIndicatorImage.Size = highIndicatorSize;
707 if (highIndicatorText != null)
709 highIndicatorText.Size = highIndicatorSize;
714 if (highIndicatorImage != null && highIndicatorImage.Size != null)
716 highIndicatorImage.Size = highIndicatorSize ?? (ViewStyle as SliderStyle)?.HighIndicatorImage.Size;
718 if (highIndicatorText != null && highIndicatorText.Size != null)
720 highIndicatorText.Size = highIndicatorSize ?? (ViewStyle as SliderStyle)?.HighIndicator.Size;
725 private void UpdateBgTrackSize()
727 if (bgTrackImage == null)
731 int curTrackThickness = (int)CurrentTrackThickness();
732 int bgTrackLength = GetBgTrackLength();
733 if (direction == DirectionType.Horizontal)
735 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
737 else if (direction == DirectionType.Vertical)
739 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
743 private void UpdateBgTrackPosition()
745 if (bgTrackImage == null)
750 int lowIndicatorOffset = GetBgTrackLowIndicatorOffset();
751 int highIndicatorOffet = GetBgTrackHighIndicatorOffset();
753 if (direction == DirectionType.Horizontal)
755 bgTrackImage.Position2D = new Position2D((lowIndicatorOffset - highIndicatorOffet) / 2, 0);
757 else if (direction == DirectionType.Vertical)
759 bgTrackImage.Position2D = new Position2D(0, (highIndicatorOffet - lowIndicatorOffset) / 2);
763 private void UpdateValue()
765 if (slidedTrackImage == null)
769 if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
775 ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
777 uint curTrackThickness = CurrentTrackThickness();
779 if (direction == DirectionType.Horizontal)
781 if (LayoutDirection == ViewLayoutDirectionType.RTL)
783 ratio = 1.0f - ratio;
785 float slidedTrackLength = (float)GetBgTrackLength() * ratio;
786 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
787 thumbImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
788 thumbImage.RaiseToTop();
792 valueIndicatorImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
795 else if (direction == DirectionType.Vertical)
797 float slidedTrackLength = (float)GetBgTrackLength() * ratio;
798 slidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(slidedTrackLength + round)); //Add const round to reach Math.Round function.
799 thumbImage.Position = new Position(0, -slidedTrackImage.Size2D.Height);
800 thumbImage.RaiseToTop();
804 valueIndicatorImage.Position = new Position(0, -(slidedTrackImage.Size2D.Height + thumbImage.Size.Height / 2));
808 // Update the track and thumb when the value is over warning value.
809 if (curValue >= warningStartValue)
811 if (direction == DirectionType.Horizontal)
813 warningSlidedTrackImage.Size2D = new Size2D((int)(((curValue - warningStartValue) / 100) * this.Size2D.Width), (int)curTrackThickness);
815 else if (direction == DirectionType.Vertical)
817 warningSlidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(((curValue - warningStartValue) / 100) * this.Size2D.Height));
820 if (warningThumbColor != null && thumbImage.Color.NotEqualTo(warningThumbColor))
822 thumbImage.Color = warningThumbColor;
824 if (warningThumbImageUrl != null && !thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
826 thumbImage.ResourceUrl = warningThumbImageUrl;
831 warningSlidedTrackImage.Size2D = new Size2D(0, 0);
832 if (warningThumbColor != null && thumbImage.Color.EqualTo(warningThumbColor))
834 thumbImage.Color = thumbColor;
836 if (warningThumbImageUrl != null && thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
838 thumbImage.ResourceUrl = thumbImageUrl;
843 private uint CurrentTrackThickness()
845 uint curTrackThickness = 0;
846 if (trackThickness != null)
848 curTrackThickness = trackThickness.Value;
852 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackThickness != null)
854 curTrackThickness = sliderStyle.TrackThickness.Value;
857 return curTrackThickness;
860 private uint CurrentSpaceBetweenTrackAndIndicator()
863 if (spaceBetweenTrackAndIndicator != null)
865 curSpace = spaceBetweenTrackAndIndicator.Start;
869 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackPadding != null)
871 curSpace = sliderStyle.TrackPadding.Start;
877 private void UpdateWarningTrackSize()
879 if (warningTrackImage == null)
884 int curTrackThickness = (int)CurrentTrackThickness();
885 float warningTrackLength = maxValue - warningStartValue;
886 if (direction == DirectionType.Horizontal)
888 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Width;
889 warningTrackImage.Size2D = new Size2D((int)warningTrackLength, curTrackThickness);
891 else if (direction == DirectionType.Vertical)
893 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Height;
894 warningTrackImage.Size2D = new Size2D(curTrackThickness, (int)warningTrackLength);
898 private IndicatorType CurrentIndicatorType()
900 IndicatorType type = IndicatorType.None;
901 if (ViewStyle is SliderStyle sliderStyle)
903 type = (IndicatorType)sliderStyle.IndicatorType;
908 private Size LowIndicatorImageSize()
910 Size size = new Size(0, 0);
911 if (lowIndicatorSize != null)
913 size = lowIndicatorSize;
917 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null)
919 size = sliderStyle.LowIndicatorImage.Size;
925 private Size HighIndicatorImageSize()
927 Size size = new Size(0, 0);
928 if (highIndicatorSize != null)
930 size = highIndicatorSize;
934 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null)
936 size = sliderStyle.HighIndicatorImage.Size;
942 private Size LowIndicatorTextSize()
944 Size size = new Size(0, 0);
945 if (lowIndicatorSize != null)
947 size = lowIndicatorSize;
951 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null)
953 size = sliderStyle.LowIndicator.Size;
959 private Size HighIndicatorTextSize()
961 Size size = new Size(0, 0);
962 if (highIndicatorSize != null)
964 size = highIndicatorSize;
968 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null)
970 size = sliderStyle.HighIndicator.Size;