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;
112 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
117 private ImageView CreateSlidedTrack()
119 if (null == slidedTrackImage)
121 slidedTrackImage = new ImageView()
123 WidthResizePolicy = ResizePolicyType.Fixed,
124 HeightResizePolicy = ResizePolicyType.Fixed
127 if (bgTrackImage != null)
129 bgTrackImage.Add(slidedTrackImage);
133 return slidedTrackImage;
136 private ImageView CreateWarningTrack()
138 if (null == warningTrackImage)
140 warningTrackImage = new ImageView()
142 WidthResizePolicy = ResizePolicyType.Fixed,
143 HeightResizePolicy = ResizePolicyType.Fixed
146 if (bgTrackImage != null)
148 bgTrackImage.Add(warningTrackImage);
151 if (warningSlidedTrackImage != null)
153 warningTrackImage.Add(warningSlidedTrackImage);
156 if (slidedTrackImage != null)
158 warningTrackImage.RaiseAbove(slidedTrackImage);
162 return warningTrackImage;
165 private ImageView CreateWarningSlidedTrack()
167 if (null == warningSlidedTrackImage)
169 warningSlidedTrackImage = new ImageView()
171 WidthResizePolicy = ResizePolicyType.Fixed,
172 HeightResizePolicy = ResizePolicyType.Fixed
175 if (warningTrackImage != null)
177 warningTrackImage.Add(warningSlidedTrackImage);
181 return warningSlidedTrackImage;
184 private TextLabel CreateLowIndicatorText()
186 if (null == lowIndicatorText)
188 lowIndicatorText = new TextLabel()
190 WidthResizePolicy = ResizePolicyType.Fixed,
191 HeightResizePolicy = ResizePolicyType.Fixed
193 this.Add(lowIndicatorText);
196 return lowIndicatorText;
199 private TextLabel CreateHighIndicatorText()
201 if (null == highIndicatorText)
203 highIndicatorText = new TextLabel()
205 WidthResizePolicy = ResizePolicyType.Fixed,
206 HeightResizePolicy = ResizePolicyType.Fixed
208 this.Add(highIndicatorText);
211 return highIndicatorText;
214 private ImageView CreateBackgroundTrack()
216 if (null == bgTrackImage)
218 bgTrackImage = new ImageView()
220 WidthResizePolicy = ResizePolicyType.Fixed,
221 HeightResizePolicy = ResizePolicyType.Fixed,
222 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
223 PivotPoint = Tizen.NUI.PivotPoint.Center,
224 PositionUsesPivotPoint = true
226 this.Add(bgTrackImage);
228 if (null != slidedTrackImage)
230 bgTrackImage.Add(slidedTrackImage);
232 if (null != warningTrackImage)
234 bgTrackImage.Add(warningTrackImage);
236 if (null != thumbImage)
238 bgTrackImage.Add(thumbImage);
239 thumbImage.RaiseToTop();
246 private ImageView CreateThumb()
248 if (null == thumbImage)
250 thumbImage = new ImageView()
252 WidthResizePolicy = ResizePolicyType.Fixed,
253 HeightResizePolicy = ResizePolicyType.Fixed,
254 ParentOrigin = NUI.ParentOrigin.Center,
255 PivotPoint = NUI.PivotPoint.Center,
256 PositionUsesPivotPoint = true,
257 EnableControlState = true
259 if (bgTrackImage != null)
261 bgTrackImage.Add(thumbImage);
263 thumbImage.RaiseToTop();
264 thumbImage.TouchEvent += OnTouchEventForThumb;
270 private ImageView CreateValueIndicator()
272 if (valueIndicatorImage == null)
274 valueIndicatorImage = new ImageView()
276 PositionUsesPivotPoint = true,
277 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
278 PivotPoint = Tizen.NUI.PivotPoint.Center,
279 WidthResizePolicy = ResizePolicyType.Fixed,
280 HeightResizePolicy = ResizePolicyType.Fixed,
282 if (valueIndicatorText != null)
284 valueIndicatorImage.Add(valueIndicatorText);
286 // TODO : ValueIndicator can be a child of Thumb
287 this.Add(valueIndicatorImage);
290 valueIndicatorImage.Hide();
291 return valueIndicatorImage;
294 private TextLabel CreateValueIndicatorText()
296 if (null == valueIndicatorText)
298 valueIndicatorText = new TextLabel()
300 WidthResizePolicy = ResizePolicyType.Fixed,
301 HeightResizePolicy = ResizePolicyType.Fixed
303 if (valueIndicatorImage != null)
305 valueIndicatorImage.Add(valueIndicatorText);
309 return valueIndicatorText;
312 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
314 if (e.PanGesture.State == Gesture.StateType.Started)
316 if (direction == DirectionType.Horizontal)
318 currentSlidedOffset = slidedTrackImage.SizeWidth;
320 else if (direction == DirectionType.Vertical)
322 currentSlidedOffset = slidedTrackImage.SizeHeight;
327 valueIndicatorImage.Show();
330 if (null != sliderSlidingStartedHandler)
332 SliderSlidingStartedEventArgs args = new SliderSlidingStartedEventArgs();
333 args.CurrentValue = curValue;
334 sliderSlidingStartedHandler(this, args);
336 UpdateState(isFocused, true);
339 if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
341 if (direction == DirectionType.Horizontal)
343 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
345 else if (direction == DirectionType.Vertical)
347 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
352 if (e.PanGesture.State == Gesture.StateType.Finished)
356 valueIndicatorImage.Hide();
359 if (null != sliderSlidingFinishedHandler)
361 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
362 args.CurrentValue = curValue;
363 sliderSlidingFinishedHandler(this, args);
366 UpdateState(isFocused, false);
370 // Relayout basic component: track, thumb and indicator
371 private void RelayoutBaseComponent(bool isInitial = true)
373 if (direction == DirectionType.Horizontal)
375 if (slidedTrackImage != null)
377 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
378 slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
379 slidedTrackImage.PositionUsesPivotPoint = true;
381 if (warningTrackImage != null)
383 warningTrackImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
384 warningTrackImage.PivotPoint = NUI.PivotPoint.CenterRight;
385 warningTrackImage.PositionUsesPivotPoint = true;
387 if (warningSlidedTrackImage != null)
389 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
390 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
391 warningSlidedTrackImage.PositionUsesPivotPoint = true;
393 if (thumbImage != null)
395 thumbImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
396 thumbImage.PivotPoint = NUI.PivotPoint.Center;
397 thumbImage.PositionUsesPivotPoint = true;
399 if (lowIndicatorImage != null)
401 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
402 lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
403 lowIndicatorImage.PositionUsesPivotPoint = true;
405 if (highIndicatorImage != null)
407 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
408 highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
409 highIndicatorImage.PositionUsesPivotPoint = true;
411 if (lowIndicatorText != null)
413 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
414 lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
415 lowIndicatorText.PositionUsesPivotPoint = true;
417 if (highIndicatorText != null)
419 highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
420 highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
421 highIndicatorText.PositionUsesPivotPoint = true;
423 if (valueIndicatorImage != null)
425 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopLeft;
426 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
427 valueIndicatorImage.PositionUsesPivotPoint = true;
429 if (valueIndicatorText != null)
431 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
432 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
433 valueIndicatorText.PositionUsesPivotPoint = true;
434 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
436 if (panGestureDetector != null)
440 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
442 panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
445 else if (direction == DirectionType.Vertical)
447 if (slidedTrackImage != null)
449 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
450 slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
451 slidedTrackImage.PositionUsesPivotPoint = true;
453 if (warningTrackImage != null)
455 warningTrackImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
456 warningTrackImage.PivotPoint = NUI.PivotPoint.TopCenter;
457 warningTrackImage.PositionUsesPivotPoint = true;
459 if (warningSlidedTrackImage != null)
461 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
462 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
463 warningSlidedTrackImage.PositionUsesPivotPoint = true;
465 if (thumbImage != null)
467 thumbImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
468 thumbImage.PivotPoint = NUI.PivotPoint.Center;
469 thumbImage.PositionUsesPivotPoint = true;
471 if (lowIndicatorImage != null)
473 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
474 lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
475 lowIndicatorImage.PositionUsesPivotPoint = true;
477 if (highIndicatorImage != null)
479 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
480 highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
481 highIndicatorImage.PositionUsesPivotPoint = true;
483 if (lowIndicatorText != null)
485 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
486 lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
487 lowIndicatorText.PositionUsesPivotPoint = true;
489 if (highIndicatorText != null)
491 highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
492 highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
493 highIndicatorText.PositionUsesPivotPoint = true;
495 if (valueIndicatorImage != null)
497 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
498 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
499 valueIndicatorImage.PositionUsesPivotPoint = true;
501 if (valueIndicatorText != null)
503 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
504 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
505 valueIndicatorText.PositionUsesPivotPoint = true;
506 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
508 if (panGestureDetector != null)
512 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
514 panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
519 private int BgTrackLength()
521 int bgTrackLength = 0;
522 IndicatorType type = CurrentIndicatorType();
524 if (type == IndicatorType.None)
526 if (direction == DirectionType.Horizontal)
528 bgTrackLength = this.Size2D.Width;
530 else if (direction == DirectionType.Vertical)
532 bgTrackLength = this.Size2D.Height;
535 else if (type == IndicatorType.Image)
536 {// <lowIndicatorImage> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage>
537 Size lowIndicatorImageSize = LowIndicatorImageSize();
538 Size highIndicatorImageSize = HighIndicatorImageSize();
539 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
540 if (direction == DirectionType.Horizontal)
542 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
543 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
544 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
546 else if (direction == DirectionType.Vertical)
548 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
549 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
550 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
553 else if (type == IndicatorType.Text)
554 {// <lowIndicatorText> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorText>
555 Size lowIndicatorTextSize = LowIndicatorTextSize();
556 Size highIndicatorTextSize = HighIndicatorTextSize();
557 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
558 if (direction == DirectionType.Horizontal)
560 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
561 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
562 bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
564 else if (direction == DirectionType.Vertical)
566 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
567 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
568 bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
571 return bgTrackLength;
574 private void UpdateLowIndicatorSize()
576 if (lowIndicatorSize != null)
578 if (lowIndicatorImage != null)
580 lowIndicatorImage.Size = lowIndicatorSize;
582 if (lowIndicatorText != null)
584 lowIndicatorText.Size = lowIndicatorSize;
589 if (lowIndicatorImage != null && lowIndicatorImage != null && lowIndicatorImage.Size != null)
591 lowIndicatorImage.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicatorImage.Size;
593 if (lowIndicatorText != null && lowIndicatorText != null && lowIndicatorText.Size != null)
595 lowIndicatorText.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicator.Size;
600 private void UpdateBgTrackSize()
602 if (bgTrackImage == null)
606 int curTrackThickness = (int)CurrentTrackThickness();
607 int bgTrackLength = BgTrackLength();
608 if (direction == DirectionType.Horizontal)
610 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
612 else if (direction == DirectionType.Vertical)
614 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
618 private void UpdateBgTrackPosition()
620 if (bgTrackImage == null)
624 IndicatorType type = CurrentIndicatorType();
626 if (type == IndicatorType.None)
628 bgTrackImage.Position2D = new Position2D(0, 0);
630 else if (type == IndicatorType.Image)
632 Size lowIndicatorImageSize = LowIndicatorImageSize();
633 Size highIndicatorImageSize = HighIndicatorImageSize();
634 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
635 if (direction == DirectionType.Horizontal)
637 int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
638 int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
639 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
641 else if (direction == DirectionType.Vertical)
643 int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
644 int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
645 bgTrackImage.Position2D = new Position2D(0, lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2);
648 else if (type == IndicatorType.Text)
650 Size lowIndicatorTextSize = LowIndicatorTextSize();
651 Size highIndicatorTextSize = HighIndicatorTextSize();
652 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
653 if (direction == DirectionType.Horizontal)
655 int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
656 int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
657 bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
659 else if (direction == DirectionType.Vertical)
661 int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
662 int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
663 bgTrackImage.Position2D = new Position2D(0, -(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2));
668 private void UpdateValue()
670 if (slidedTrackImage == null)
674 if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
680 ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
682 uint curTrackThickness = CurrentTrackThickness();
684 if (direction == DirectionType.Horizontal)
686 if (LayoutDirection == ViewLayoutDirectionType.RTL)
688 ratio = 1.0f - ratio;
690 float slidedTrackLength = (float)BgTrackLength() * ratio;
691 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
692 thumbImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
693 thumbImage.RaiseToTop();
697 valueIndicatorImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
700 else if (direction == DirectionType.Vertical)
702 float slidedTrackLength = (float)BgTrackLength() * ratio;
703 slidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(slidedTrackLength + round)); //Add const round to reach Math.Round function.
704 thumbImage.Position = new Position(0, -slidedTrackImage.Size2D.Height);
705 thumbImage.RaiseToTop();
709 valueIndicatorImage.Position = new Position(0, -(slidedTrackImage.Size2D.Height + thumbImage.Size.Height / 2));
713 // Update the track and thumb when the value is over warning value.
714 if (curValue >= warningStartValue)
716 if (direction == DirectionType.Horizontal)
718 warningSlidedTrackImage.Size2D = new Size2D((int)(((curValue - warningStartValue) / 100) * this.Size2D.Width), (int)curTrackThickness);
720 else if (direction == DirectionType.Vertical)
722 warningSlidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(((curValue - warningStartValue) / 100) * this.Size2D.Height));
725 if (warningThumbColor != null && thumbImage.Color.NotEqualTo(warningThumbColor))
727 thumbImage.Color = warningThumbColor;
729 if (warningThumbImageUrl != null && !thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
731 thumbImage.ResourceUrl = warningThumbImageUrl;
736 warningSlidedTrackImage.Size2D = new Size2D(0, 0);
737 if (warningThumbColor != null && thumbImage.Color.EqualTo(warningThumbColor))
739 thumbImage.Color = thumbColor;
741 if (warningThumbImageUrl != null && thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
743 thumbImage.ResourceUrl = thumbImageUrl;
748 private uint CurrentTrackThickness()
750 uint curTrackThickness = 0;
751 if (trackThickness != null)
753 curTrackThickness = trackThickness.Value;
757 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackThickness != null)
759 curTrackThickness = sliderStyle.TrackThickness.Value;
762 return curTrackThickness;
765 private uint CurrentSpaceBetweenTrackAndIndicator()
768 if (spaceBetweenTrackAndIndicator != null)
770 curSpace = spaceBetweenTrackAndIndicator.Start;
774 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackPadding != null)
776 curSpace = sliderStyle.TrackPadding.Start;
782 private void UpdateWarningTrackSize()
784 if (warningTrackImage == null)
789 int curTrackThickness = (int)CurrentTrackThickness();
790 float warningTrackLength = maxValue - warningStartValue;
791 if (direction == DirectionType.Horizontal)
793 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Width;
794 warningTrackImage.Size2D = new Size2D((int)warningTrackLength, curTrackThickness);
796 else if (direction == DirectionType.Vertical)
798 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Height;
799 warningTrackImage.Size2D = new Size2D(curTrackThickness, (int)warningTrackLength);
803 private IndicatorType CurrentIndicatorType()
805 IndicatorType type = IndicatorType.None;
806 if (ViewStyle is SliderStyle sliderStyle)
808 type = (IndicatorType)sliderStyle.IndicatorType;
813 private Size LowIndicatorImageSize()
815 Size size = new Size(0, 0);
816 if (lowIndicatorSize != null)
818 size = lowIndicatorSize;
822 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null)
824 size = sliderStyle.LowIndicatorImage.Size;
830 private Size HighIndicatorImageSize()
832 Size size = new Size(0, 0);
833 if (highIndicatorSize != null)
835 size = highIndicatorSize;
839 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null)
841 size = sliderStyle.HighIndicatorImage.Size;
847 private Size LowIndicatorTextSize()
849 Size size = new Size(0, 0);
850 if (lowIndicatorSize != null)
852 size = lowIndicatorSize;
856 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null)
858 size = sliderStyle.LowIndicator.Size;
864 private Size HighIndicatorTextSize()
866 Size size = new Size(0, 0);
867 if (highIndicatorSize != null)
869 size = highIndicatorSize;
873 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null)
875 size = sliderStyle.HighIndicator.Size;