[NUI][TCSACR-483] Remove Slider deprecated events and eventArgs
[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 float currentSlidedOffset;
89         private EventHandler<SliderValueChangedEventArgs> sliderValueChangedHandler;
90         private EventHandler<SliderSlidingStartedEventArgs> sliderSlidingStartedHandler;
91         private EventHandler<SliderSlidingFinishedEventArgs> sliderSlidingFinishedHandler;
92
93         bool isFocused = false;
94         bool isPressed = false;
95
96         private void Initialize()
97         {
98             AccessibilityHighlightable = true;
99
100             currentSlidedOffset = 0;
101             isFocused = false;
102             isPressed = false;
103             LayoutDirectionChanged += OnLayoutDirectionChanged;
104
105             this.TouchEvent += OnTouchEventForTrack;
106
107             panGestureDetector = new PanGestureDetector();
108             panGestureDetector.Attach(this);
109             panGestureDetector.Detected += OnPanGestureDetected;
110         }
111
112         private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
113         {
114             RelayoutRequest();
115         }
116
117         private ImageView CreateSlidedTrack()
118         {
119             if (null == slidedTrackImage)
120             {
121                 slidedTrackImage = new ImageView()
122                 {
123                     WidthResizePolicy = ResizePolicyType.Fixed,
124                     HeightResizePolicy = ResizePolicyType.Fixed
125                 };
126
127                 if (bgTrackImage != null)
128                 {
129                     bgTrackImage.Add(slidedTrackImage);
130                 }
131             }
132
133             return slidedTrackImage;
134         }
135
136         private ImageView CreateWarningTrack()
137         {
138             if (null == warningTrackImage)
139             {
140                 warningTrackImage = new ImageView()
141                 {
142                     WidthResizePolicy = ResizePolicyType.Fixed,
143                     HeightResizePolicy = ResizePolicyType.Fixed
144                 };
145
146                 if (bgTrackImage != null)
147                 {
148                     bgTrackImage.Add(warningTrackImage);
149                 }
150
151                 if (warningSlidedTrackImage != null)
152                 {
153                     warningTrackImage.Add(warningSlidedTrackImage);
154                 }
155
156                 if (slidedTrackImage != null)
157                 {
158                     warningTrackImage.RaiseAbove(slidedTrackImage);
159                 }
160             }
161
162             return warningTrackImage;
163         }
164
165         private ImageView CreateWarningSlidedTrack()
166         {
167             if (null == warningSlidedTrackImage)
168             {
169                 warningSlidedTrackImage = new ImageView()
170                 {
171                     WidthResizePolicy = ResizePolicyType.Fixed,
172                     HeightResizePolicy = ResizePolicyType.Fixed
173                 };
174
175                 if (warningTrackImage != null)
176                 {
177                     warningTrackImage.Add(warningSlidedTrackImage);
178                 }
179             }
180
181             return warningSlidedTrackImage;
182         }
183
184         private TextLabel CreateLowIndicatorText()
185         {
186             if (null == lowIndicatorText)
187             {
188                 lowIndicatorText = new TextLabel()
189                 {
190                     WidthResizePolicy = ResizePolicyType.Fixed,
191                     HeightResizePolicy = ResizePolicyType.Fixed
192                 };
193                 this.Add(lowIndicatorText);
194             }
195
196             return lowIndicatorText;
197         }
198
199         private TextLabel CreateHighIndicatorText()
200         {
201             if (null == highIndicatorText)
202             {
203                 highIndicatorText = new TextLabel()
204                 {
205                     WidthResizePolicy = ResizePolicyType.Fixed,
206                     HeightResizePolicy = ResizePolicyType.Fixed
207                 };
208                 this.Add(highIndicatorText);
209             }
210
211             return highIndicatorText;
212         }
213
214         private ImageView CreateBackgroundTrack()
215         {
216             if (null == bgTrackImage)
217             {
218                 bgTrackImage = new ImageView()
219                 {
220                     WidthResizePolicy = ResizePolicyType.Fixed,
221                     HeightResizePolicy = ResizePolicyType.Fixed,
222                     ParentOrigin = Tizen.NUI.ParentOrigin.Center,
223                     PivotPoint = Tizen.NUI.PivotPoint.Center,
224                     PositionUsesPivotPoint = true
225                 };
226                 this.Add(bgTrackImage);
227
228                 if (null != slidedTrackImage)
229                 {
230                     bgTrackImage.Add(slidedTrackImage);
231                 }
232                 if (null != warningTrackImage)
233                 {
234                     bgTrackImage.Add(warningTrackImage);
235                 }
236                 if (null != thumbImage)
237                 {
238                     bgTrackImage.Add(thumbImage);
239                     thumbImage.RaiseToTop();
240                 }
241             }
242
243             return bgTrackImage;
244         }
245
246         private ImageView CreateThumb()
247         {
248             if (null == thumbImage)
249             {
250                 thumbImage = new ImageView()
251                 {
252                     WidthResizePolicy = ResizePolicyType.Fixed,
253                     HeightResizePolicy = ResizePolicyType.Fixed,
254                     ParentOrigin = NUI.ParentOrigin.Center,
255                     PivotPoint = NUI.PivotPoint.Center,
256                     PositionUsesPivotPoint = true,
257                     EnableControlState = true
258                 };
259                 if (bgTrackImage != null)
260                 {
261                     bgTrackImage.Add(thumbImage);
262                 }
263                 thumbImage.RaiseToTop();
264                 thumbImage.TouchEvent += OnTouchEventForThumb;
265             }
266
267             return thumbImage;
268         }
269
270         private ImageView CreateValueIndicator()
271         {
272             if (valueIndicatorImage == null)
273             {
274                 valueIndicatorImage = new ImageView()
275                 {
276                     PositionUsesPivotPoint = true,
277                     ParentOrigin = Tizen.NUI.ParentOrigin.Center,
278                     PivotPoint = Tizen.NUI.PivotPoint.Center,
279                     WidthResizePolicy = ResizePolicyType.Fixed,
280                     HeightResizePolicy = ResizePolicyType.Fixed,
281                 };
282                 if (valueIndicatorText != null)
283                 {
284                     valueIndicatorImage.Add(valueIndicatorText);
285                 }
286                 // TODO : ValueIndicator can be a child of Thumb
287                 this.Add(valueIndicatorImage);
288             }
289
290             valueIndicatorImage.Hide();
291             return valueIndicatorImage;
292         }
293
294         private TextLabel CreateValueIndicatorText()
295         {
296             if (null == valueIndicatorText)
297             {
298                 valueIndicatorText = new TextLabel()
299                 {
300                     WidthResizePolicy = ResizePolicyType.Fixed,
301                     HeightResizePolicy = ResizePolicyType.Fixed
302                 };
303                 if (valueIndicatorImage != null)
304                 {
305                     valueIndicatorImage.Add(valueIndicatorText);
306                 }
307             }
308
309             return valueIndicatorText;
310         }
311
312         private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
313         {
314             if (e.PanGesture.State == Gesture.StateType.Started)
315             {
316                 if (direction == DirectionType.Horizontal)
317                 {
318                     currentSlidedOffset = slidedTrackImage.SizeWidth;
319                 }
320                 else if (direction == DirectionType.Vertical)
321                 {
322                     currentSlidedOffset = slidedTrackImage.SizeHeight;
323                 }
324
325                 if (isValueShown)
326                 {
327                     valueIndicatorImage.Show();
328                 }
329
330                 if (null != sliderSlidingStartedHandler)
331                 {
332                     SliderSlidingStartedEventArgs args = new SliderSlidingStartedEventArgs();
333                     args.CurrentValue = curValue;
334                     sliderSlidingStartedHandler(this, args);
335                 }
336                 UpdateState(isFocused, true);
337             }
338
339             if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
340             {
341                 if (direction == DirectionType.Horizontal)
342                 {
343                     CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
344                 }
345                 else if (direction == DirectionType.Vertical)
346                 {
347                     CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
348                 }
349                 UpdateValue();
350             }
351
352             if (e.PanGesture.State == Gesture.StateType.Finished)
353             {
354                 if (isValueShown)
355                 {
356                     valueIndicatorImage.Hide();
357                 }
358
359                 if (null != sliderSlidingFinishedHandler)
360                 {
361                     SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
362                     args.CurrentValue = curValue;
363                     sliderSlidingFinishedHandler(this, args);
364                 }
365
366                 UpdateState(isFocused, false);
367             }
368         }
369
370         // Relayout basic component: track, thumb and indicator
371         private void RelayoutBaseComponent(bool isInitial = true)
372         {
373             if (direction == DirectionType.Horizontal)
374             {
375                 if (slidedTrackImage != null)
376                 {
377                     slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
378                     slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
379                     slidedTrackImage.PositionUsesPivotPoint = true;
380                 }
381                 if (warningTrackImage != null)
382                 {
383                     warningTrackImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
384                     warningTrackImage.PivotPoint = NUI.PivotPoint.CenterRight;
385                     warningTrackImage.PositionUsesPivotPoint = true;
386                 }
387                 if (warningSlidedTrackImage != null)
388                 {
389                     warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
390                     warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
391                     warningSlidedTrackImage.PositionUsesPivotPoint = true;
392                 }
393                 if (thumbImage != null)
394                 {
395                     thumbImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
396                     thumbImage.PivotPoint = NUI.PivotPoint.Center;
397                     thumbImage.PositionUsesPivotPoint = true;
398                 }
399                 if (lowIndicatorImage != null)
400                 {
401                     lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
402                     lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
403                     lowIndicatorImage.PositionUsesPivotPoint = true;
404                 }
405                 if (highIndicatorImage != null)
406                 {
407                     highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
408                     highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
409                     highIndicatorImage.PositionUsesPivotPoint = true;
410                 }
411                 if (lowIndicatorText != null)
412                 {
413                     lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
414                     lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
415                     lowIndicatorText.PositionUsesPivotPoint = true;
416                 }
417                 if (highIndicatorText != null)
418                 {
419                     highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
420                     highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
421                     highIndicatorText.PositionUsesPivotPoint = true;
422                 }
423                 if (valueIndicatorImage != null)
424                 {
425                     valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopLeft;
426                     valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
427                     valueIndicatorImage.PositionUsesPivotPoint = true;
428                 }
429                 if (valueIndicatorText != null)
430                 {
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
435                 }
436                 if (panGestureDetector != null)
437                 {
438                     if (!isInitial)
439                     {
440                         panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
441                     }
442                     panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
443                 }
444             }
445             else if (direction == DirectionType.Vertical)
446             {
447                 if (slidedTrackImage != null)
448                 {
449                     slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
450                     slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
451                     slidedTrackImage.PositionUsesPivotPoint = true;
452                 }
453                 if (warningTrackImage != null)
454                 {
455                     warningTrackImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
456                     warningTrackImage.PivotPoint = NUI.PivotPoint.TopCenter;
457                     warningTrackImage.PositionUsesPivotPoint = true;
458                 }
459                 if (warningSlidedTrackImage != null)
460                 {
461                     warningSlidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
462                     warningSlidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
463                     warningSlidedTrackImage.PositionUsesPivotPoint = true;
464                 }
465                 if (thumbImage != null)
466                 {
467                     thumbImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
468                     thumbImage.PivotPoint = NUI.PivotPoint.Center;
469                     thumbImage.PositionUsesPivotPoint = true;
470                 }
471                 if (lowIndicatorImage != null)
472                 {
473                     lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
474                     lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
475                     lowIndicatorImage.PositionUsesPivotPoint = true;
476                 }
477                 if (highIndicatorImage != null)
478                 {
479                     highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
480                     highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
481                     highIndicatorImage.PositionUsesPivotPoint = true;
482                 }
483                 if (lowIndicatorText != null)
484                 {
485                     lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
486                     lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
487                     lowIndicatorText.PositionUsesPivotPoint = true;
488                 }
489                 if (highIndicatorText != null)
490                 {
491                     highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
492                     highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
493                     highIndicatorText.PositionUsesPivotPoint = true;
494                 }
495                 if (valueIndicatorImage != null)
496                 {
497                     valueIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
498                     valueIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
499                     valueIndicatorImage.PositionUsesPivotPoint = true;
500                 }
501                 if (valueIndicatorText != null)
502                 {
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
507                 }
508                 if (panGestureDetector != null)
509                 {
510                     if (!isInitial)
511                     {
512                         panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
513                     }
514                     panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
515                 }
516             }
517         }
518
519         private int BgTrackLength()
520         {
521             int bgTrackLength = 0;
522             IndicatorType type = CurrentIndicatorType();
523
524             if (type == IndicatorType.None)
525             {
526                 if (direction == DirectionType.Horizontal)
527                 {
528                     bgTrackLength = this.Size2D.Width;
529                 }
530                 else if (direction == DirectionType.Vertical)
531                 {
532                     bgTrackLength = this.Size2D.Height;
533                 }
534             }
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)
541                 {
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;
545                 }
546                 else if (direction == DirectionType.Vertical)
547                 {
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;
551                 }
552             }
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)
559                 {
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;
563                 }
564                 else if (direction == DirectionType.Vertical)
565                 {
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;
569                 }
570             }
571             return bgTrackLength;
572         }
573
574         private void UpdateLowIndicatorSize()
575         {
576             if (lowIndicatorSize != null)
577             {
578                 if (lowIndicatorImage != null)
579                 {
580                     lowIndicatorImage.Size = lowIndicatorSize;
581                 }
582                 if (lowIndicatorText != null)
583                 {
584                     lowIndicatorText.Size = lowIndicatorSize;
585                 }
586             }
587             else
588             {
589                 if (lowIndicatorImage != null && lowIndicatorImage != null && lowIndicatorImage.Size != null)
590                 {
591                     lowIndicatorImage.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicatorImage.Size;
592                 }
593                 if (lowIndicatorText != null && lowIndicatorText != null && lowIndicatorText.Size != null)
594                 {
595                     lowIndicatorText.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicator.Size;
596                 }
597             }
598         }
599
600         private void UpdateBgTrackSize()
601         {
602             if (bgTrackImage == null)
603             {
604                 return;
605             }
606             int curTrackThickness = (int)CurrentTrackThickness();
607             int bgTrackLength = BgTrackLength();
608             if (direction == DirectionType.Horizontal)
609             {
610                 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
611             }
612             else if (direction == DirectionType.Vertical)
613             {
614                 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
615             }
616         }
617
618         private void UpdateBgTrackPosition()
619         {
620             if (bgTrackImage == null)
621             {
622                 return;
623             }
624             IndicatorType type = CurrentIndicatorType();
625
626             if (type == IndicatorType.None)
627             {
628                 bgTrackImage.Position2D = new Position2D(0, 0);
629             }
630             else if (type == IndicatorType.Image)
631             {
632                 Size lowIndicatorImageSize = LowIndicatorImageSize();
633                 Size highIndicatorImageSize = HighIndicatorImageSize();
634                 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
635                 if (direction == DirectionType.Horizontal)
636                 {
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);
640                 }
641                 else if (direction == DirectionType.Vertical)
642                 {
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);
646                 }
647             }
648             else if (type == IndicatorType.Text)
649             {
650                 Size lowIndicatorTextSize = LowIndicatorTextSize();
651                 Size highIndicatorTextSize = HighIndicatorTextSize();
652                 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
653                 if (direction == DirectionType.Horizontal)
654                 {
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);
658                 }
659                 else if (direction == DirectionType.Vertical)
660                 {
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));
664                 }
665             }
666         }
667
668         private void UpdateValue()
669         {
670             if (slidedTrackImage == null)
671             {
672                 return;
673             }
674             if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
675             {
676                 return;
677             }
678
679             float ratio = 0;
680             ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
681
682             uint curTrackThickness = CurrentTrackThickness();
683
684             if (direction == DirectionType.Horizontal)
685             {
686                 if (LayoutDirection == ViewLayoutDirectionType.RTL)
687                 {
688                     ratio = 1.0f - ratio;
689                 }
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();
694
695                 if (isValueShown)
696                 {
697                     valueIndicatorImage.Position = new Position(slidedTrackImage.Size2D.Width, 0);
698                 }
699             }
700             else if (direction == DirectionType.Vertical)
701             {
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();
706
707                 if (isValueShown)
708                 {
709                     valueIndicatorImage.Position = new Position(0, -(slidedTrackImage.Size2D.Height + thumbImage.Size.Height / 2));
710                 }
711             }
712
713             // Update the track and thumb when the value is over warning value.
714             if (curValue >= warningStartValue)
715             {
716                 if (direction == DirectionType.Horizontal)
717                 {
718                     warningSlidedTrackImage.Size2D = new Size2D((int)(((curValue - warningStartValue) / 100) * this.Size2D.Width), (int)curTrackThickness);
719                 }
720                 else if (direction == DirectionType.Vertical)
721                 {
722                     warningSlidedTrackImage.Size2D = new Size2D((int)curTrackThickness, (int)(((curValue - warningStartValue) / 100) * this.Size2D.Height));
723                 }
724
725                 if (warningThumbColor != null && thumbImage.Color.NotEqualTo(warningThumbColor))
726                 {
727                     thumbImage.Color = warningThumbColor;
728                 }
729                 if (warningThumbImageUrl != null && !thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
730                 {
731                     thumbImage.ResourceUrl = warningThumbImageUrl;
732                 }
733             }
734             else
735             {
736                 warningSlidedTrackImage.Size2D = new Size2D(0, 0);
737                 if (warningThumbColor != null && thumbImage.Color.EqualTo(warningThumbColor))
738                 {
739                     thumbImage.Color = thumbColor;
740                 }
741                 if (warningThumbImageUrl != null && thumbImage.ResourceUrl.Equals(warningThumbImageUrl))
742                 {
743                     thumbImage.ResourceUrl = thumbImageUrl;
744                 }
745             }
746         }
747
748         private uint CurrentTrackThickness()
749         {
750             uint curTrackThickness = 0;
751             if (trackThickness != null)
752             {
753                 curTrackThickness = trackThickness.Value;
754             }
755             else
756             {
757                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackThickness != null)
758                 {
759                     curTrackThickness = sliderStyle.TrackThickness.Value;
760                 }
761             }
762             return curTrackThickness;
763         }
764
765         private uint CurrentSpaceBetweenTrackAndIndicator()
766         {
767             uint curSpace = 0;
768             if (spaceBetweenTrackAndIndicator != null)
769             {
770                 curSpace = spaceBetweenTrackAndIndicator.Start;
771             }
772             else
773             {
774                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackPadding != null)
775                 {
776                     curSpace = sliderStyle.TrackPadding.Start;
777                 }
778             }
779             return curSpace;
780         }
781
782         private void UpdateWarningTrackSize()
783         {
784             if (warningTrackImage == null)
785             {
786                 return;
787             }
788
789             int curTrackThickness = (int)CurrentTrackThickness();
790             float warningTrackLength = maxValue - warningStartValue;
791             if (direction == DirectionType.Horizontal)
792             {
793                 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Width;
794                 warningTrackImage.Size2D = new Size2D((int)warningTrackLength, curTrackThickness);
795             }
796             else if (direction == DirectionType.Vertical)
797             {
798                 warningTrackLength = (warningTrackLength / 100) * this.Size2D.Height;
799                 warningTrackImage.Size2D = new Size2D(curTrackThickness, (int)warningTrackLength);
800             }
801         }
802
803         private IndicatorType CurrentIndicatorType()
804         {
805             IndicatorType type = IndicatorType.None;
806             if (ViewStyle is SliderStyle sliderStyle)
807             {
808                 type = (IndicatorType)sliderStyle.IndicatorType;
809             }
810             return type;
811         }
812
813         private Size LowIndicatorImageSize()
814         {
815             Size size = new Size(0, 0);
816             if (lowIndicatorSize != null)
817             {
818                 size = lowIndicatorSize;
819             }
820             else
821             {
822                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null)
823                 {
824                     size = sliderStyle.LowIndicatorImage.Size;
825                 }
826             }
827             return size;
828         }
829
830         private Size HighIndicatorImageSize()
831         {
832             Size size = new Size(0, 0);
833             if (highIndicatorSize != null)
834             {
835                 size = highIndicatorSize;
836             }
837             else
838             {
839                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null)
840                 {
841                     size = sliderStyle.HighIndicatorImage.Size;
842                 }
843             }
844             return size;
845         }
846
847         private Size LowIndicatorTextSize()
848         {
849             Size size = new Size(0, 0);
850             if (lowIndicatorSize != null)
851             {
852                 size = lowIndicatorSize;
853             }
854             else
855             {
856                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null)
857                 {
858                     size = sliderStyle.LowIndicator.Size;
859                 }
860             }
861             return size;
862         }
863
864         private Size HighIndicatorTextSize()
865         {
866             Size size = new Size(0, 0);
867             if (highIndicatorSize != null)
868             {
869                 size = highIndicatorSize;
870             }
871             else
872             {
873                 if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null)
874                 {
875                     size = sliderStyle.HighIndicator.Size;
876                 }
877             }
878             return size;
879         }
880     }
881 }