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 float currentSlidedOffset;
89 private EventHandler<SliderValueChangedEventArgs> sliderValueChangedHandler;
90 private EventHandler<SliderSlidingStartedEventArgs> sliderSlidingStartedHandler;
91 private EventHandler<SliderSlidingFinishedEventArgs> sliderSlidingFinishedHandler;
93 bool isFocused = false;
94 bool isPressed = false;
96 private void Initialize()
98 AccessibilityHighlightable = true;
100 currentSlidedOffset = 0;
103 LayoutDirectionChanged += OnLayoutDirectionChanged;
105 this.TouchEvent += OnTouchEventForTrack;
107 panGestureDetector = new PanGestureDetector();
108 panGestureDetector.Attach(this);
109 panGestureDetector.Detected += OnPanGestureDetected;
111 this.Layout = new LinearLayout()
113 LinearOrientation = LinearLayout.Orientation.Horizontal,
117 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
122 private ImageView CreateSlidedTrack()
124 if (null == slidedTrackImage)
126 slidedTrackImage = new ImageView()
128 WidthResizePolicy = ResizePolicyType.Fixed,
129 HeightResizePolicy = ResizePolicyType.Fixed,
130 AccessibilityHidden = true,
133 if (bgTrackImage != null)
135 bgTrackImage.Add(slidedTrackImage);
139 return slidedTrackImage;
142 private ImageView CreateWarningTrack()
144 if (null == warningTrackImage)
146 warningTrackImage = new ImageView()
148 WidthResizePolicy = ResizePolicyType.Fixed,
149 HeightResizePolicy = ResizePolicyType.Fixed,
150 AccessibilityHidden = true,
153 if (bgTrackImage != null)
155 bgTrackImage.Add(warningTrackImage);
158 if (warningSlidedTrackImage != null)
160 warningTrackImage.Add(warningSlidedTrackImage);
163 if (slidedTrackImage != null)
165 warningTrackImage.RaiseAbove(slidedTrackImage);
169 return warningTrackImage;
172 private ImageView CreateWarningSlidedTrack()
174 if (null == warningSlidedTrackImage)
176 warningSlidedTrackImage = new ImageView()
178 WidthResizePolicy = ResizePolicyType.Fixed,
179 HeightResizePolicy = ResizePolicyType.Fixed,
180 AccessibilityHidden = true,
183 if (warningTrackImage != null)
185 warningTrackImage.Add(warningSlidedTrackImage);
189 return warningSlidedTrackImage;
192 private TextLabel CreateLowIndicatorText()
194 if (null == lowIndicatorText)
196 lowIndicatorText = new TextLabel()
198 WidthResizePolicy = ResizePolicyType.Fixed,
199 HeightResizePolicy = ResizePolicyType.Fixed,
200 AccessibilityHidden = true,
202 this.Add(lowIndicatorText);
205 return lowIndicatorText;
208 private TextLabel CreateHighIndicatorText()
210 if (null == highIndicatorText)
212 highIndicatorText = new TextLabel()
214 WidthResizePolicy = ResizePolicyType.Fixed,
215 HeightResizePolicy = ResizePolicyType.Fixed,
216 AccessibilityHidden = true,
218 this.Add(highIndicatorText);
221 return highIndicatorText;
224 private ImageView CreateBackgroundTrack()
226 if (null == bgTrackImage)
228 bgTrackImage = new ImageView()
230 WidthResizePolicy = ResizePolicyType.Fixed,
231 HeightResizePolicy = ResizePolicyType.Fixed,
232 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
233 PivotPoint = Tizen.NUI.PivotPoint.Center,
234 PositionUsesPivotPoint = true,
235 AccessibilityHidden = true,
237 this.Add(bgTrackImage);
239 if (null != slidedTrackImage)
241 bgTrackImage.Add(slidedTrackImage);
243 if (null != warningTrackImage)
245 bgTrackImage.Add(warningTrackImage);
247 if (null != thumbImage)
249 bgTrackImage.Add(thumbImage);
250 thumbImage.RaiseToTop();
257 private ImageView CreateThumb()
259 if (null == thumbImage)
261 thumbImage = new ImageView()
263 WidthResizePolicy = ResizePolicyType.Fixed,
264 HeightResizePolicy = ResizePolicyType.Fixed,
265 ParentOrigin = NUI.ParentOrigin.Center,
266 PivotPoint = NUI.PivotPoint.Center,
267 PositionUsesPivotPoint = true,
268 EnableControlState = true,
269 AccessibilityHidden = true,
271 if (bgTrackImage != null)
273 bgTrackImage.Add(thumbImage);
275 thumbImage.RaiseToTop();
276 thumbImage.TouchEvent += OnTouchEventForThumb;
282 private ImageView CreateValueIndicator()
284 if (valueIndicatorImage == null)
286 valueIndicatorImage = new ImageView()
288 PositionUsesPivotPoint = true,
289 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
290 PivotPoint = Tizen.NUI.PivotPoint.Center,
291 WidthResizePolicy = ResizePolicyType.Fixed,
292 HeightResizePolicy = ResizePolicyType.Fixed,
293 AccessibilityHidden = true,
295 if (valueIndicatorText != null)
297 valueIndicatorImage.Add(valueIndicatorText);
299 // TODO : ValueIndicator can be a child of Thumb
300 this.Add(valueIndicatorImage);
303 valueIndicatorImage.Hide();
304 return valueIndicatorImage;
307 private TextLabel CreateValueIndicatorText()
309 if (null == valueIndicatorText)
311 valueIndicatorText = new TextLabel()
313 WidthResizePolicy = ResizePolicyType.Fixed,
314 HeightResizePolicy = ResizePolicyType.Fixed,
315 AccessibilityHidden = true,
317 if (valueIndicatorImage != null)
319 valueIndicatorImage.Add(valueIndicatorText);
323 return valueIndicatorText;
326 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
328 if (e.PanGesture.State == Gesture.StateType.Started)
330 if (direction == DirectionType.Horizontal)
332 currentSlidedOffset = slidedTrackImage.SizeWidth;
334 else if (direction == DirectionType.Vertical)
336 currentSlidedOffset = slidedTrackImage.SizeHeight;
341 valueIndicatorImage.Show();
344 if (null != sliderSlidingStartedHandler)
346 SliderSlidingStartedEventArgs args = new SliderSlidingStartedEventArgs();
347 args.CurrentValue = curValue;
348 sliderSlidingStartedHandler(this, args);
350 UpdateState(isFocused, true);
353 if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
355 if (direction == DirectionType.Horizontal)
357 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
359 else if (direction == DirectionType.Vertical)
361 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
366 if (e.PanGesture.State == Gesture.StateType.Finished)
370 valueIndicatorImage.Hide();
373 if (null != sliderSlidingFinishedHandler)
375 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
376 args.CurrentValue = curValue;
377 sliderSlidingFinishedHandler(this, args);
380 UpdateState(isFocused, false);
384 // Relayout basic component: track, thumb and indicator
385 private void RelayoutBaseComponent(bool isInitial = true)
387 if (direction == DirectionType.Horizontal)
389 if (slidedTrackImage != null)
391 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
392 slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
393 slidedTrackImage.PositionUsesPivotPoint = true;
395 if (warningTrackImage != null)
397 warningTrackImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
398 warningTrackImage.PivotPoint = NUI.PivotPoint.CenterRight;
399 warningTrackImage.PositionUsesPivotPoint = true;
401 if (warningSlidedTrackImage != null)
403 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
404 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
405 warningSlidedTrackImage.PositionUsesPivotPoint = true;
407 if (thumbImage != null)
409 thumbImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
410 thumbImage.PivotPoint = NUI.PivotPoint.Center;
411 thumbImage.PositionUsesPivotPoint = true;
413 if (lowIndicatorImage != null)
415 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
416 lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
417 lowIndicatorImage.PositionUsesPivotPoint = true;
419 if (highIndicatorImage != null)
421 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
422 highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
423 highIndicatorImage.PositionUsesPivotPoint = true;
425 if (lowIndicatorText != null)
427 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
428 lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
429 lowIndicatorText.PositionUsesPivotPoint = true;
431 if (highIndicatorText != null)
433 highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
434 highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
435 highIndicatorText.PositionUsesPivotPoint = true;
437 if (valueIndicatorImage != null)
439 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopLeft;
440 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
441 valueIndicatorImage.PositionUsesPivotPoint = true;
443 if (valueIndicatorText != null)
445 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
446 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
447 valueIndicatorText.PositionUsesPivotPoint = true;
448 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
450 if (panGestureDetector != null)
454 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
456 panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
459 else if (direction == DirectionType.Vertical)
461 if (slidedTrackImage != null)
463 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
464 slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
465 slidedTrackImage.PositionUsesPivotPoint = true;
467 if (warningTrackImage != null)
469 warningTrackImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
470 warningTrackImage.PivotPoint = NUI.PivotPoint.TopCenter;
471 warningTrackImage.PositionUsesPivotPoint = true;
473 if (warningSlidedTrackImage != null)
475 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
476 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
477 warningSlidedTrackImage.PositionUsesPivotPoint = true;
479 if (thumbImage != null)
481 thumbImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
482 thumbImage.PivotPoint = NUI.PivotPoint.Center;
483 thumbImage.PositionUsesPivotPoint = true;
485 if (lowIndicatorImage != null)
487 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
488 lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
489 lowIndicatorImage.PositionUsesPivotPoint = true;
491 if (highIndicatorImage != null)
493 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
494 highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
495 highIndicatorImage.PositionUsesPivotPoint = true;
497 if (lowIndicatorText != null)
499 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
500 lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
501 lowIndicatorText.PositionUsesPivotPoint = true;
503 if (highIndicatorText != null)
505 highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
506 highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
507 highIndicatorText.PositionUsesPivotPoint = true;
509 if (valueIndicatorImage != null)
511 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
512 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
513 valueIndicatorImage.PositionUsesPivotPoint = true;
515 if (valueIndicatorText != null)
517 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
518 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
519 valueIndicatorText.PositionUsesPivotPoint = true;
520 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
522 if (panGestureDetector != null)
526 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
528 panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
533 private int BgTrackLength()
535 int bgTrackLength = 0;
536 IndicatorType type = CurrentIndicatorType();
538 if (type == IndicatorType.None)
540 if (direction == DirectionType.Horizontal)
542 bgTrackLength = this.Size2D.Width - thumbImage.Size2D.Width;
544 else if (direction == DirectionType.Vertical)
546 bgTrackLength = this.Size2D.Height - thumbImage.Size2D.Height;
549 else if (type == IndicatorType.Image)
550 {// <lowIndicatorImage> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage>
551 Size lowIndicatorImageSize = LowIndicatorImageSize();
552 Size highIndicatorImageSize = HighIndicatorImageSize();
553 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
554 if (direction == DirectionType.Horizontal)
556 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
557 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
558 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
560 else if (direction == DirectionType.Vertical)
562 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
563 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
564 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
567 else if (type == IndicatorType.Text)
568 {// <lowIndicatorText> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorText>
569 Size lowIndicatorTextSize = LowIndicatorTextSize();
570 Size highIndicatorTextSize = HighIndicatorTextSize();
571 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
572 if (direction == DirectionType.Horizontal)
574 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
575 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
576 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
578 else if (direction == DirectionType.Vertical)
580 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
581 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
582 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
585 return bgTrackLength;
588 private void UpdateLowIndicatorSize()
590 if (lowIndicatorSize != null)
592 if (lowIndicatorImage != null)
594 lowIndicatorImage.Size = lowIndicatorSize;
596 if (lowIndicatorText != null)
598 lowIndicatorText.Size = lowIndicatorSize;
603 if (lowIndicatorImage != null && lowIndicatorImage != null && lowIndicatorImage.Size != null)
605 lowIndicatorImage.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicatorImage.Size;
607 if (lowIndicatorText != null && lowIndicatorText != null && lowIndicatorText.Size != null)
609 lowIndicatorText.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicator.Size;
614 private void UpdateBgTrackSize()
616 if (bgTrackImage == null)
620 int curTrackThickness = (int)CurrentTrackThickness();
621 int bgTrackLength = BgTrackLength();
622 if (direction == DirectionType.Horizontal)
624 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
626 else if (direction == DirectionType.Vertical)
628 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
632 private void UpdateBgTrackPosition()
634 if (bgTrackImage == null)
638 IndicatorType type = CurrentIndicatorType();
640 if (type == IndicatorType.None)
642 bgTrackImage.Position2D = new Position2D(0, 0);
644 else if (type == IndicatorType.Image)
646 Size lowIndicatorImageSize = LowIndicatorImageSize();
647 Size highIndicatorImageSize = HighIndicatorImageSize();
648 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
649 if (direction == DirectionType.Horizontal)
651 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
652 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
653 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
655 else if (direction == DirectionType.Vertical)
657 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
658 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
659 bgTrackImage.Position2D = new Position2D(0, lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2);
662 else if (type == IndicatorType.Text)
664 Size lowIndicatorTextSize = LowIndicatorTextSize();
665 Size highIndicatorTextSize = HighIndicatorTextSize();
666 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
667 if (direction == DirectionType.Horizontal)
669 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
670 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
671 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
673 else if (direction == DirectionType.Vertical)
675 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
676 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
677 bgTrackImage.Position2D = new Position2D(0, -(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2));
682 private void UpdateValue()
684 if (slidedTrackImage == null)
688 if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
694 ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
696 uint curTrackThickness = CurrentTrackThickness();
698 if (direction == DirectionType.Horizontal)
700 if (LayoutDirection == ViewLayoutDirectionType.RTL)
702 ratio = 1.0f - ratio;
704 float slidedTrackLength = (float)BgTrackLength() * ratio;
705 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
706 thumbImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
707 thumbImage.RaiseToTop();
711 valueIndicatorImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
714 else if (direction == DirectionType.Vertical)
716 float slidedTrackLength = (float)BgTrackLength() * ratio;
717 slidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(slidedTrackLength + round)); //Add const round to reach Math.Round function.
718 thumbImage.Position = new Position(0, -slidedTrackImage.Size2D.Height);
719 thumbImage.RaiseToTop();
723 valueIndicatorImage.Position = new Position(0, -(slidedTrackImage.Size2D.Height + thumbImage.Size.Height / 2));
727 // Update the track and thumb when the value is over warning value.
728 if (curValue >= warningStartValue)
730 if (direction == DirectionType.Horizontal)
732 warningSlidedTrackImage.Size2D = new Size2D((int)(((curValue - warningStartValue) / 100) * this.Size2D.Width), (int)curTrackThickness);
734 else if (direction == DirectionType.Vertical)
736 warningSlidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(((curValue - warningStartValue) / 100) * this.Size2D.Height));
739 if (warningThumbColor != null && thumbImage.Color.NotEqualTo(warningThumbColor))
741 thumbImage.Color = warningThumbColor;
743 if (warningThumbImageUrl != null && !thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
745 thumbImage.ResourceUrl = warningThumbImageUrl;
750 warningSlidedTrackImage.Size2D = new Size2D(0, 0);
751 if (warningThumbColor != null && thumbImage.Color.EqualTo(warningThumbColor))
753 thumbImage.Color = thumbColor;
755 if (warningThumbImageUrl != null && thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
757 thumbImage.ResourceUrl = thumbImageUrl;
762 private uint CurrentTrackThickness()
764 uint curTrackThickness = 0;
765 if (trackThickness != null)
767 curTrackThickness = trackThickness.Value;
771 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackThickness != null)
773 curTrackThickness = sliderStyle.TrackThickness.Value;
776 return curTrackThickness;
779 private uint CurrentSpaceBetweenTrackAndIndicator()
782 if (spaceBetweenTrackAndIndicator != null)
784 curSpace = spaceBetweenTrackAndIndicator.Start;
788 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackPadding != null)
790 curSpace = sliderStyle.TrackPadding.Start;
796 private void UpdateWarningTrackSize()
798 if (warningTrackImage == null)
803 int curTrackThickness = (int)CurrentTrackThickness();
804 float warningTrackLength = maxValue - warningStartValue;
805 if (direction == DirectionType.Horizontal)
807 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Width;
808 warningTrackImage.Size2D = new Size2D((int)warningTrackLength, curTrackThickness);
810 else if (direction == DirectionType.Vertical)
812 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Height;
813 warningTrackImage.Size2D = new Size2D(curTrackThickness, (int)warningTrackLength);
817 private IndicatorType CurrentIndicatorType()
819 IndicatorType type = IndicatorType.None;
820 if (ViewStyle is SliderStyle sliderStyle)
822 type = (IndicatorType)sliderStyle.IndicatorType;
827 private Size LowIndicatorImageSize()
829 Size size = new Size(0, 0);
830 if (lowIndicatorSize != null)
832 size = lowIndicatorSize;
836 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null)
838 size = sliderStyle.LowIndicatorImage.Size;
844 private Size HighIndicatorImageSize()
846 Size size = new Size(0, 0);
847 if (highIndicatorSize != null)
849 size = highIndicatorSize;
853 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null)
855 size = sliderStyle.HighIndicatorImage.Size;
861 private Size LowIndicatorTextSize()
863 Size size = new Size(0, 0);
864 if (lowIndicatorSize != null)
866 size = lowIndicatorSize;
870 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null)
872 size = sliderStyle.LowIndicator.Size;
878 private Size HighIndicatorTextSize()
880 Size size = new Size(0, 0);
881 if (highIndicatorSize != null)
883 size = highIndicatorSize;
887 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null)
889 size = sliderStyle.HighIndicator.Size;