[NUI] Add ScrollPosition and ScrollCurrentPosition to ScrollbarBase (#1872)
authorjaehyun0cho <jaehyun0cho@gmail.com>
Thu, 13 Aug 2020 02:42:47 +0000 (11:42 +0900)
committerGitHub <noreply@github.com>
Thu, 13 Aug 2020 02:42:47 +0000 (11:42 +0900)
To get the scroll position given to ScrollTo or Update, ScrollPosition
is added.

To get the current scroll position in the middle of ScrollTo or Update
animation, ScrollCurrentPosition is added.

Co-authored-by: Jaehyun Cho <jae_hyun.cho@samsung.com>
src/Tizen.NUI.Components/Controls/Scrollbar.cs
src/Tizen.NUI.Components/Controls/ScrollbarBase.cs
src/Tizen.NUI.Wearable/src/public/CircularScrollbar.cs

index 5da4255..6a01a63 100755 (executable)
@@ -112,6 +112,7 @@ namespace Tizen.NUI.Components
         private Size containerSize = new Size(0, 0);
         private ScrollbarStyle scrollbarStyle => ViewStyle as ScrollbarStyle;
         private bool mScrollEnabled = true;
+        private float previousPosition;
 
         #endregion Fields
 
@@ -312,6 +313,7 @@ namespace Tizen.NUI.Components
             }
 
             calculator.contentLength = contentLength > 0.0f ? contentLength : 0.0f;
+            previousPosition = calculator.currentPosition;
             calculator.currentPosition = position;
 
             thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size);
@@ -352,6 +354,7 @@ namespace Tizen.NUI.Components
                 return;
             }
 
+            previousPosition = calculator.currentPosition;
             calculator.currentPosition = position;
             thumbVisual.Position = calculator.CalculateThumbScrollPosition(trackVisual.Size, thumbVisual.Position, TrackPadding);
 
@@ -505,6 +508,62 @@ namespace Tizen.NUI.Components
             }
         }
 
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override Position ScrollPosition
+        {
+            get
+            {
+                if (calculator == null)
+                {
+                    return new Position(0.0f, 0.0f);
+                }
+
+                float length = Math.Min(Math.Max(calculator.currentPosition, 0.0f), calculator.contentLength - calculator.visibleLength);
+
+                if (calculator is HorizontalCalculator)
+                {
+                    return new Position(length, 0.0f);
+                }
+                else
+                {
+                    return new Position(0.0f, length);
+                }
+            }
+        }
+
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override Position ScrollCurrentPosition
+        {
+            get
+            {
+                if (calculator == null)
+                {
+                    return new Position(0.0f, 0.0f);
+                }
+
+                float length = Math.Min(Math.Max(calculator.currentPosition, 0.0f), calculator.contentLength - calculator.visibleLength);
+
+                if (thumbPositionAnimation != null)
+                {
+                    float progress = thumbPositionAnimation.CurrentProgress;
+                    float previousLength = Math.Min(Math.Max(previousPosition, 0.0f), calculator.contentLength - calculator.visibleLength);
+
+                    length = ((1.0f - progress) * previousLength) + (progress * length);
+                }
+
+                if (calculator is HorizontalCalculator)
+                {
+                    return new Position(length, 0.0f);
+                }
+                else
+                {
+                    return new Position(0.0f, length);
+                }
+            }
+        }
+
         #endregion Methods
 
 
index dc7003a..f7acb4d 100755 (executable)
@@ -93,6 +93,18 @@ namespace Tizen.NUI.Components
         [EditorBrowsable(EditorBrowsableState.Never)]
         public abstract bool ScrollEnabled { get; set; }
 
+        /// <summary>
+        /// Scroll position given to ScrollTo or Update.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public abstract Position ScrollPosition { get; }
+
+        /// <summary>
+        /// Current scroll position in the middle of ScrollTo or Update animation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public abstract Position ScrollCurrentPosition { get; }
+
         #endregion Methods
     }
 }
index 747f479..abb046f 100644 (file)
@@ -91,6 +91,7 @@ namespace Tizen.NUI.Wearable
         private ArcVisual thumbVisual;
         private float contentLength;
         private float visibleLength;
+        private float previousPosition;
         private float currentPosition;
         private float directionAlpha;
         private Size containerSize = new Size(0, 0);
@@ -285,6 +286,7 @@ namespace Tizen.NUI.Wearable
         [EditorBrowsable(EditorBrowsableState.Never)]
         public override void Update(float contentLength, float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
         {
+            this.previousPosition = this.currentPosition;
             this.currentPosition = position;
             this.contentLength = contentLength > 0.0f ? contentLength : 0.0f;
 
@@ -320,6 +322,7 @@ namespace Tizen.NUI.Wearable
         [EditorBrowsable(EditorBrowsableState.Never)]
         public override void ScrollTo(float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
         {
+            previousPosition = currentPosition;
             currentPosition = position;
 
             if (mScrollEnabled == false)
@@ -482,6 +485,40 @@ namespace Tizen.NUI.Wearable
             }
         }
 
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override Position ScrollPosition
+        {
+            get
+            {
+                bool isHorizontal = (directionAlpha == 270.0f) ? true : false;
+                float length = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
+
+                return (isHorizontal ? new Position(length, 0.0f) : new Position(0.0f, length));
+            }
+        }
+
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override Position ScrollCurrentPosition
+        {
+            get
+            {
+                bool isHorizontal = (directionAlpha == 270.0f) ? true : false;
+                float length = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
+
+                if (thumbStartAngleAnimation != null)
+                {
+                    float progress = thumbStartAngleAnimation.CurrentProgress;
+                    float previousLength = Math.Min(Math.Max(previousPosition, 0.0f), contentLength - visibleLength);
+
+                    length = ((1.0f - progress) * previousLength) + (progress * length);
+                }
+
+                return (isHorizontal ? new Position(length, 0.0f) : new Position(0.0f, length));
+            }
+        }
+
         #endregion Methods
     }
 }