[NUI] Fix NUI button not working when style disabled
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Slider.Internal.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21
22 namespace Tizen.NUI.Components
23 {
24     public partial class Slider
25     {
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;
44         // the direction type
45         private DirectionType direction = DirectionType.Horizontal;
46         // the indicator type
47         private IndicatorType indicatorType = IndicatorType.None;
48         private const float round = 0.5f;
49         // the minimum value
50         private float minValue = 0;
51         // the maximum value
52         private float maxValue = 100;
53         // the current value
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;
71
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;
84         // the discrete value
85         private float discreteValue = 0;
86
87         private PanGestureDetector panGestureDetector = null;
88         private readonly uint panGestureMotionEventAge = 16; // TODO : Can't we get this value from system configure?
89         private float currentSlidedOffset;
90         private EventHandler<SliderValueChangedEventArgs> sliderValueChangedHandler;
91         private EventHandler<SliderSlidingStartedEventArgs> sliderSlidingStartedHandler;
92         private EventHandler<SliderSlidingFinishedEventArgs> sliderSlidingFinishedHandler;
93
94         bool isFocused = false;
95         bool isPressed = false;
96
97         private void Initialize()
98         {
99             AccessibilityHighlightable = true;
100
101             currentSlidedOffset = 0;
102             isFocused = false;
103             isPressed = false;
104             LayoutDirectionChanged += OnLayoutDirectionChanged;
105
106             this.TouchEvent += OnTouchEventForTrack;
107             this.GrabTouchAfterLeave = true;
108
109             panGestureDetector = new PanGestureDetector();
110             panGestureDetector.Attach(this);
111             panGestureDetector.SetMaximumMotionEventAge(panGestureMotionEventAge);
112             panGestureDetector.Detected += OnPanGestureDetected;
113
114             this.Layout = new LinearLayout()
115             {
116                 LinearOrientation = LinearLayout.Orientation.Horizontal,
117             };
118         }
119
120         private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
121         {
122             RelayoutRequest();
123         }
124
125         private ImageView CreateSlidedTrack()
126         {
127             if (null == slidedTrackImage)
128             {
129                 slidedTrackImage = new ImageView()
130                 {
131                     WidthResizePolicy = ResizePolicyType.Fixed,
132                     HeightResizePolicy = ResizePolicyType.Fixed,
133                     AccessibilityHidden = true,
134                 };
135
136                 if (bgTrackImage != null)
137                 {
138                     bgTrackImage.Add(slidedTrackImage);
139                 }
140             }
141
142             return slidedTrackImage;
143         }
144
145         private ImageView CreateWarningTrack()
146         {
147             if (null == warningTrackImage)
148             {
149                 warningTrackImage = new ImageView()
150                 {
151                     WidthResizePolicy = ResizePolicyType.Fixed,
152                     HeightResizePolicy = ResizePolicyType.Fixed,
153                     AccessibilityHidden = true,
154                 };
155
156                 if (bgTrackImage != null)
157                 {
158                     bgTrackImage.Add(warningTrackImage);
159                 }
160
161                 if (warningSlidedTrackImage != null)
162                 {
163                     warningTrackImage.Add(warningSlidedTrackImage);
164                 }
165
166                 if (slidedTrackImage != null)
167                 {
168                     warningTrackImage.RaiseAbove(slidedTrackImage);
169                 }
170             }
171
172             return warningTrackImage;
173         }
174
175         private ImageView CreateWarningSlidedTrack()
176         {
177             if (null == warningSlidedTrackImage)
178             {
179                 warningSlidedTrackImage = new ImageView()
180                 {
181                     WidthResizePolicy = ResizePolicyType.Fixed,
182                     HeightResizePolicy = ResizePolicyType.Fixed,
183                     AccessibilityHidden = true,
184                 };
185
186                 if (warningTrackImage != null)
187                 {
188                     warningTrackImage.Add(warningSlidedTrackImage);
189                 }
190             }
191
192             return warningSlidedTrackImage;
193         }
194
195         private TextLabel CreateLowIndicatorText()
196         {
197             if (null == lowIndicatorText)
198             {
199                 lowIndicatorText = new TextLabel()
200                 {
201                     WidthResizePolicy = ResizePolicyType.Fixed,
202                     HeightResizePolicy = ResizePolicyType.Fixed,
203                     AccessibilityHidden = true,
204                 };
205                 this.Add(lowIndicatorText);
206             }
207
208             return lowIndicatorText;
209         }
210
211         private TextLabel CreateHighIndicatorText()
212         {
213             if (null == highIndicatorText)
214             {
215                 highIndicatorText = new TextLabel()
216                 {
217                     WidthResizePolicy = ResizePolicyType.Fixed,
218                     HeightResizePolicy = ResizePolicyType.Fixed,
219                     AccessibilityHidden = true,
220                 };
221                 this.Add(highIndicatorText);
222             }
223
224             return highIndicatorText;
225         }
226
227         private ImageView CreateLowIndicatorImage()
228         {
229             if (lowIndicatorImage == null)
230             {
231                 lowIndicatorImage = new ImageView()
232                 {
233                     WidthResizePolicy = ResizePolicyType.Fixed,
234                     HeightResizePolicy = ResizePolicyType.Fixed,
235                     AccessibilityHidden = true,
236                 };
237                 this.Add(lowIndicatorImage);
238             }
239
240             return lowIndicatorImage;
241         }
242
243         private ImageView CreateHighIndicatorImage()
244         {
245             if (highIndicatorImage == null)
246             {
247                 highIndicatorImage = new ImageView()
248                 {
249                     WidthResizePolicy = ResizePolicyType.Fixed,
250                     HeightResizePolicy = ResizePolicyType.Fixed,
251                                         AccessibilityHidden = true,
252                 };
253                 this.Add(highIndicatorImage);
254             }
255
256             return highIndicatorImage;
257         }
258
259
260
261         private ImageView CreateBackgroundTrack()
262         {
263             if (null == bgTrackImage)
264             {
265                 bgTrackImage = new ImageView()
266                 {
267                     WidthResizePolicy = ResizePolicyType.Fixed,
268                     HeightResizePolicy = ResizePolicyType.Fixed,
269                     ParentOrigin = Tizen.NUI.ParentOrigin.Center,
270                     PivotPoint = Tizen.NUI.PivotPoint.Center,
271                     PositionUsesPivotPoint = true,
272                     GrabTouchAfterLeave = true,
273                     AccessibilityHidden = true,
274                 };
275                 this.Add(bgTrackImage);
276
277                 if (null != slidedTrackImage)
278                 {
279                     bgTrackImage.Add(slidedTrackImage);
280                 }
281                 if (null != warningTrackImage)
282                 {
283                     bgTrackImage.Add(warningTrackImage);
284                 }
285                 if (null != thumbImage)
286                 {
287                     bgTrackImage.Add(thumbImage);
288                     thumbImage.RaiseToTop();
289                 }
290             }
291
292             return bgTrackImage;
293         }
294
295         private ImageView CreateThumb()
296         {
297             if (null == thumbImage)
298             {
299                 thumbImage = new ImageView()
300                 {
301                     WidthResizePolicy = ResizePolicyType.Fixed,
302                     HeightResizePolicy = ResizePolicyType.Fixed,
303                     EnableControlState = true,
304                     GrabTouchAfterLeave = true,
305                     AccessibilityHidden = true,
306                 };
307                 if (valueIndicatorImage != null)
308                 {
309                     thumbImage.Add(valueIndicatorImage);
310                 }
311                 if (bgTrackImage != null)
312                 {
313                     bgTrackImage.Add(thumbImage);
314                 }
315                 thumbImage.RaiseToTop();
316                 thumbImage.TouchEvent += OnTouchEventForThumb;
317             }
318
319             return thumbImage;
320         }
321
322         private ImageView CreateValueIndicatorImage()
323         {
324             if (valueIndicatorImage == null)
325             {
326                 valueIndicatorImage = new ImageView()
327                 {
328                     WidthResizePolicy = ResizePolicyType.FitToChildren,
329                     HeightResizePolicy = ResizePolicyType.Fixed,
330                     AccessibilityHidden = true,
331                 };
332                 if (thumbImage != null)
333                 {
334                     thumbImage.Add(valueIndicatorImage);
335                 }
336                 if (valueIndicatorText != null)
337                 {
338                     valueIndicatorImage.Add(valueIndicatorText);
339                     valueIndicatorText.RaiseToTop();
340                 }
341             }
342
343             valueIndicatorImage.Hide();
344             return valueIndicatorImage;
345         }
346
347         private TextLabel CreateValueIndicatorText()
348         {
349             if (null == valueIndicatorText)
350             {
351                 valueIndicatorText = new TextLabel()
352                 {
353                     WidthResizePolicy = ResizePolicyType.UseNaturalSize,
354                     HeightResizePolicy = ResizePolicyType.Fixed,
355                     AccessibilityHidden = true,
356                 };
357                 if (valueIndicatorImage != null)
358                 {
359                     valueIndicatorImage.Add(valueIndicatorText);
360                 }
361                 valueIndicatorText.RaiseToTop();
362             }
363
364             return valueIndicatorText;
365         }
366
367         private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
368         {
369             if (e.PanGesture.State == Gesture.StateType.Started)
370             {
371                 if (direction == DirectionType.Horizontal)
372                 {
373                     currentSlidedOffset = slidedTrackImage.SizeWidth;
374                 }
375                 else if (direction == DirectionType.Vertical)
376                 {
377                     currentSlidedOffset = slidedTrackImage.SizeHeight;
378                 }
379
380                 if (isValueShown)
381                 {
382                     valueIndicatorImage.Show();
383                 }
384
385                 if (null != sliderSlidingStartedHandler)
386                 {
387                     SliderSlidingStartedEventArgs args = new SliderSlidingStartedEventArgs();
388                     args.CurrentValue = curValue;
389                     sliderSlidingStartedHandler(this, args);
390                 }
391                 UpdateState(isFocused, true);
392             }
393
394             if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
395             {
396                 if (direction == DirectionType.Horizontal)
397                 {
398                     CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
399                 }
400                 else if (direction == DirectionType.Vertical)
401                 {
402                     CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
403                 }
404                 UpdateState(isFocused, true);
405                 UpdateValue();
406             }
407
408             if (e.PanGesture.State == Gesture.StateType.Finished)
409             {
410                 // Update as finished position value
411                 if (direction == DirectionType.Horizontal)
412                 {
413                     CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
414                 }
415                 else if (direction == DirectionType.Vertical)
416                 {
417                     CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
418                 }
419                 UpdateValue();
420
421                 if (isValueShown)
422                 {
423                     valueIndicatorImage.Hide();
424                 }
425
426                 if (null != sliderSlidingFinishedHandler)
427                 {
428                     SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
429                     args.CurrentValue = curValue;
430                     sliderSlidingFinishedHandler(this, args);
431                 }
432
433                 UpdateState(isFocused, false);
434             }
435         }
436
437         // Relayout basic component: track, thumb and indicator
438         private void RelayoutBaseComponent(bool isInitial = true)
439         {
440             if (direction == DirectionType.Horizontal)
441             {
442                 if (slidedTrackImage != null)
443                 {
444                     slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
445                     slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
446                     slidedTrackImage.PositionUsesPivotPoint = true;
447                 }
448                 if (warningTrackImage != null)
449                 {
450                     warningTrackImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
451                     warningTrackImage.PivotPoint = NUI.PivotPoint.CenterRight;
452                     warningTrackImage.PositionUsesPivotPoint = true;
453                 }
454                 if (warningSlidedTrackImage != null)
455                 {
456                     warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
457                     warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
458                     warningSlidedTrackImage.PositionUsesPivotPoint = true;
459                 }
460                 if (thumbImage != null)
461                 {
462                     thumbImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
463                     thumbImage.PivotPoint = NUI.PivotPoint.Center;
464                     thumbImage.PositionUsesPivotPoint = true;
465                 }
466                 if (lowIndicatorImage != null)
467                 {
468                     lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
469                     lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
470                     lowIndicatorImage.PositionUsesPivotPoint = true;
471                 }
472                 if (highIndicatorImage != null)
473                 {
474                     highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
475                     highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
476                     highIndicatorImage.PositionUsesPivotPoint = true;
477                 }
478                 if (lowIndicatorText != null)
479                 {
480                     lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
481                     lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
482                     lowIndicatorText.PositionUsesPivotPoint = true;
483                 }
484                 if (highIndicatorText != null)
485                 {
486                     highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
487                     highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
488                     highIndicatorText.PositionUsesPivotPoint = true;
489                 }
490                 if (valueIndicatorImage != null)
491                 {
492                     valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
493                     valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
494                     valueIndicatorImage.PositionUsesPivotPoint = true;
495                     valueIndicatorImage.PositionY = -10.0f;
496                 }
497                 if (valueIndicatorText != null)
498                 {
499                     valueIndicatorText.ParentOrigin = NUI.ParentOrigin.Center;
500                     valueIndicatorText.PivotPoint = NUI.PivotPoint.Center;
501                     valueIndicatorText.PositionUsesPivotPoint = true;
502                 }
503                 if (panGestureDetector != null)
504                 {
505                     if (!isInitial)
506                     {
507                         panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
508                     }
509                     panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
510                 }
511             }
512             else if (direction == DirectionType.Vertical)
513             {
514                 if (slidedTrackImage != null)
515                 {
516                     slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
517                     slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
518                     slidedTrackImage.PositionUsesPivotPoint = true;
519                 }
520                 if (warningTrackImage != null)
521                 {
522                     warningTrackImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
523                     warningTrackImage.PivotPoint = NUI.PivotPoint.TopCenter;
524                     warningTrackImage.PositionUsesPivotPoint = true;
525                 }
526                 if (warningSlidedTrackImage != null)
527                 {
528                     warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
529                     warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
530                     warningSlidedTrackImage.PositionUsesPivotPoint = true;
531                 }
532                 if (thumbImage != null)
533                 {
534                     thumbImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
535                     thumbImage.PivotPoint = NUI.PivotPoint.Center;
536                     thumbImage.PositionUsesPivotPoint = true;
537                 }
538                 if (lowIndicatorImage != null)
539                 {
540                     lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
541                     lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
542                     lowIndicatorImage.PositionUsesPivotPoint = true;
543                 }
544                 if (highIndicatorImage != null)
545                 {
546                     highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
547                     highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
548                     highIndicatorImage.PositionUsesPivotPoint = true;
549                 }
550                 if (lowIndicatorText != null)
551                 {
552                     lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
553                     lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
554                     lowIndicatorText.PositionUsesPivotPoint = true;
555                 }
556                 if (highIndicatorText != null)
557                 {
558                     highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
559                     highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
560                     highIndicatorText.PositionUsesPivotPoint = true;
561                 }
562                 if (valueIndicatorImage != null)
563                 {
564                     valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
565                     valueIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
566                     valueIndicatorImage.PositionUsesPivotPoint = true;
567                     valueIndicatorImage.PositionX = -14.0f;
568                 }
569                 if (valueIndicatorText != null)
570                 {
571                     valueIndicatorText.ParentOrigin = NUI.ParentOrigin.Center;
572                     valueIndicatorText.PivotPoint = NUI.PivotPoint.Center;
573                     valueIndicatorText.PositionUsesPivotPoint = true;
574                 }
575                 if (panGestureDetector != null)
576                 {
577                     if (!isInitial)
578                     {
579                         panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
580                     }
581                     panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
582                 }
583             }
584         }
585
586         private int GetBgTrackLength()
587         {
588             int bgTrackLength = 0;
589
590             int lowIndicatorOffset = GetBgTrackLowIndicatorOffset();
591             int highIndicatorOffet = GetBgTrackHighIndicatorOffset();
592
593             if (direction == DirectionType.Horizontal)
594             {
595                 bgTrackLength = this.Size2D.Width - lowIndicatorOffset - highIndicatorOffet;
596             }
597             else if (direction == DirectionType.Vertical)
598             {
599                 bgTrackLength = this.Size2D.Height - lowIndicatorOffset - highIndicatorOffet;
600             }
601
602             return bgTrackLength;
603         }
604
605         /// <summary>
606         /// Get offset value of bgtrack's low indicator side.
607         /// </summary>
608         private int GetBgTrackLowIndicatorOffset()
609         {
610             int bgTrackLowIndicatorOffset = 0;
611             IndicatorType type = CurrentIndicatorType();
612
613             if (type == IndicatorType.None)
614             {
615                 if (direction == DirectionType.Horizontal)
616                 {
617                     bgTrackLowIndicatorOffset = (int)(thumbImage.Size.Width * 0.5f);
618                 }
619                 else if (direction == DirectionType.Vertical)
620                 {
621                     bgTrackLowIndicatorOffset = (int)(thumbImage.Size.Height * 0.5f);
622                 }
623             }
624             else if (type == IndicatorType.Image || type == IndicatorType.Text)
625             {// <lowIndicatorImage or Text> <spaceBetweenTrackAndIndicator> <bgTrack>
626                 Size lowIndicatorSize = (type == IndicatorType.Image) ? LowIndicatorImageSize() : LowIndicatorTextSize();
627                 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
628                 if (direction == DirectionType.Horizontal)
629                 {
630                     bgTrackLowIndicatorOffset = ((lowIndicatorSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorSize.Width)));
631                 }
632                 else if (direction == DirectionType.Vertical)
633                 {
634                     bgTrackLowIndicatorOffset = ((lowIndicatorSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorSize.Height)));
635                 }
636             }
637             return bgTrackLowIndicatorOffset;
638         }
639
640         /// <summary>
641         /// Get offset value of bgtrack's high indicator side.
642         /// </summary>
643         private int GetBgTrackHighIndicatorOffset()
644         {
645             int bgTrackHighIndicatorOffset = 0;
646             IndicatorType type = CurrentIndicatorType();
647
648             if (type == IndicatorType.None)
649             {
650                 if (direction == DirectionType.Horizontal)
651                 {
652                     bgTrackHighIndicatorOffset = (int)(thumbImage.Size.Width * 0.5f);
653                 }
654                 else if (direction == DirectionType.Vertical)
655                 {
656                     bgTrackHighIndicatorOffset = (int)(thumbImage.Size.Height * 0.5f);
657                 }
658             }
659             else if (type == IndicatorType.Image || type == IndicatorType.Text)
660             {// <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage or Text>
661                 Size highIndicatorSize = (type == IndicatorType.Image) ? HighIndicatorImageSize() : HighIndicatorTextSize();
662                 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
663                 if (direction == DirectionType.Horizontal)
664                 {
665                     bgTrackHighIndicatorOffset = ((highIndicatorSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorSize.Width)));
666                 }
667                 else if (direction == DirectionType.Vertical)
668                 {
669                     bgTrackHighIndicatorOffset = ((highIndicatorSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorSize.Height)));
670                 }
671             }
672             return bgTrackHighIndicatorOffset;
673         }
674
675         private void UpdateLowIndicatorSize()
676         {
677             if (lowIndicatorSize != null)
678             {
679                 if (lowIndicatorImage != null)
680                 {
681                     lowIndicatorImage.Size = lowIndicatorSize;
682                 }
683                 if (lowIndicatorText != null)
684                 {
685                     lowIndicatorText.Size = lowIndicatorSize;
686                 }
687             }
688             else
689             {
690                 if (lowIndicatorImage != null && lowIndicatorImage.Size != null)
691                 {
692                     lowIndicatorImage.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicatorImage.Size;
693                 }
694                 if (lowIndicatorText != null && lowIndicatorText.Size != null)
695                 {
696                     lowIndicatorText.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicator.Size;
697                 }
698             }
699         }
700
701         private void UpdateHighIndicatorSize()
702         {
703             if (highIndicatorSize != null)
704             {
705                 if (highIndicatorImage != null)
706                 {
707                     highIndicatorImage.Size = highIndicatorSize;
708                 }
709                 if (highIndicatorText != null)
710                 {
711                     highIndicatorText.Size = highIndicatorSize;
712                 }
713             }
714             else
715             {
716                 if (highIndicatorImage != null && highIndicatorImage.Size != null)
717                 {
718                     highIndicatorImage.Size = highIndicatorSize ?? (ViewStyle as SliderStyle)?.HighIndicatorImage.Size;
719                 }
720                 if (highIndicatorText != null && highIndicatorText.Size != null)
721                 {
722                     highIndicatorText.Size = highIndicatorSize ?? (ViewStyle as SliderStyle)?.HighIndicator.Size;
723                 }
724             }
725         }
726
727         private void UpdateBgTrackSize()
728         {
729             if (bgTrackImage == null)
730             {
731                 return;
732             }
733             int curTrackThickness = (int)CurrentTrackThickness();
734             int bgTrackLength = GetBgTrackLength();
735             if (direction == DirectionType.Horizontal)
736             {
737                 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
738             }
739             else if (direction == DirectionType.Vertical)
740             {
741                 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
742             }
743         }
744
745         private void UpdateBgTrackPosition()
746         {
747             if (bgTrackImage == null)
748             {
749                 return;
750             }
751
752             int lowIndicatorOffset = GetBgTrackLowIndicatorOffset();
753             int highIndicatorOffet = GetBgTrackHighIndicatorOffset();
754
755             if (direction == DirectionType.Horizontal)
756             {
757                 bgTrackImage.Position2D = new Position2D((lowIndicatorOffset - highIndicatorOffet) / 2, 0);
758             }
759             else if (direction == DirectionType.Vertical)
760             {
761                 bgTrackImage.Position2D = new Position2D(0, (highIndicatorOffet - lowIndicatorOffset) / 2);
762             }
763         }
764
765         private void UpdateValue()
766         {
767             if (slidedTrackImage == null)
768             {
769                 return;
770             }
771             if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
772             {
773                 return;
774             }
775
776             float ratio = 0;
777             ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
778
779             uint curTrackThickness = CurrentTrackThickness();
780
781             if (direction == DirectionType.Horizontal)
782             {
783                 if (LayoutDirection == ViewLayoutDirectionType.RTL)
784                 {
785                     ratio = 1.0f - ratio;
786                 }
787                 float slidedTrackLength = (float)GetBgTrackLength() * ratio;
788                 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
789                 thumbImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
790                 thumbImage.RaiseToTop();
791             }
792             else if (direction == DirectionType.Vertical)
793             {
794                 float slidedTrackLength = (float)GetBgTrackLength() * ratio;
795                 slidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(slidedTrackLength + round)); //Add const round to reach Math.Round function.
796                 thumbImage.Position = new Position(0, -slidedTrackImage.Size2D.Height);
797                 thumbImage.RaiseToTop();
798             }
799
800             // Update the track and thumb when the value is over warning value.
801             if (curValue >= warningStartValue)
802             {
803                 if (direction == DirectionType.Horizontal)
804                 {
805                     warningSlidedTrackImage.Size2D = new Size2D((int)(((curValue - warningStartValue) / 100) * this.Size2D.Width), (int)curTrackThickness);
806                 }
807                 else if (direction == DirectionType.Vertical)
808                 {
809                     warningSlidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(((curValue - warningStartValue) / 100) * this.Size2D.Height));
810                 }
811
812                 if (warningThumbColor != null && thumbImage.Color.NotEqualTo(warningThumbColor))
813                 {
814                     thumbImage.Color = warningThumbColor;
815                 }
816                 if (warningThumbImageUrl != null && !thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
817                 {
818                     thumbImage.ResourceUrl = warningThumbImageUrl;
819                 }
820             }
821             else
822             {
823                 warningSlidedTrackImage.Size2D = new Size2D(0, 0);
824                 if (warningThumbColor != null && thumbImage.Color.EqualTo(warningThumbColor))
825                 {
826                     thumbImage.Color = thumbColor;
827                 }
828                 if (warningThumbImageUrl != null && thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
829                 {
830                     thumbImage.ResourceUrl = thumbImageUrl;
831                 }
832             }
833         }
834
835         private uint CurrentTrackThickness()
836         {
837             uint curTrackThickness = 0;
838             if (trackThickness != null)
839             {
840                 curTrackThickness = trackThickness.Value;
841             }
842             else
843             {
844                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackThickness != null)
845                 {
846                     curTrackThickness = sliderStyle.TrackThickness.Value;
847                 }
848             }
849             return curTrackThickness;
850         }
851
852         private uint CurrentSpaceBetweenTrackAndIndicator()
853         {
854             uint curSpace = 0;
855             if (spaceBetweenTrackAndIndicator != null)
856             {
857                 curSpace = spaceBetweenTrackAndIndicator.Start;
858             }
859             else
860             {
861                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackPadding != null)
862                 {
863                     curSpace = sliderStyle.TrackPadding.Start;
864                 }
865             }
866             return curSpace;
867         }
868
869         private void UpdateWarningTrackSize()
870         {
871             if (warningTrackImage == null)
872             {
873                 return;
874             }
875
876             int curTrackThickness = (int)CurrentTrackThickness();
877             float warningTrackLength = maxValue - warningStartValue;
878             if (direction == DirectionType.Horizontal)
879             {
880                 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Width;
881                 warningTrackImage.Size2D = new Size2D((int)warningTrackLength, curTrackThickness);
882             }
883             else if (direction == DirectionType.Vertical)
884             {
885                 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Height;
886                 warningTrackImage.Size2D = new Size2D(curTrackThickness, (int)warningTrackLength);
887             }
888         }
889
890         private IndicatorType CurrentIndicatorType()
891         {
892             IndicatorType type = IndicatorType.None;
893             if (ViewStyle is SliderStyle sliderStyle)
894             {
895                 type = (IndicatorType)sliderStyle.IndicatorType;
896             }
897             return type;
898         }
899
900         private Size LowIndicatorImageSize()
901         {
902             Size size = new Size(0, 0);
903             if (lowIndicatorSize != null)
904             {
905                 size = lowIndicatorSize;
906             }
907             else
908             {
909                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null)
910                 {
911                     size = sliderStyle.LowIndicatorImage.Size;
912                 }
913             }
914             return size;
915         }
916
917         private Size HighIndicatorImageSize()
918         {
919             Size size = new Size(0, 0);
920             if (highIndicatorSize != null)
921             {
922                 size = highIndicatorSize;
923             }
924             else
925             {
926                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null)
927                 {
928                     size = sliderStyle.HighIndicatorImage.Size;
929                 }
930             }
931             return size;
932         }
933
934         private Size LowIndicatorTextSize()
935         {
936             Size size = new Size(0, 0);
937             if (lowIndicatorSize != null)
938             {
939                 size = lowIndicatorSize;
940             }
941             else
942             {
943                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null)
944                 {
945                     size = sliderStyle.LowIndicator.Size;
946                 }
947             }
948             return size;
949         }
950
951         private Size HighIndicatorTextSize()
952         {
953             Size size = new Size(0, 0);
954             if (highIndicatorSize != null)
955             {
956                 size = highIndicatorSize;
957             }
958             else
959             {
960                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null)
961                 {
962                     size = sliderStyle.HighIndicator.Size;
963                 }
964             }
965             return size;
966         }
967     }
968 }