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;
106 this.GrabTouchAfterLeave = true;
108 panGestureDetector = new PanGestureDetector();
109 panGestureDetector.Attach(this);
110 panGestureDetector.Detected += OnPanGestureDetected;
112 this.Layout = new LinearLayout()
114 LinearOrientation = LinearLayout.Orientation.Horizontal,
118 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
123 private ImageView CreateSlidedTrack()
125 if (null == slidedTrackImage)
127 slidedTrackImage = new ImageView()
129 WidthResizePolicy = ResizePolicyType.Fixed,
130 HeightResizePolicy = ResizePolicyType.Fixed,
131 AccessibilityHidden = true,
134 if (bgTrackImage != null)
136 bgTrackImage.Add(slidedTrackImage);
140 return slidedTrackImage;
143 private ImageView CreateWarningTrack()
145 if (null == warningTrackImage)
147 warningTrackImage = new ImageView()
149 WidthResizePolicy = ResizePolicyType.Fixed,
150 HeightResizePolicy = ResizePolicyType.Fixed,
151 AccessibilityHidden = true,
154 if (bgTrackImage != null)
156 bgTrackImage.Add(warningTrackImage);
159 if (warningSlidedTrackImage != null)
161 warningTrackImage.Add(warningSlidedTrackImage);
164 if (slidedTrackImage != null)
166 warningTrackImage.RaiseAbove(slidedTrackImage);
170 return warningTrackImage;
173 private ImageView CreateWarningSlidedTrack()
175 if (null == warningSlidedTrackImage)
177 warningSlidedTrackImage = new ImageView()
179 WidthResizePolicy = ResizePolicyType.Fixed,
180 HeightResizePolicy = ResizePolicyType.Fixed,
181 AccessibilityHidden = true,
184 if (warningTrackImage != null)
186 warningTrackImage.Add(warningSlidedTrackImage);
190 return warningSlidedTrackImage;
193 private TextLabel CreateLowIndicatorText()
195 if (null == lowIndicatorText)
197 lowIndicatorText = new TextLabel()
199 WidthResizePolicy = ResizePolicyType.Fixed,
200 HeightResizePolicy = ResizePolicyType.Fixed,
201 AccessibilityHidden = true,
203 this.Add(lowIndicatorText);
206 return lowIndicatorText;
209 private TextLabel CreateHighIndicatorText()
211 if (null == highIndicatorText)
213 highIndicatorText = new TextLabel()
215 WidthResizePolicy = ResizePolicyType.Fixed,
216 HeightResizePolicy = ResizePolicyType.Fixed,
217 AccessibilityHidden = true,
219 this.Add(highIndicatorText);
222 return highIndicatorText;
225 private ImageView CreateLowIndicatorImage()
227 if (lowIndicatorImage == null)
229 lowIndicatorImage = new ImageView()
231 WidthResizePolicy = ResizePolicyType.Fixed,
232 HeightResizePolicy = ResizePolicyType.Fixed,
233 AccessibilityHidden = true,
235 this.Add(lowIndicatorImage);
238 return lowIndicatorImage;
241 private ImageView CreateHighIndicatorImage()
243 if (highIndicatorImage == null)
245 highIndicatorImage = new ImageView()
247 WidthResizePolicy = ResizePolicyType.Fixed,
248 HeightResizePolicy = ResizePolicyType.Fixed,
249 AccessibilityHidden = true,
251 this.Add(highIndicatorImage);
254 return highIndicatorImage;
259 private ImageView CreateBackgroundTrack()
261 if (null == bgTrackImage)
263 bgTrackImage = new ImageView()
265 WidthResizePolicy = ResizePolicyType.Fixed,
266 HeightResizePolicy = ResizePolicyType.Fixed,
267 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
268 PivotPoint = Tizen.NUI.PivotPoint.Center,
269 PositionUsesPivotPoint = true,
270 GrabTouchAfterLeave = true,
271 AccessibilityHidden = true,
273 this.Add(bgTrackImage);
275 if (null != slidedTrackImage)
277 bgTrackImage.Add(slidedTrackImage);
279 if (null != warningTrackImage)
281 bgTrackImage.Add(warningTrackImage);
283 if (null != thumbImage)
285 bgTrackImage.Add(thumbImage);
286 thumbImage.RaiseToTop();
293 private ImageView CreateThumb()
295 if (null == thumbImage)
297 thumbImage = new ImageView()
299 WidthResizePolicy = ResizePolicyType.Fixed,
300 HeightResizePolicy = ResizePolicyType.Fixed,
301 ParentOrigin = NUI.ParentOrigin.Center,
302 PivotPoint = NUI.PivotPoint.Center,
303 PositionUsesPivotPoint = true,
304 EnableControlState = true,
305 GrabTouchAfterLeave = true,
306 AccessibilityHidden = true,
308 if (bgTrackImage != null)
310 bgTrackImage.Add(thumbImage);
312 thumbImage.RaiseToTop();
313 thumbImage.TouchEvent += OnTouchEventForThumb;
319 private ImageView CreateValueIndicatorImage()
321 if (valueIndicatorImage == null)
323 valueIndicatorImage = new ImageView()
325 PositionUsesPivotPoint = true,
326 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
327 PivotPoint = Tizen.NUI.PivotPoint.Center,
328 WidthResizePolicy = ResizePolicyType.Fixed,
329 HeightResizePolicy = ResizePolicyType.Fixed,
330 AccessibilityHidden = true,
332 if (valueIndicatorText != null)
334 valueIndicatorImage.Add(valueIndicatorText);
336 // TODO : ValueIndicator can be a child of Thumb
337 this.Add(valueIndicatorImage);
340 valueIndicatorImage.Hide();
341 return valueIndicatorImage;
344 private TextLabel CreateValueIndicatorText()
346 if (null == valueIndicatorText)
348 valueIndicatorText = new TextLabel()
350 WidthResizePolicy = ResizePolicyType.Fixed,
351 HeightResizePolicy = ResizePolicyType.Fixed,
352 AccessibilityHidden = true,
354 if (valueIndicatorImage != null)
356 valueIndicatorImage.Add(valueIndicatorText);
360 return valueIndicatorText;
363 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
365 if (e.PanGesture.State == Gesture.StateType.Started)
367 if (direction == DirectionType.Horizontal)
369 currentSlidedOffset = slidedTrackImage.SizeWidth;
371 else if (direction == DirectionType.Vertical)
373 currentSlidedOffset = slidedTrackImage.SizeHeight;
378 valueIndicatorImage.Show();
381 if (null != sliderSlidingStartedHandler)
383 SliderSlidingStartedEventArgs args = new SliderSlidingStartedEventArgs();
384 args.CurrentValue = curValue;
385 sliderSlidingStartedHandler(this, args);
387 UpdateState(isFocused, true);
390 if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
392 if (direction == DirectionType.Horizontal)
394 CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
396 else if (direction == DirectionType.Vertical)
398 CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
400 UpdateState(isFocused, true);
404 if (e.PanGesture.State == Gesture.StateType.Finished)
408 valueIndicatorImage.Hide();
411 if (null != sliderSlidingFinishedHandler)
413 SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
414 args.CurrentValue = curValue;
415 sliderSlidingFinishedHandler(this, args);
418 UpdateState(isFocused, false);
422 // Relayout basic component: track, thumb and indicator
423 private void RelayoutBaseComponent(bool isInitial = true)
425 if (direction == DirectionType.Horizontal)
427 if (slidedTrackImage != null)
429 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
430 slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
431 slidedTrackImage.PositionUsesPivotPoint = true;
433 if (warningTrackImage != null)
435 warningTrackImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
436 warningTrackImage.PivotPoint = NUI.PivotPoint.CenterRight;
437 warningTrackImage.PositionUsesPivotPoint = true;
439 if (warningSlidedTrackImage != null)
441 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
442 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
443 warningSlidedTrackImage.PositionUsesPivotPoint = true;
445 if (thumbImage != null)
447 thumbImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
448 thumbImage.PivotPoint = NUI.PivotPoint.Center;
449 thumbImage.PositionUsesPivotPoint = true;
451 if (lowIndicatorImage != null)
453 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
454 lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
455 lowIndicatorImage.PositionUsesPivotPoint = true;
457 if (highIndicatorImage != null)
459 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
460 highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
461 highIndicatorImage.PositionUsesPivotPoint = true;
463 if (lowIndicatorText != null)
465 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
466 lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
467 lowIndicatorText.PositionUsesPivotPoint = true;
469 if (highIndicatorText != null)
471 highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
472 highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
473 highIndicatorText.PositionUsesPivotPoint = true;
475 if (valueIndicatorImage != null)
477 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopLeft;
478 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
479 valueIndicatorImage.PositionUsesPivotPoint = true;
481 if (valueIndicatorText != null)
483 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
484 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
485 valueIndicatorText.PositionUsesPivotPoint = true;
486 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
488 if (panGestureDetector != null)
492 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
494 panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
497 else if (direction == DirectionType.Vertical)
499 if (slidedTrackImage != null)
501 slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
502 slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
503 slidedTrackImage.PositionUsesPivotPoint = true;
505 if (warningTrackImage != null)
507 warningTrackImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
508 warningTrackImage.PivotPoint = NUI.PivotPoint.TopCenter;
509 warningTrackImage.PositionUsesPivotPoint = true;
511 if (warningSlidedTrackImage != null)
513 warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
514 warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
515 warningSlidedTrackImage.PositionUsesPivotPoint = true;
517 if (thumbImage != null)
519 thumbImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
520 thumbImage.PivotPoint = NUI.PivotPoint.Center;
521 thumbImage.PositionUsesPivotPoint = true;
523 if (lowIndicatorImage != null)
525 lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
526 lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
527 lowIndicatorImage.PositionUsesPivotPoint = true;
529 if (highIndicatorImage != null)
531 highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
532 highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
533 highIndicatorImage.PositionUsesPivotPoint = true;
535 if (lowIndicatorText != null)
537 lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
538 lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
539 lowIndicatorText.PositionUsesPivotPoint = true;
541 if (highIndicatorText != null)
543 highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
544 highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
545 highIndicatorText.PositionUsesPivotPoint = true;
547 if (valueIndicatorImage != null)
549 valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
550 valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
551 valueIndicatorImage.PositionUsesPivotPoint = true;
553 if (valueIndicatorText != null)
555 valueIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
556 valueIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
557 valueIndicatorText.PositionUsesPivotPoint = true;
558 valueIndicatorText.Padding = new Extents(0, 0, 5, 0); // TODO : How to set the text as center
560 if (panGestureDetector != null)
564 panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
566 panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
571 private int GetBgTrackLength()
573 int bgTrackLength = 0;
575 int lowIndicatorOffset = GetBgTrackLowIndicatorOffset();
576 int highIndicatorOffet = GetBgTrackHighIndicatorOffset();
578 if (direction == DirectionType.Horizontal)
580 bgTrackLength = this.Size2D.Width - lowIndicatorOffset - highIndicatorOffet;
582 else if (direction == DirectionType.Vertical)
584 bgTrackLength = this.Size2D.Height - lowIndicatorOffset - highIndicatorOffet;
587 return bgTrackLength;
591 /// Get offset value of bgtrack's low indicator side.
593 private int GetBgTrackLowIndicatorOffset()
595 int bgTrackLowIndicatorOffset = 0;
596 IndicatorType type = CurrentIndicatorType();
598 if (type == IndicatorType.None)
600 if (direction == DirectionType.Horizontal)
602 bgTrackLowIndicatorOffset = (int)(thumbImage.Size.Width * 0.5f);
604 else if (direction == DirectionType.Vertical)
606 bgTrackLowIndicatorOffset = (int)(thumbImage.Size.Height * 0.5f);
609 else if (type == IndicatorType.Image || type == IndicatorType.Text)
610 {// <lowIndicatorImage or Text> <spaceBetweenTrackAndIndicator> <bgTrack>
611 Size lowIndicatorSize = (type == IndicatorType.Image) ? LowIndicatorImageSize() : LowIndicatorTextSize();
612 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
613 if (direction == DirectionType.Horizontal)
615 bgTrackLowIndicatorOffset = ((lowIndicatorSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorSize.Width)));
617 else if (direction == DirectionType.Vertical)
619 bgTrackLowIndicatorOffset = ((lowIndicatorSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorSize.Height)));
622 return bgTrackLowIndicatorOffset;
626 /// Get offset value of bgtrack's high indicator side.
628 private int GetBgTrackHighIndicatorOffset()
630 int bgTrackHighIndicatorOffset = 0;
631 IndicatorType type = CurrentIndicatorType();
633 if (type == IndicatorType.None)
635 if (direction == DirectionType.Horizontal)
637 bgTrackHighIndicatorOffset = (int)(thumbImage.Size.Width * 0.5f);
639 else if (direction == DirectionType.Vertical)
641 bgTrackHighIndicatorOffset = (int)(thumbImage.Size.Height * 0.5f);
644 else if (type == IndicatorType.Image || type == IndicatorType.Text)
645 {// <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage or Text>
646 Size highIndicatorSize = (type == IndicatorType.Image) ? HighIndicatorImageSize() : HighIndicatorTextSize();
647 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
648 if (direction == DirectionType.Horizontal)
650 bgTrackHighIndicatorOffset = ((highIndicatorSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorSize.Width)));
652 else if (direction == DirectionType.Vertical)
654 bgTrackHighIndicatorOffset = ((highIndicatorSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorSize.Height)));
657 return bgTrackHighIndicatorOffset;
660 private void UpdateLowIndicatorSize()
662 if (lowIndicatorSize != null)
664 if (lowIndicatorImage != null)
666 lowIndicatorImage.Size = lowIndicatorSize;
668 if (lowIndicatorText != null)
670 lowIndicatorText.Size = lowIndicatorSize;
675 if (lowIndicatorImage != null && lowIndicatorImage.Size != null)
677 lowIndicatorImage.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicatorImage.Size;
679 if (lowIndicatorText != null && lowIndicatorText.Size != null)
681 lowIndicatorText.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicator.Size;
686 private void UpdateHighIndicatorSize()
688 if (highIndicatorSize != null)
690 if (highIndicatorImage != null)
692 highIndicatorImage.Size = highIndicatorSize;
694 if (highIndicatorText != null)
696 highIndicatorText.Size = highIndicatorSize;
701 if (highIndicatorImage != null && highIndicatorImage.Size != null)
703 highIndicatorImage.Size = highIndicatorSize ?? (ViewStyle as SliderStyle)?.HighIndicatorImage.Size;
705 if (highIndicatorText != null && highIndicatorText.Size != null)
707 highIndicatorText.Size = highIndicatorSize ?? (ViewStyle as SliderStyle)?.HighIndicator.Size;
712 private void UpdateBgTrackSize()
714 if (bgTrackImage == null)
718 int curTrackThickness = (int)CurrentTrackThickness();
719 int bgTrackLength = GetBgTrackLength();
720 if (direction == DirectionType.Horizontal)
722 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
724 else if (direction == DirectionType.Vertical)
726 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
730 private void UpdateBgTrackPosition()
732 if (bgTrackImage == null)
737 int lowIndicatorOffset = GetBgTrackLowIndicatorOffset();
738 int highIndicatorOffet = GetBgTrackHighIndicatorOffset();
740 if (direction == DirectionType.Horizontal)
742 bgTrackImage.Position2D = new Position2D((lowIndicatorOffset - highIndicatorOffet) / 2, 0);
744 else if (direction == DirectionType.Vertical)
746 bgTrackImage.Position2D = new Position2D(0, (highIndicatorOffet - lowIndicatorOffset) / 2);
750 private void UpdateValue()
752 if (slidedTrackImage == null)
756 if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
762 ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
764 uint curTrackThickness = CurrentTrackThickness();
766 if (direction == DirectionType.Horizontal)
768 if (LayoutDirection == ViewLayoutDirectionType.RTL)
770 ratio = 1.0f - ratio;
772 float slidedTrackLength = (float)GetBgTrackLength() * ratio;
773 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
774 thumbImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
775 thumbImage.RaiseToTop();
779 valueIndicatorImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
782 else if (direction == DirectionType.Vertical)
784 float slidedTrackLength = (float)GetBgTrackLength() * ratio;
785 slidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(slidedTrackLength + round)); //Add const round to reach Math.Round function.
786 thumbImage.Position = new Position(0, -slidedTrackImage.Size2D.Height);
787 thumbImage.RaiseToTop();
791 valueIndicatorImage.Position = new Position(0, -(slidedTrackImage.Size2D.Height + thumbImage.Size.Height / 2));
795 // Update the track and thumb when the value is over warning value.
796 if (curValue >= warningStartValue)
798 if (direction == DirectionType.Horizontal)
800 warningSlidedTrackImage.Size2D = new Size2D((int)(((curValue - warningStartValue) / 100) * this.Size2D.Width), (int)curTrackThickness);
802 else if (direction == DirectionType.Vertical)
804 warningSlidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(((curValue - warningStartValue) / 100) * this.Size2D.Height));
807 if (warningThumbColor != null && thumbImage.Color.NotEqualTo(warningThumbColor))
809 thumbImage.Color = warningThumbColor;
811 if (warningThumbImageUrl != null && !thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
813 thumbImage.ResourceUrl = warningThumbImageUrl;
818 warningSlidedTrackImage.Size2D = new Size2D(0, 0);
819 if (warningThumbColor != null && thumbImage.Color.EqualTo(warningThumbColor))
821 thumbImage.Color = thumbColor;
823 if (warningThumbImageUrl != null && thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
825 thumbImage.ResourceUrl = thumbImageUrl;
830 private uint CurrentTrackThickness()
832 uint curTrackThickness = 0;
833 if (trackThickness != null)
835 curTrackThickness = trackThickness.Value;
839 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackThickness != null)
841 curTrackThickness = sliderStyle.TrackThickness.Value;
844 return curTrackThickness;
847 private uint CurrentSpaceBetweenTrackAndIndicator()
850 if (spaceBetweenTrackAndIndicator != null)
852 curSpace = spaceBetweenTrackAndIndicator.Start;
856 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackPadding != null)
858 curSpace = sliderStyle.TrackPadding.Start;
864 private void UpdateWarningTrackSize()
866 if (warningTrackImage == null)
871 int curTrackThickness = (int)CurrentTrackThickness();
872 float warningTrackLength = maxValue - warningStartValue;
873 if (direction == DirectionType.Horizontal)
875 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Width;
876 warningTrackImage.Size2D = new Size2D((int)warningTrackLength, curTrackThickness);
878 else if (direction == DirectionType.Vertical)
880 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Height;
881 warningTrackImage.Size2D = new Size2D(curTrackThickness, (int)warningTrackLength);
885 private IndicatorType CurrentIndicatorType()
887 IndicatorType type = IndicatorType.None;
888 if (ViewStyle is SliderStyle sliderStyle)
890 type = (IndicatorType)sliderStyle.IndicatorType;
895 private Size LowIndicatorImageSize()
897 Size size = new Size(0, 0);
898 if (lowIndicatorSize != null)
900 size = lowIndicatorSize;
904 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null)
906 size = sliderStyle.LowIndicatorImage.Size;
912 private Size HighIndicatorImageSize()
914 Size size = new Size(0, 0);
915 if (highIndicatorSize != null)
917 size = highIndicatorSize;
921 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null)
923 size = sliderStyle.HighIndicatorImage.Size;
929 private Size LowIndicatorTextSize()
931 Size size = new Size(0, 0);
932 if (lowIndicatorSize != null)
934 size = lowIndicatorSize;
938 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null)
940 size = sliderStyle.LowIndicator.Size;
946 private Size HighIndicatorTextSize()
948 Size size = new Size(0, 0);
949 if (highIndicatorSize != null)
951 size = highIndicatorSize;
955 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null)
957 size = sliderStyle.HighIndicator.Size;