2 * Copyright(c) 2021 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 image url selector of normal state
77 private Selector<string> thumbImageUrlSelector = null;
78 // To store the thumb color of normal state
79 private Color thumbColor = Color.White;
80 // To store the thumb image url of warning state
81 private string warningThumbImageUrl = null;
82 // To store the thumb image url selector of warning state
83 private Selector<string> warningThumbImageUrlSelector = null;
84 // To store the thumb color of warning state
85 private Color warningThumbColor = null;
87 private float discreteValue = 0;
89 private PanGestureDetector panGestureDetector = null;
90 private float currentSlidedOffset;
91 private EventHandler<ValueChangedArgs> valueChangedHandler;
92 private EventHandler<SlidingFinishedArgs> slidingFinishedHandler;
93 private EventHandler<SliderValueChangedEventArgs> sliderValueChangedHandler;
94 private EventHandler<SliderSlidingStartedEventArgs> sliderSlidingStartedHandler;
95 private EventHandler<SliderSlidingFinishedEventArgs> sliderSlidingFinishedHandler;
96 private EventHandler<StateChangedArgs> stateChangedHandler;
98 bool isFocused = false;
99 bool isPressed = false;
101 private void Initialize()
103 AccessibilityHighlightable = true;
105 currentSlidedOffset = 0;
108 LayoutDirectionChanged += OnLayoutDirectionChanged;
110 panGestureDetector = new PanGestureDetector();
111 panGestureDetector.Attach(this);
112 panGestureDetector.Detected += OnPanGestureDetected;
115 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
120 private ImageView CreateSlidedTrack()
122 if (null == slidedTrackImage)
124 slidedTrackImage = new ImageView()
126 WidthResizePolicy = ResizePolicyType.Fixed,
127 HeightResizePolicy = ResizePolicyType.Fixed
130 if (bgTrackImage != null)
132 bgTrackImage.Add(slidedTrackImage);
136 return slidedTrackImage;
139 private ImageView CreateWarningTrack()
141 if (null == warningTrackImage)
143 warningTrackImage = new ImageView()
145 WidthResizePolicy = ResizePolicyType.Fixed,
146 HeightResizePolicy = ResizePolicyType.Fixed
149 if (bgTrackImage != null)
151 bgTrackImage.Add(warningTrackImage);
154 if (warningSlidedTrackImage != null)
156 warningTrackImage.Add(warningSlidedTrackImage);
159 if (slidedTrackImage != null)
161 warningTrackImage.RaiseAbove(slidedTrackImage);
165 return warningTrackImage;
168 private ImageView CreateWarningSlidedTrack()
170 if (null == warningSlidedTrackImage)
172 warningSlidedTrackImage = new ImageView()
174 WidthResizePolicy = ResizePolicyType.Fixed,
175 HeightResizePolicy = ResizePolicyType.Fixed
178 if (warningTrackImage != null)
180 warningTrackImage.Add(warningSlidedTrackImage);
184 return warningSlidedTrackImage;
187 private TextLabel CreateLowIndicatorText()
189 if (null == lowIndicatorText)
191 lowIndicatorText = new TextLabel()
193 WidthResizePolicy = ResizePolicyType.Fixed,
194 HeightResizePolicy = ResizePolicyType.Fixed
196 this.Add(lowIndicatorText);
199 return lowIndicatorText;
202 private TextLabel CreateHighIndicatorText()
204 if (null == highIndicatorText)
206 highIndicatorText = new TextLabel()
208 WidthResizePolicy = ResizePolicyType.Fixed,
209 HeightResizePolicy = ResizePolicyType.Fixed
211 this.Add(highIndicatorText);
214 return highIndicatorText;
217 private ImageView CreateBackgroundTrack()
219 if (null == bgTrackImage)
221 bgTrackImage = new ImageView()
223 WidthResizePolicy = ResizePolicyType.Fixed,
224 HeightResizePolicy = ResizePolicyType.Fixed,
225 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
226 PivotPoint = Tizen.NUI.PivotPoint.Center,
227 PositionUsesPivotPoint = true
229 this.Add(bgTrackImage);
231 if (null != slidedTrackImage)
233 bgTrackImage.Add(slidedTrackImage);
235 if (null != warningTrackImage)
237 bgTrackImage.Add(warningTrackImage);
239 if (null != thumbImage)
241 bgTrackImage.Add(thumbImage);
242 thumbImage.RaiseToTop();
245 bgTrackImage.TouchEvent += OnTouchEventForBgTrack;
251 private ImageView CreateThumb()
253 if (null == thumbImage)
255 thumbImage = new ImageView()
257 WidthResizePolicy = ResizePolicyType.Fixed,
258 HeightResizePolicy = ResizePolicyType.Fixed,
259 ParentOrigin = NUI.ParentOrigin.Center,
260 PivotPoint = NUI.PivotPoint.Center,
261 PositionUsesPivotPoint = true
263 if (bgTrackImage != null)
265 bgTrackImage.Add(thumbImage);
267 thumbImage.RaiseToTop();
268 thumbImage.TouchEvent += OnTouchEventForThumb;
274 private ImageView CreateValueIndicator()
276 if (valueIndicatorImage == null)
278 valueIndicatorImage = new ImageView()
280 PositionUsesPivotPoint = true,
281 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
282 PivotPoint = Tizen.NUI.PivotPoint.Center,
283 WidthResizePolicy = ResizePolicyType.Fixed,
284 HeightResizePolicy = ResizePolicyType.Fixed,
286 if (valueIndicatorText != null)
288 valueIndicatorImage.Add(valueIndicatorText);
290 // TODO : ValueIndicator can be a child of Thumb
291 this.Add(valueIndicatorImage);
294 valueIndicatorImage.Hide();
295 return valueIndicatorImage;
298 private TextLabel CreateValueIndicatorText()
300 if (null == valueIndicatorText)
302 valueIndicatorText = new TextLabel()
304 WidthResizePolicy = ResizePolicyType.Fixed,
305 HeightResizePolicy = ResizePolicyType.Fixed
307 if (valueIndicatorImage != null)
309 valueIndicatorImage.Add(valueIndicatorText);
313 return valueIndicatorText;
316 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
318 if (e.PanGesture.State == Gesture.StateType.Started)
320 if (direction == DirectionType.Horizontal)
322 currentSlidedOffset = slidedTrackImage.SizeWidth;
324 else if (direction == DirectionType.Vertical)
326 currentSlidedOffset = slidedTrackImage.SizeHeight;
331 valueIndicatorImage.Show();
334 if (null != sliderSlidingStartedHandler)
336 SliderSlidingStartedEventArgs args = new SliderSlidingStartedEventArgs();
337 args.CurrentValue = curValue;
338 sliderSlidingStartedHandler(this, args);
340 UpdateState(isFocused, true);
343 if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
345 if (direction == DirectionType.Horizontal)
347 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
349 else if (direction == DirectionType.Vertical)
351 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
356 if (e.PanGesture.State == Gesture.StateType.Finished)
360 valueIndicatorImage.Hide();
363 if (null != slidingFinishedHandler)
365 SlidingFinishedArgs args = new SlidingFinishedArgs();
366 args.CurrentValue = curValue;
367 slidingFinishedHandler(this, args);
370 if (null != sliderSlidingFinishedHandler)
372 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
373 args.CurrentValue = curValue;
374 sliderSlidingFinishedHandler(this, args);
377 UpdateState(isFocused, false);
381 // Relayout basic component: track, thumb and indicator
382 private void RelayoutBaseComponent(bool isInitial = true)
384 if (direction == DirectionType.Horizontal)
386 if (slidedTrackImage != null)
388 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
389 slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
390 slidedTrackImage.PositionUsesPivotPoint = true;
392 if (warningTrackImage != null)
394 warningTrackImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
395 warningTrackImage.PivotPoint = NUI.PivotPoint.CenterRight;
396 warningTrackImage.PositionUsesPivotPoint = true;
398 if (warningSlidedTrackImage != null)
400 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
401 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
402 warningSlidedTrackImage.PositionUsesPivotPoint = true;
404 if (thumbImage != null)
406 thumbImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
407 thumbImage.PivotPoint = NUI.PivotPoint.Center;
408 thumbImage.PositionUsesPivotPoint = true;
410 if (lowIndicatorImage != null)
412 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
413 lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
414 lowIndicatorImage.PositionUsesPivotPoint = true;
416 if (highIndicatorImage != null)
418 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
419 highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
420 highIndicatorImage.PositionUsesPivotPoint = true;
422 if (lowIndicatorText != null)
424 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
425 lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
426 lowIndicatorText.PositionUsesPivotPoint = true;
428 if (highIndicatorText != null)
430 highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
431 highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
432 highIndicatorText.PositionUsesPivotPoint = true;
434 if (valueIndicatorImage != null)
436 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopLeft;
437 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
438 valueIndicatorImage.PositionUsesPivotPoint = true;
440 if (valueIndicatorText != null)
442 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
443 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
444 valueIndicatorText.PositionUsesPivotPoint = true;
445 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
447 if (panGestureDetector != null)
451 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
453 panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
456 else if (direction == DirectionType.Vertical)
458 if (slidedTrackImage != null)
460 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
461 slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
462 slidedTrackImage.PositionUsesPivotPoint = true;
464 if (warningTrackImage != null)
466 warningTrackImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
467 warningTrackImage.PivotPoint = NUI.PivotPoint.TopCenter;
468 warningTrackImage.PositionUsesPivotPoint = true;
470 if (warningSlidedTrackImage != null)
472 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
473 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
474 warningSlidedTrackImage.PositionUsesPivotPoint = true;
476 if (thumbImage != null)
478 thumbImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
479 thumbImage.PivotPoint = NUI.PivotPoint.Center;
480 thumbImage.PositionUsesPivotPoint = true;
482 if (lowIndicatorImage != null)
484 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
485 lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
486 lowIndicatorImage.PositionUsesPivotPoint = true;
488 if (highIndicatorImage != null)
490 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
491 highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
492 highIndicatorImage.PositionUsesPivotPoint = true;
494 if (lowIndicatorText != null)
496 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
497 lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
498 lowIndicatorText.PositionUsesPivotPoint = true;
500 if (highIndicatorText != null)
502 highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
503 highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
504 highIndicatorText.PositionUsesPivotPoint = true;
506 if (valueIndicatorImage != null)
508 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
509 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
510 valueIndicatorImage.PositionUsesPivotPoint = true;
512 if (valueIndicatorText != null)
514 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
515 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
516 valueIndicatorText.PositionUsesPivotPoint = true;
517 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
519 if (panGestureDetector != null)
523 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
525 panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
530 private int BgTrackLength()
532 int bgTrackLength = 0;
533 IndicatorType type = CurrentIndicatorType();
535 if (type == IndicatorType.None)
537 if (direction == DirectionType.Horizontal)
539 bgTrackLength = this.Size2D.Width;
541 else if (direction == DirectionType.Vertical)
543 bgTrackLength = this.Size2D.Height;
546 else if (type == IndicatorType.Image)
547 {// <lowIndicatorImage> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage>
548 Size lowIndicatorImageSize = LowIndicatorImageSize();
549 Size highIndicatorImageSize = HighIndicatorImageSize();
550 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
551 if (direction == DirectionType.Horizontal)
553 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
554 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
555 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
557 else if (direction == DirectionType.Vertical)
559 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
560 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
561 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
564 else if (type == IndicatorType.Text)
565 {// <lowIndicatorText> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorText>
566 Size lowIndicatorTextSize = LowIndicatorTextSize();
567 Size highIndicatorTextSize = HighIndicatorTextSize();
568 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
569 if (direction == DirectionType.Horizontal)
571 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
572 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
573 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
575 else if (direction == DirectionType.Vertical)
577 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
578 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
579 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
582 return bgTrackLength;
585 private void UpdateLowIndicatorSize()
587 if (lowIndicatorSize != null)
589 if (lowIndicatorImage != null)
591 lowIndicatorImage.Size = lowIndicatorSize;
593 if (lowIndicatorText != null)
595 lowIndicatorText.Size = lowIndicatorSize;
600 if (lowIndicatorImage != null && lowIndicatorImage != null && lowIndicatorImage.Size != null)
602 lowIndicatorImage.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicatorImage.Size;
604 if (lowIndicatorText != null && lowIndicatorText != null && lowIndicatorText.Size != null)
606 lowIndicatorText.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicator.Size;
611 private void UpdateBgTrackSize()
613 if (bgTrackImage == null)
617 int curTrackThickness = (int)CurrentTrackThickness();
618 int bgTrackLength = BgTrackLength();
619 if (direction == DirectionType.Horizontal)
621 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
623 else if (direction == DirectionType.Vertical)
625 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
629 private void UpdateBgTrackPosition()
631 if (bgTrackImage == null)
635 IndicatorType type = CurrentIndicatorType();
637 if (type == IndicatorType.None)
639 bgTrackImage.Position2D = new Position2D(0, 0);
641 else if (type == IndicatorType.Image)
643 Size lowIndicatorImageSize = LowIndicatorImageSize();
644 Size highIndicatorImageSize = HighIndicatorImageSize();
645 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
646 if (direction == DirectionType.Horizontal)
648 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
649 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
650 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
652 else if (direction == DirectionType.Vertical)
654 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
655 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
656 bgTrackImage.Position2D = new Position2D(0, lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2);
659 else if (type == IndicatorType.Text)
661 Size lowIndicatorTextSize = LowIndicatorTextSize();
662 Size highIndicatorTextSize = HighIndicatorTextSize();
663 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
664 if (direction == DirectionType.Horizontal)
666 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
667 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
668 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
670 else if (direction == DirectionType.Vertical)
672 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
673 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
674 bgTrackImage.Position2D = new Position2D(0, -(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2));
679 private void UpdateValue()
681 if (slidedTrackImage == null)
685 if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
691 ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
693 uint curTrackThickness = CurrentTrackThickness();
695 if (direction == DirectionType.Horizontal)
697 if (LayoutDirection == ViewLayoutDirectionType.RTL)
699 ratio = 1.0f - ratio;
701 float slidedTrackLength = (float)BgTrackLength() * ratio;
702 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
703 thumbImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
704 thumbImage.RaiseToTop();
708 valueIndicatorImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
711 else if (direction == DirectionType.Vertical)
713 float slidedTrackLength = (float)BgTrackLength() * ratio;
714 slidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(slidedTrackLength + round)); //Add const round to reach Math.Round function.
715 thumbImage.Position = new Position(0, -slidedTrackImage.Size2D.Height);
716 thumbImage.RaiseToTop();
720 valueIndicatorImage.Position = new Position(0, -(slidedTrackImage.Size2D.Height + thumbImage.Size.Height / 2));
724 // Update the track and thumb when the value is over warning value.
725 if (curValue >= warningStartValue)
727 if (direction == DirectionType.Horizontal)
729 warningSlidedTrackImage.Size2D = new Size2D((int)(((curValue - warningStartValue) / 100) * this.Size2D.Width), (int)curTrackThickness);
731 else if (direction == DirectionType.Vertical)
733 warningSlidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(((curValue - warningStartValue) / 100) * this.Size2D.Height));
736 if (warningThumbColor != null && thumbImage.Color.NotEqualTo(warningThumbColor))
738 thumbImage.Color = warningThumbColor;
740 if (warningThumbImageUrl != null && !thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
742 thumbImage.ResourceUrl = warningThumbImageUrl;
747 warningSlidedTrackImage.Size2D = new Size2D(0, 0);
748 if (warningThumbColor != null && thumbImage.Color.EqualTo(warningThumbColor))
750 thumbImage.Color = thumbColor;
752 if (warningThumbImageUrl != null && thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
754 thumbImage.ResourceUrl = thumbImageUrl;
759 private uint CurrentTrackThickness()
761 uint curTrackThickness = 0;
762 if (trackThickness != null)
764 curTrackThickness = trackThickness.Value;
768 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackThickness != null)
770 curTrackThickness = sliderStyle.TrackThickness.Value;
773 return curTrackThickness;
776 private uint CurrentSpaceBetweenTrackAndIndicator()
779 if (spaceBetweenTrackAndIndicator != null)
781 curSpace = spaceBetweenTrackAndIndicator.Start;
785 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackPadding != null)
787 curSpace = sliderStyle.TrackPadding.Start;
793 private void UpdateWarningTrackSize()
795 if (warningTrackImage == null)
800 int curTrackThickness = (int)CurrentTrackThickness();
801 float warningTrackLength = maxValue - warningStartValue;
802 if (direction == DirectionType.Horizontal)
804 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Width;
805 warningTrackImage.Size2D = new Size2D((int)warningTrackLength, curTrackThickness);
807 else if (direction == DirectionType.Vertical)
809 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Height;
810 warningTrackImage.Size2D = new Size2D(curTrackThickness, (int)warningTrackLength);
814 private IndicatorType CurrentIndicatorType()
816 IndicatorType type = IndicatorType.None;
817 if (ViewStyle is SliderStyle sliderStyle)
819 type = (IndicatorType)sliderStyle.IndicatorType;
824 private Size LowIndicatorImageSize()
826 Size size = new Size(0, 0);
827 if (lowIndicatorSize != null)
829 size = lowIndicatorSize;
833 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null)
835 size = sliderStyle.LowIndicatorImage.Size;
841 private Size HighIndicatorImageSize()
843 Size size = new Size(0, 0);
844 if (highIndicatorSize != null)
846 size = highIndicatorSize;
850 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null)
852 size = sliderStyle.HighIndicatorImage.Size;
858 private Size LowIndicatorTextSize()
860 Size size = new Size(0, 0);
861 if (lowIndicatorSize != null)
863 size = lowIndicatorSize;
867 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null)
869 size = sliderStyle.LowIndicator.Size;
875 private Size HighIndicatorTextSize()
877 Size size = new Size(0, 0);
878 if (highIndicatorSize != null)
880 size = highIndicatorSize;
884 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null)
886 size = sliderStyle.HighIndicator.Size;