[NUI] Add ScrollPosition and ScrollCurrentPosition to ScrollbarBase (#1872)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Scrollbar.cs
1 /*
2  * Copyright(c) 2020 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 using System;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// The Scrollbar is a component that contains track and thumb to indicate the current scrolled position of a scrollable object.
26     /// </summary>
27     [EditorBrowsable(EditorBrowsableState.Never)]
28     public class Scrollbar : ScrollbarBase
29     {
30         #region Fields
31
32         /// <summary>Bindable property of TrackThickness</summary>
33         [EditorBrowsable(EditorBrowsableState.Never)]
34         public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(float), typeof(Scrollbar), default(float), propertyChanged: (bindable, oldValue, newValue) =>
35         {
36             var instance = ((Scrollbar)bindable);
37             var thickness = (float?)newValue;
38
39             instance.scrollbarStyle.TrackThickness = thickness;
40             instance.UpdateTrackThickness(thickness ?? 0);
41         },
42         defaultValueCreator: (bindable) =>
43         {
44             return ((Scrollbar)bindable).scrollbarStyle.TrackThickness ?? 0;
45         });
46
47         /// <summary>Bindable property of ThumbThickness</summary>
48         [EditorBrowsable(EditorBrowsableState.Never)]
49         public static readonly BindableProperty ThumbThicknessProperty = BindableProperty.Create(nameof(ThumbThickness), typeof(float), typeof(Scrollbar), default(float), propertyChanged: (bindable, oldValue, newValue) =>
50         {
51             var instance = ((Scrollbar)bindable);
52             var thickness = (float?)newValue;
53
54             instance.scrollbarStyle.ThumbThickness = thickness;
55             instance.UpdateThumbThickness(thickness ?? 0);
56         },
57         defaultValueCreator: (bindable) =>
58         {
59             return ((Scrollbar)bindable).scrollbarStyle.ThumbThickness ?? 0;
60         });
61
62         /// <summary>Bindable property of TrackColor</summary>
63         [EditorBrowsable(EditorBrowsableState.Never)]
64         public static readonly BindableProperty TrackColorProperty = BindableProperty.Create(nameof(TrackColor), typeof(Color), typeof(Scrollbar), null, propertyChanged: (bindable, oldValue, newValue) =>
65         {
66             var instance = ((Scrollbar)bindable);
67             var color = (Color)newValue;
68
69             instance.scrollbarStyle.TrackColor = color;
70             instance.UpdateTrackColor(color);
71         },
72         defaultValueCreator: (bindable) =>
73         {
74             return ((Scrollbar)bindable).scrollbarStyle.TrackColor;
75         });
76
77         /// <summary>Bindable property of ThumbColor</summary>
78         [EditorBrowsable(EditorBrowsableState.Never)]
79         public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(Scrollbar), null, propertyChanged: (bindable, oldValue, newValue) =>
80         {
81             var instance = ((Scrollbar)bindable);
82             var color = (Color)newValue;
83
84             instance.scrollbarStyle.ThumbColor = color;
85             instance.UpdateThumbColor(color);
86         },
87         defaultValueCreator: (bindable) =>
88         {
89             return ((Scrollbar)bindable).scrollbarStyle.ThumbColor;
90         });
91
92         /// <summary>Bindable property of TrackPadding</summary>
93         [EditorBrowsable(EditorBrowsableState.Never)]
94         public static readonly BindableProperty TrackPaddingProperty = BindableProperty.Create(nameof(TrackPadding), typeof(Extents), typeof(Scrollbar), null, propertyChanged: (bindable, oldValue, newValue) =>
95         {
96             var instance = ((Scrollbar)bindable);
97             var trackPadding = (Extents)newValue;
98
99             instance.scrollbarStyle.TrackPadding = trackPadding;
100             instance.UpdateTrackPadding(trackPadding);
101         },
102         defaultValueCreator: (bindable) =>
103         {
104             return ((Scrollbar)bindable).scrollbarStyle.TrackPadding;
105         });
106
107         private ColorVisual trackVisual;
108         private ColorVisual thumbVisual;
109         private Animation thumbPositionAnimation;
110         private Animation thumbSizeAnimation;
111         private Calculator calculator;
112         private Size containerSize = new Size(0, 0);
113         private ScrollbarStyle scrollbarStyle => ViewStyle as ScrollbarStyle;
114         private bool mScrollEnabled = true;
115         private float previousPosition;
116
117         #endregion Fields
118
119
120         #region Constructors
121
122         /// <summary>
123         /// Create an empty Scrollbar.
124         /// </summary>
125         public Scrollbar() : base(new ScrollbarStyle())
126         {
127         }
128
129         /// <summary>
130         /// Create a Scrollbar and initialize with properties.
131         /// </summary>
132         /// <param name="contentLength">The length of the scrollable content area.</param>
133         /// <param name="viewportLength">The length of the viewport representing the amount of visible content.</param>
134         /// <param name="currentPosition">The current position of the viewport in scrollable content area. This is the viewport's top position if the scroller is vertical, otherwise, left.</param>
135         /// <param name="isHorizontal">Whether the direction of scrolling is horizontal or not. It is vertical by default.</param>
136         [EditorBrowsable(EditorBrowsableState.Never)]
137         public Scrollbar(float contentLength, float viewportLength, float currentPosition, bool isHorizontal = false) : base(new ScrollbarStyle())
138         {
139             Initialize(contentLength, viewportLength, currentPosition, isHorizontal);
140         }
141
142         /// <summary>
143         /// Create an empty Scrollbar with a ScrollbarStyle instance to set style properties.
144         /// </summary>
145         [EditorBrowsable(EditorBrowsableState.Never)]
146         public Scrollbar(ScrollbarStyle style) : base(style)
147         {
148         }
149
150         /// <summary>
151         /// Static constructor to initialize bindable properties when loading.
152         /// </summary>
153         static Scrollbar()
154         {
155         }
156
157         #endregion Constructors
158
159
160         #region Properties
161
162         /// <summary>
163         /// Return a copied Style instance of Scrollbar
164         /// </summary>
165         /// <remarks>
166         /// It returns copied Style instance and changing it does not effect to the Scrollbar.
167         /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
168         /// </remarks>
169         [EditorBrowsable(EditorBrowsableState.Never)]
170         public new ScrollbarStyle Style
171         {
172             get
173             {
174                 var result = new ScrollbarStyle(scrollbarStyle);
175                 result.CopyPropertiesFromView(this);
176                 return result;
177             }
178         }
179
180         /// <summary>
181         /// The thickness of the track.
182         /// </summary>
183         [EditorBrowsable(EditorBrowsableState.Never)]
184         public float TrackThickness
185         {
186             get => (float)GetValue(TrackThicknessProperty);
187             set => SetValue(TrackThicknessProperty, value);
188         }
189
190         /// <summary>
191         /// The thickness of the thumb.
192         /// </summary>
193         [EditorBrowsable(EditorBrowsableState.Never)]
194         public float ThumbThickness
195         {
196             get => (float)GetValue(ThumbThicknessProperty);
197             set => SetValue(ThumbThicknessProperty, value);
198         }
199
200         /// <summary>
201         /// The color of the track part.
202         /// </summary>
203         [EditorBrowsable(EditorBrowsableState.Never)]
204         public Color TrackColor
205         {
206             get => (Color)GetValue(TrackColorProperty);
207             set => SetValue(TrackColorProperty, value);
208         }
209
210         /// <summary>
211         /// The color of the thumb part.
212         /// </summary>
213         [EditorBrowsable(EditorBrowsableState.Never)]
214         public Color ThumbColor
215         {
216             get => (Color)GetValue(ThumbColorProperty);
217             set => SetValue(ThumbColorProperty, value);
218         }
219
220         /// <summary>
221         /// The padding value of the track.
222         /// </summary>
223         [EditorBrowsable(EditorBrowsableState.Never)]
224         public Extents TrackPadding
225         {
226             get => (Extents)GetValue(TrackPaddingProperty);
227             set => SetValue(TrackPaddingProperty, value);
228         }
229
230         #endregion Properties
231
232
233         #region Methods
234
235         /// <inheritdoc/>
236         [EditorBrowsable(EditorBrowsableState.Never)]
237         public override void Initialize(float contentLength, float viewportLength, float currentPosition, bool isHorizontal = false)
238         {
239             if (isHorizontal)
240             {
241                 calculator = new HorizontalCalculator(contentLength > 0.0f ? contentLength : 0.0f, viewportLength, currentPosition);
242             }
243             else
244             {
245                 calculator = new VerticalCalculator(contentLength > 0.0f ? contentLength : 0.0f, viewportLength, currentPosition);
246             }
247
248             thumbPositionAnimation?.Stop();
249             thumbPositionAnimation = null;
250
251             thumbSizeAnimation?.Stop();
252             thumbSizeAnimation = null;
253
254             Size trackSize = calculator.CalculateTrackSize(TrackThickness, containerSize, TrackPadding);
255             Vector2 trackPosition = calculator.CalculateTrackPosition(TrackPadding);
256             Size thumbSize = calculator.CalculateThumbSize(ThumbThickness, trackSize);
257             Vector2 thumbPosition = calculator.CalculateThumbPosition(trackSize, thumbSize, TrackPadding);
258
259             if (trackVisual == null)
260             {
261                 trackVisual = new ColorVisual
262                 {
263                     SuppressUpdateVisual = true,
264                     Color = TrackColor,
265                     SizePolicy = VisualTransformPolicyType.Absolute,
266                     Origin = calculator.CalculatorTrackAlign(),
267                     AnchorPoint = calculator.CalculatorTrackAlign(),
268                     Size = trackSize,
269                     Position = trackPosition,
270                 };
271
272                 AddVisual("Track", trackVisual);
273             }
274             else
275             {
276                 trackVisual.Size = trackSize;
277                 trackVisual.Position = trackPosition;
278                 trackVisual.UpdateVisual(true);
279             }
280
281             if (thumbVisual == null)
282             {
283                 thumbVisual = new ColorVisual
284                 {
285                     SuppressUpdateVisual = true,
286                     MixColor = ThumbColor,
287                     SizePolicy = VisualTransformPolicyType.Absolute,
288                     Origin = calculator.CalculatorThumbAlign(),
289                     AnchorPoint = calculator.CalculatorThumbAlign(),
290                     Opacity = calculator.CalculateThumbVisibility() ? 1.0f : 0.0f,
291                     Size = thumbSize,
292                     Position = thumbPosition,
293                 };
294
295                 AddVisual("Thumb", thumbVisual);
296             }
297             else
298             {
299                 thumbVisual.Size = thumbSize;
300                 thumbVisual.Position = thumbPosition;
301                 thumbVisual.UpdateVisual(true);
302             }
303         }
304
305         /// <inheritdoc/>
306         /// <remarks>Please note that, for now, only alpha functions created with BuiltinFunctions are valid when animating. Otherwise, it will be treated as a linear alpha function. </remarks>
307         [EditorBrowsable(EditorBrowsableState.Never)]
308         public override void Update(float contentLength, float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
309         {
310             if (calculator == null)
311             {
312                 return;
313             }
314
315             calculator.contentLength = contentLength > 0.0f ? contentLength : 0.0f;
316             previousPosition = calculator.currentPosition;
317             calculator.currentPosition = position;
318
319             thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size);
320             thumbVisual.Position = calculator.CalculateThumbScrollPosition(trackVisual.Size, thumbVisual.Position, TrackPadding);
321             thumbVisual.Opacity = calculator.CalculateThumbVisibility() ? 1.0f : 0.0f;
322
323             if (durationMs == 0)
324             {
325                 thumbVisual.UpdateVisual(true);
326
327                 return;
328             }
329
330             // TODO Support non built-in alpha function for visual trainsition in DALi.
331             AlphaFunction.BuiltinFunctions builtinAlphaFunction = alphaFunction?.GetBuiltinFunction() ?? AlphaFunction.BuiltinFunctions.Default;
332
333             thumbPositionAnimation?.Stop();
334             thumbPositionAnimation = AnimateVisual(thumbVisual, "position", thumbVisual.Position, 0, (int)durationMs, builtinAlphaFunction);
335             thumbPositionAnimation.Play();
336
337             thumbSizeAnimation?.Stop();
338             thumbSizeAnimation = AnimateVisual(thumbVisual, "size", thumbVisual.Size, 0, (int)durationMs, builtinAlphaFunction);
339             thumbSizeAnimation.Play();
340         }
341
342         /// <inheritdoc/>
343         /// <remarks>Please note that, for now, only alpha functions created with BuiltinFunctions are valid when animating. Otherwise, it will be treated as a linear alpha function. </remarks>
344         [EditorBrowsable(EditorBrowsableState.Never)]
345         public override void ScrollTo(float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
346         {
347             if (mScrollEnabled == false)
348             {
349                 return;
350             }
351
352             if (calculator == null)
353             {
354                 return;
355             }
356
357             previousPosition = calculator.currentPosition;
358             calculator.currentPosition = position;
359             thumbVisual.Position = calculator.CalculateThumbScrollPosition(trackVisual.Size, thumbVisual.Position, TrackPadding);
360
361             if (durationMs == 0)
362             {
363                 thumbVisual.UpdateVisual(true);
364
365                 return;
366             }
367
368             // TODO Support non built-in alpha function for visual trainsition in DALi.
369             AlphaFunction.BuiltinFunctions builtinAlphaFunction = alphaFunction?.GetBuiltinFunction() ?? AlphaFunction.BuiltinFunctions.Default;
370
371             thumbPositionAnimation?.Stop();
372             thumbPositionAnimation = AnimateVisual(thumbVisual, "position", thumbVisual.Position, 0, (int)durationMs, builtinAlphaFunction);
373             thumbPositionAnimation.Play();
374         }
375
376         /// <inheritdoc/>
377         [EditorBrowsable(EditorBrowsableState.Never)]
378         public override void OnRelayout(Vector2 size, RelayoutContainer container)
379         {
380             base.OnRelayout(size, container);
381
382             if (size.Width == containerSize.Width && size.Height == containerSize.Height)
383             {
384                 return;
385             }
386
387             containerSize = new Size(size.Width, size.Height);
388
389             if (calculator == null)
390             {
391                 return;
392             }
393
394             trackVisual.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, TrackPadding);
395             trackVisual.Position = calculator.CalculateTrackPosition(TrackPadding);
396             thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size);
397             thumbVisual.Position = calculator.CalculateThumbPosition(trackVisual.Size, thumbVisual.Size, TrackPadding);
398
399             trackVisual.UpdateVisual(true);
400             thumbVisual.UpdateVisual(true);
401         }
402
403         /// <inheritdoc/>
404         [EditorBrowsable(EditorBrowsableState.Never)]
405         protected override ViewStyle CreateViewStyle()
406         {
407             return new ScrollbarStyle();
408         }
409
410         /// <summary>
411         /// Update TrackThickness property of the scrollbar.
412         /// </summary>
413         /// <param name="thickness">The width of the track.</param>
414         [EditorBrowsable(EditorBrowsableState.Never)]
415         protected virtual void UpdateTrackThickness(float thickness)
416         {
417             if (trackVisual == null)
418             {
419                 return;
420             }
421
422             trackVisual.Size = calculator.CalculateTrackSize(thickness, containerSize, TrackPadding);
423             trackVisual.UpdateVisual(true);
424         }
425
426         /// <summary>
427         /// Update ThumbThickness property of the scrollbar.
428         /// </summary>
429         /// <param name="thickness">The width of the track.</param>
430         [EditorBrowsable(EditorBrowsableState.Never)]
431         protected virtual void UpdateThumbThickness(float thickness)
432         {
433             if (thumbVisual == null)
434             {
435                 return;
436             }
437
438             thumbVisual.Size = calculator.CalculateThumbSize(thickness, trackVisual.Size);
439             thumbVisual.UpdateVisual(true);
440         }
441
442         /// <summary>
443         /// Update TrackColor property of the scrollbar.
444         /// </summary>
445         /// <param name="color">The color of the track.</param>
446         [EditorBrowsable(EditorBrowsableState.Never)]
447         protected virtual void UpdateTrackColor(Color color)
448         {
449             if (trackVisual == null)
450             {
451                 return;
452             }
453
454             trackVisual.MixColor = color;
455             trackVisual.UpdateVisual(true);
456         }
457
458         /// <summary>
459         /// Update ThumbColor property of the scrollbar.
460         /// </summary>
461         /// <param name="color">The color of the thumb.</param>
462         [EditorBrowsable(EditorBrowsableState.Never)]
463         protected virtual void UpdateThumbColor(Color color)
464         {
465             if (thumbVisual == null)
466             {
467                 return;
468             }
469
470             thumbVisual.MixColor = color;
471             thumbVisual.UpdateVisual(true);
472         }
473
474         /// <summary>
475         /// Update TrackPadding property of the scrollbar.
476         /// </summary>
477         /// <param name="trackPadding">The padding of the track.</param>
478         protected virtual void UpdateTrackPadding(Extents trackPadding)
479         {
480             if (calculator == null)
481             {
482                 return;
483             }
484
485             trackVisual.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding); 
486             trackVisual.Position = calculator.CalculateTrackPosition(trackPadding);
487             thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size);
488             thumbVisual.Position = calculator.CalculateThumbPaddingPosition(trackVisual.Size, thumbVisual.Size, thumbVisual.Position, trackPadding);
489
490             trackVisual.UpdateVisual(true);
491             thumbVisual.UpdateVisual(true);
492         }
493
494         /// <inheritdoc/>
495         [EditorBrowsable(EditorBrowsableState.Never)]
496         public override bool ScrollEnabled
497         {
498             get
499             {
500                 return mScrollEnabled;
501             }
502             set
503             {
504                 if (value != mScrollEnabled)
505                 {
506                     mScrollEnabled = value;
507                 }
508             }
509         }
510
511         /// <inheritdoc/>
512         [EditorBrowsable(EditorBrowsableState.Never)]
513         public override Position ScrollPosition
514         {
515             get
516             {
517                 if (calculator == null)
518                 {
519                     return new Position(0.0f, 0.0f);
520                 }
521
522                 float length = Math.Min(Math.Max(calculator.currentPosition, 0.0f), calculator.contentLength - calculator.visibleLength);
523
524                 if (calculator is HorizontalCalculator)
525                 {
526                     return new Position(length, 0.0f);
527                 }
528                 else
529                 {
530                     return new Position(0.0f, length);
531                 }
532             }
533         }
534
535         /// <inheritdoc/>
536         [EditorBrowsable(EditorBrowsableState.Never)]
537         public override Position ScrollCurrentPosition
538         {
539             get
540             {
541                 if (calculator == null)
542                 {
543                     return new Position(0.0f, 0.0f);
544                 }
545
546                 float length = Math.Min(Math.Max(calculator.currentPosition, 0.0f), calculator.contentLength - calculator.visibleLength);
547
548                 if (thumbPositionAnimation != null)
549                 {
550                     float progress = thumbPositionAnimation.CurrentProgress;
551                     float previousLength = Math.Min(Math.Max(previousPosition, 0.0f), calculator.contentLength - calculator.visibleLength);
552
553                     length = ((1.0f - progress) * previousLength) + (progress * length);
554                 }
555
556                 if (calculator is HorizontalCalculator)
557                 {
558                     return new Position(length, 0.0f);
559                 }
560                 else
561                 {
562                     return new Position(0.0f, length);
563                 }
564             }
565         }
566
567         #endregion Methods
568
569
570         #region Classes
571
572         private abstract class Calculator
573         {
574             public float contentLength;
575             public float visibleLength;
576             public float currentPosition;
577
578             public Calculator(float contentLength, float visibleLength, float currentPosition)
579             {
580                 this.contentLength = contentLength;
581                 this.visibleLength = visibleLength;
582                 this.currentPosition = currentPosition;
583             }
584
585             public bool CalculateThumbVisibility()
586             {
587                 return contentLength > visibleLength;
588             }
589
590             public abstract Visual.AlignType CalculatorTrackAlign();
591             public abstract Visual.AlignType CalculatorThumbAlign();
592             public abstract Size CalculateTrackSize(float thickness, Size containerSize, Extents trackPadding);
593             public abstract Vector2 CalculateTrackPosition(Extents trackPadding);
594             public abstract Size CalculateThumbSize(float thickness, Size trackSize);
595             public abstract Vector2 CalculateThumbPosition(Size trackSize, Size thumbSize, Extents trackPadding);
596             public abstract Vector2 CalculateThumbPaddingPosition(Size trackSize, Size thumbSize, Vector2 thumbCurrentPosition, Extents trackPadding);
597             public abstract Vector2 CalculateThumbScrollPosition(Size trackSize, Vector2 thumbCurrentPosition, Extents trackPadding);
598         }
599
600         private class HorizontalCalculator : Calculator
601         {
602             public HorizontalCalculator(float contentLength, float visibleLength, float currentPosition) : base(contentLength, visibleLength, currentPosition)
603             {
604             }
605
606             public override Visual.AlignType CalculatorTrackAlign()
607             {
608                 return Visual.AlignType.BottomCenter;
609             }
610
611             public override Visual.AlignType CalculatorThumbAlign()
612             {
613                 return Visual.AlignType.BottomBegin;
614             }
615
616             public override Size CalculateTrackSize(float thickness, Size containerSize, Extents trackPadding)
617             {
618                 return new Size(containerSize.Width - trackPadding.Start - trackPadding.End, thickness);
619             }
620
621             public override Vector2 CalculateTrackPosition(Extents trackPadding)
622             {
623                 return new Vector2(0, -trackPadding.Bottom);
624             }
625
626             public override Size CalculateThumbSize(float thickness, Size trackSize)
627             {
628                 return new Size(trackSize.Width * visibleLength / contentLength, thickness);
629             }
630
631             public override Vector2 CalculateThumbPosition(Size trackSize, Size thumbSize, Extents trackPadding)
632             {
633                 float padding = ((trackSize.Height - thumbSize.Height) / 2.0f) + trackPadding.Bottom;
634                 float pos = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
635                 return new Vector2(trackPadding.Start + trackSize.Width * pos / contentLength, -padding);
636             }
637
638             public override Vector2 CalculateThumbPaddingPosition(Size trackSize, Size thumbSize, Vector2 thumbCurrentPosition, Extents trackPadding)
639             {
640                 float padding = ((trackSize.Height - thumbSize.Height) / 2.0f) + trackPadding.Bottom;
641                 return new Vector2(thumbCurrentPosition.X, -padding);
642             }
643
644             public override Vector2 CalculateThumbScrollPosition(Size trackSize, Vector2 thumbCurrentPosition, Extents trackPadding)
645             {
646                 float pos = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
647                 return new Vector2(trackPadding.Start + trackSize.Width * pos / contentLength, thumbCurrentPosition.Y);
648             }
649         }
650
651         private class VerticalCalculator : Calculator
652         {
653             public VerticalCalculator(float contentLength, float visibleLength, float currentPosition) : base(contentLength, visibleLength, currentPosition)
654             {
655             }
656
657             public override Visual.AlignType CalculatorTrackAlign()
658             {
659                 return Visual.AlignType.CenterEnd;
660             }
661
662             public override Visual.AlignType CalculatorThumbAlign()
663             {
664                 return Visual.AlignType.TopEnd;
665             }
666
667             public override Size CalculateTrackSize(float thickness, Size containerSize, Extents trackPadding)
668             {
669                 return new Size(thickness, containerSize.Height - trackPadding.Top - trackPadding.Bottom);
670             }
671
672             public override Vector2 CalculateTrackPosition(Extents trackPadding)
673             {
674                 return new Vector2(-trackPadding.End, 0);
675             }
676
677             public override Size CalculateThumbSize(float thickness, Size trackSize)
678             {
679                 return new Size(thickness, trackSize.Height * visibleLength / contentLength);
680             }
681
682             public override Vector2 CalculateThumbPosition(Size trackSize, Size thumbSize, Extents trackPadding)
683             {
684                 float padding = ((trackSize.Width - thumbSize.Width) / 2.0f) + trackPadding.End;
685                 float pos = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
686                 return new Vector2(-padding, trackPadding.Top + trackSize.Height * pos / contentLength);
687             }
688
689             public override Vector2 CalculateThumbPaddingPosition(Size trackSize, Size thumbSize, Vector2 thumbCurrentPosition, Extents trackPadding)
690             {
691                 float padding = ((trackSize.Width - thumbSize.Width) / 2.0f) + trackPadding.End;
692                 return new Vector2(-padding, thumbCurrentPosition.Y);
693             }
694
695             public override Vector2 CalculateThumbScrollPosition(Size trackSize, Vector2 thumbPosition, Extents trackPadding)
696             {
697                 float pos = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
698                 return new Vector2(thumbPosition.X, trackPadding.Top + trackSize.Height * pos / contentLength);
699             }
700         }
701
702         #endregion Classes
703     }
704 }