[NUI] Scrollbar uses View instead Visual since blinking issue (#2745)
authorJiyun Yang <ji.yang@samsung.com>
Fri, 19 Mar 2021 02:12:59 +0000 (11:12 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Fri, 19 Mar 2021 08:05:58 +0000 (17:05 +0900)
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI.Components/Controls/ScrollableBase.cs
src/Tizen.NUI.Components/Controls/Scrollbar.cs
src/Tizen.NUI.Components/Controls/ScrollbarBase.cs
src/Tizen.NUI.Wearable/src/public/CircularScrollbar.cs

index 28eea61fe3b82682bc7408cf68b8efe1f0490323..99c0200d3fd0a2e595eb8e871281c0f260ba39e9 100755 (executable)
@@ -268,6 +268,7 @@ namespace Tizen.NUI.Components
 
                     ContentContainer.WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent;
                     ContentContainer.HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent;
+                    SetScrollbar();
                 }
             }
         }
@@ -753,13 +754,33 @@ namespace Tizen.NUI.Components
             if (isSizeChanged)
             {
                 maxScrollDistance = CalculateMaximumScrollDistance();
-                SetScrollbar();
+                if (!ReviseContainerPositionIfNeed())
+                {
+                    UpdateScrollbar();
+                }
             }
 
             previousContainerSize = ContentContainer.Size;
             previousSize = Size;
         }
 
+        private bool ReviseContainerPositionIfNeed()
+        {
+            bool isHorizontal = ScrollingDirection == Direction.Horizontal;
+            float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
+
+            if (Math.Abs(currentPosition) > maxScrollDistance)
+            {
+                StopScroll();
+                var targetPosition = BoundScrollPosition(-maxScrollDistance);
+                if (isHorizontal) ContentContainer.PositionX = targetPosition;
+                else ContentContainer.PositionY = targetPosition;
+                return true;
+            }
+
+            return false;
+        }
+
         /// <summary>
         /// The composition of a Scrollbar can vary depending on how you use ScrollableBase.
         /// Set the composition that will go into the ScrollableBase according to your ScrollableBase.
@@ -774,7 +795,21 @@ namespace Tizen.NUI.Components
                 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
                 float viewportLength = isHorizontal ? Size.Width : Size.Height;
                 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
-                Scrollbar.Initialize(contentLength, viewportLength, currentPosition, isHorizontal);
+                Scrollbar.Initialize(contentLength, viewportLength, -currentPosition, isHorizontal);
+            }
+        }
+
+        /// Update scrollbar position and size.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void UpdateScrollbar()
+        {
+            if (Scrollbar)
+            {
+                bool isHorizontal = ScrollingDirection == Direction.Horizontal;
+                float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
+                float viewportLength = isHorizontal ? Size.Width : Size.Height;
+                float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
+                Scrollbar.Update(contentLength, viewportLength, -currentPosition);
             }
         }
 
index c6f1605da23512204f2d671941bbda78dae637ef..799f7c3f2138d00158533351c4c4bb5c989185cf 100755 (executable)
@@ -50,15 +50,15 @@ namespace Tizen.NUI.Components
         /// <summary>Bindable property of TrackColor</summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static readonly BindableProperty TrackColorProperty = BindableProperty.Create(nameof(TrackColor), typeof(Color), typeof(Scrollbar), null,
-            propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateTrackColor((Color)newValue),
-            defaultValueCreator: (bindable) => ((Scrollbar)bindable).trackVisual.MixColor
+            propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).trackView.BackgroundColor = (Color)newValue,
+            defaultValueCreator: (bindable) => ((Scrollbar)bindable).trackView.BackgroundColor
         );
 
         /// <summary>Bindable property of ThumbColor</summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(Scrollbar), null,
-            propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateThumbColor((Color)newValue),
-            defaultValueCreator: (bindable) => ((Scrollbar)bindable).thumbVisual.MixColor
+            propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).thumbView.BackgroundColor = (Color)newValue,
+            defaultValueCreator: (bindable) => ((Scrollbar)bindable).thumbView.BackgroundColor
         );
 
         /// <summary>Bindable property of TrackPadding</summary>
@@ -68,17 +68,17 @@ namespace Tizen.NUI.Components
             defaultValueCreator: (bindable) => ((Scrollbar)bindable).trackPadding
         );
 
-        private ColorVisual trackVisual;
-        private ColorVisual thumbVisual;
+        private View trackView;
+        private View thumbView;
         private Animation thumbPositionAnimation;
         private Animation thumbSizeAnimation;
+        private Animation opacityAnimation;
         private Calculator calculator;
         private Size containerSize = new Size(0, 0);
-        private bool mScrollEnabled = true;
         private float previousPosition;
-        private float trackThickness;
-        private float thumbThickness;
-        private PaddingType trackPadding;
+        private float trackThickness = 6.0f;
+        private float thumbThickness = 6.0f;
+        private PaddingType trackPadding = new PaddingType(4, 4, 4, 4);
 
         #endregion Fields
 
@@ -177,6 +177,46 @@ namespace Tizen.NUI.Components
             set => SetValue(TrackPaddingProperty, value);
         }
 
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override float ScrollPosition
+        {
+            get
+            {
+                if (calculator == null)
+                {
+                    return 0.0f;
+                }
+
+                return Math.Min(Math.Max(calculator.currentPosition, 0.0f), calculator.contentLength - calculator.visibleLength);
+            }
+        }
+
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override float ScrollCurrentPosition
+        {
+            get
+            {
+                if (calculator == null)
+                {
+                    return 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);
+                }
+
+                return length;
+            }
+        }
+
         #endregion Properties
 
 
@@ -188,21 +228,22 @@ namespace Tizen.NUI.Components
         {
             base.OnInitialize();
 
-            trackVisual = new ColorVisual
+            trackView = new View()
             {
-                SuppressUpdateVisual = true,
-                SizePolicy = VisualTransformPolicyType.Absolute,
-                MixColor = Color.Transparent,
+                PositionUsesPivotPoint = true,
+                BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.15f)
             };
-            AddVisual("Track", trackVisual);
+            Add(trackView);
 
-            thumbVisual = new ColorVisual
+            thumbView = new View()
             {
-                SuppressUpdateVisual = true,
-                SizePolicy = VisualTransformPolicyType.Absolute,
-                MixColor = Color.Transparent,
+                PositionUsesPivotPoint = true,
+                BackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f)
             };
-            AddVisual("Thumb", thumbVisual);
+            Add(thumbView);
+
+            WidthResizePolicy = ResizePolicyType.FillToParent;
+            HeightResizePolicy = ResizePolicyType.FillToParent;
         }
 
         /// <inheritdoc/>
@@ -218,70 +259,91 @@ namespace Tizen.NUI.Components
                 calculator = new VerticalCalculator(contentLength > 0.0f ? contentLength : 0.0f, viewportLength, currentPosition);
             }
 
-            thumbPositionAnimation?.Stop();
+            thumbPositionAnimation?.Clear();
             thumbPositionAnimation = null;
 
-            thumbSizeAnimation?.Stop();
+            thumbSizeAnimation?.Clear();
             thumbSizeAnimation = null;
 
-            Size trackSize = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding);
-            Vector2 trackPosition = calculator.CalculateTrackPosition(trackPadding);
-            Size thumbSize = calculator.CalculateThumbSize(ThumbThickness, trackSize);
-            Vector2 thumbPosition = calculator.CalculateThumbPosition(trackSize, thumbSize, trackPadding);
-
-            Debug.Assert(trackVisual != null && thumbVisual != null);
-
-            trackVisual.MixColor = TrackColor;
-            trackVisual.Origin = calculator.CalculatorTrackAlign();
-            trackVisual.AnchorPoint = calculator.CalculatorTrackAlign();
-            trackVisual.Size = trackSize;
-            trackVisual.Position = trackPosition;
-            trackVisual.UpdateVisual(true);
-
-            thumbVisual.MixColor = ThumbColor;
-            thumbVisual.Origin = calculator.CalculatorThumbAlign();
-            thumbVisual.AnchorPoint = calculator.CalculatorThumbAlign();
-            thumbVisual.Opacity = calculator.CalculateThumbVisibility() ? 1.0f : 0.0f;
-            thumbVisual.Size = thumbSize;
-            thumbVisual.Position = thumbPosition;
-            thumbVisual.UpdateVisual(true);
+            opacityAnimation?.Clear();
+            opacityAnimation = null;
+
+            var trackSize = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding);
+            var trackPosition = calculator.CalculateTrackPosition(trackPadding);
+            var thumbSize = calculator.CalculateThumbSize(ThumbThickness, trackSize);
+            var thumbPosition = calculator.CalculateThumbPosition(trackSize, thumbSize, trackPadding);
+
+            Debug.Assert(trackView != null);
+            trackView.ParentOrigin = calculator.CalculatorTrackAlign();
+            trackView.PivotPoint = calculator.CalculatorTrackAlign();
+            trackView.Size = trackSize;
+            trackView.Position = trackPosition;
+
+            Debug.Assert(thumbView != null);
+            thumbView.ParentOrigin = calculator.CalculatorThumbAlign();
+            thumbView.PivotPoint = calculator.CalculatorThumbAlign();
+            thumbView.Size = thumbSize;
+            thumbView.Position = thumbPosition;;
+
+            Opacity = calculator.IsScrollable() ? 1.0f : 0.0f;
         }
 
         /// <inheritdoc/>
-        /// <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>
+        /// <exception cref="InvalidOperationException">Thrown when the scrollabr not yet initialized.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override void Update(float contentLength, float viewportLength, float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
+        {
+            if (calculator == null)
+            {
+                throw new InvalidOperationException("Scrollbar is not initialized. Please call Initialize() first.");
+            }
+
+            calculator.visibleLength = viewportLength;
+            Update(contentLength, position, durationMs, alphaFunction);
+        }
+
+        /// <inheritdoc/>
+        /// <exception cref="InvalidOperationException">Thrown when the scrollabr not yet initialized.</exception>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public override void Update(float contentLength, float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
         {
             if (calculator == null)
             {
-                return;
+                throw new InvalidOperationException("Scrollbar is not initialized. Please call Initialize() first.");
             }
 
             calculator.contentLength = contentLength > 0.0f ? contentLength : 0.0f;
-            previousPosition = calculator.currentPosition;
             calculator.currentPosition = position;
 
-            thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size);
-            thumbVisual.Position = calculator.CalculateThumbScrollPosition(trackVisual.Size, thumbVisual.Position, trackPadding);
-            thumbVisual.Opacity = calculator.CalculateThumbVisibility() ? 1.0f : 0.0f;
+            float newOpacity = calculator.IsScrollable() ? 1.0f : 0.0f;
+            bool opacityChanged = (int)Opacity != (int)newOpacity;
+
+            var thumbSize = calculator.CalculateThumbSize(ThumbThickness, trackView.Size);
+            var thumbPosition = calculator.CalculateThumbScrollPosition(trackView.Size, thumbView.Position, trackPadding);
 
             if (durationMs == 0)
             {
-                thumbVisual.UpdateVisual(true);
+                thumbView.Position = thumbPosition;
+                thumbView.Size = thumbSize;
 
+                if (opacityChanged)
+                {
+                    Opacity = newOpacity;
+                }
                 return;
             }
 
-            // TODO Support non built-in alpha function for visual transition in DALi.
-            AlphaFunction.BuiltinFunctions builtinAlphaFunction = alphaFunction?.GetBuiltinFunction() ?? AlphaFunction.BuiltinFunctions.Default;
-
-            thumbPositionAnimation?.Stop();
-            thumbPositionAnimation = AnimateVisual(thumbVisual, "position", thumbVisual.Position, 0, (int)durationMs, builtinAlphaFunction);
+            EnsureThumbPositionAnimation().AnimateTo(thumbView, "Position", thumbPosition, 0, (int)durationMs, alphaFunction);
             thumbPositionAnimation.Play();
 
-            thumbSizeAnimation?.Stop();
-            thumbSizeAnimation = AnimateVisual(thumbVisual, "size", thumbVisual.Size, 0, (int)durationMs, builtinAlphaFunction);
+            EnsureThumbSizeAnimation().AnimateTo(thumbView, "Size", thumbSize, 0, (int)durationMs, alphaFunction);
             thumbSizeAnimation.Play();
+
+            if (opacityChanged)
+            {
+                EnsureOpacityAnimation().AnimateTo(this, "Opacity", newOpacity, 0, (int)durationMs, alphaFunction);
+                opacityAnimation.Play();
+            }
         }
 
         /// <inheritdoc/>
@@ -289,7 +351,7 @@ namespace Tizen.NUI.Components
         [EditorBrowsable(EditorBrowsableState.Never)]
         public override void ScrollTo(float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
         {
-            if (mScrollEnabled == false)
+            if (ControlState == ControlState.Disabled)
             {
                 return;
             }
@@ -301,20 +363,15 @@ namespace Tizen.NUI.Components
 
             previousPosition = calculator.currentPosition;
             calculator.currentPosition = position;
-            thumbVisual.Position = calculator.CalculateThumbScrollPosition(trackVisual.Size, thumbVisual.Position, trackPadding);
+            var thumbPosition = calculator.CalculateThumbScrollPosition(trackView.Size, thumbView.Position, trackPadding);
 
             if (durationMs == 0)
             {
-                thumbVisual.UpdateVisual(true);
-
+                thumbView.Position = thumbPosition;
                 return;
             }
 
-            // TODO Support non built-in alpha function for visual transition in DALi.
-            AlphaFunction.BuiltinFunctions builtinAlphaFunction = alphaFunction?.GetBuiltinFunction() ?? AlphaFunction.BuiltinFunctions.Default;
-
-            thumbPositionAnimation?.Stop();
-            thumbPositionAnimation = AnimateVisual(thumbVisual, "position", thumbVisual.Position, 0, (int)durationMs, builtinAlphaFunction);
+            EnsureThumbPositionAnimation().AnimateTo(thumbView, "position", thumbPosition, 0, (int)durationMs, alphaFunction);
             thumbPositionAnimation.Play();
         }
 
@@ -336,13 +393,10 @@ namespace Tizen.NUI.Components
                 return;
             }
 
-            trackVisual.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding);
-            trackVisual.Position = calculator.CalculateTrackPosition(trackPadding);
-            thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size);
-            thumbVisual.Position = calculator.CalculateThumbPosition(trackVisual.Size, thumbVisual.Size, trackPadding);
-
-            trackVisual.UpdateVisual(true);
-            thumbVisual.UpdateVisual(true);
+            trackView.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding);
+            trackView.Position = calculator.CalculateTrackPosition(trackPadding);
+            thumbView.Size = calculator.CalculateThumbSize(ThumbThickness, trackView.Size);
+            thumbView.Position = calculator.CalculateThumbPosition(trackView.Size, thumbView.Size, trackPadding);
         }
 
         /// <inheritdoc/>
@@ -375,8 +429,7 @@ namespace Tizen.NUI.Components
         /// Update TrackThickness property of the scrollbar.
         /// </summary>
         /// <param name="thickness">The width of the track.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected virtual void UpdateTrackThickness(float thickness)
+        private void UpdateTrackThickness(float thickness)
         {
             trackThickness = thickness;
 
@@ -385,16 +438,14 @@ namespace Tizen.NUI.Components
                 return;
             }
 
-            trackVisual.Size = calculator.CalculateTrackSize(thickness, containerSize, trackPadding);
-            trackVisual.UpdateVisual(true);
+            trackView.Size = calculator.CalculateTrackSize(thickness, containerSize, trackPadding);
         }
 
         /// <summary>
         /// Update ThumbThickness property of the scrollbar.
         /// </summary>
         /// <param name="thickness">The width of the track.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected virtual void UpdateThumbThickness(float thickness)
+        private void UpdateThumbThickness(float thickness)
         {
             thumbThickness = thickness;
 
@@ -403,47 +454,14 @@ namespace Tizen.NUI.Components
                 return;
             }
 
-            thumbVisual.Size = calculator.CalculateThumbSize(thickness, trackVisual.Size);
-            thumbVisual.UpdateVisual(true);
-        }
-
-        /// <summary>
-        /// Update TrackColor property of the scrollbar.
-        /// </summary>
-        /// <param name="color">The color of the track.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected virtual void UpdateTrackColor(Color color)
-        {
-            if (trackVisual == null)
-            {
-                return;
-            }
-
-            trackVisual.MixColor = color;
-            trackVisual.UpdateVisual(true);
-        }
-
-        /// <summary>
-        /// Update ThumbColor property of the scrollbar.
-        /// </summary>
-        /// <param name="color">The color of the thumb.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected virtual void UpdateThumbColor(Color color)
-        {
-            if (thumbVisual == null)
-            {
-                return;
-            }
-
-            thumbVisual.MixColor = color;
-            thumbVisual.UpdateVisual(true);
+            thumbView.Size = calculator.CalculateThumbSize(thickness, trackView.Size);
         }
 
         /// <summary>
         /// Update TrackPadding property of the scrollbar.
         /// </summary>
         /// <param name="padding">The padding of the track.</param>
-        protected virtual void UpdateTrackPadding(Extents padding)
+        private void UpdateTrackPadding(Extents padding)
         {
             trackPadding = padding == null ? new PaddingType(0, 0, 0, 0) : new PaddingType(padding.Start, padding.End, padding.Top, padding.Bottom);
 
@@ -452,90 +470,54 @@ namespace Tizen.NUI.Components
                 return;
             }
 
-            trackVisual.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding);
-            trackVisual.Position = calculator.CalculateTrackPosition(trackPadding);
-            thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size);
-            thumbVisual.Position = calculator.CalculateThumbPaddingPosition(trackVisual.Size, thumbVisual.Size, thumbVisual.Position, trackPadding);
-
-            trackVisual.UpdateVisual(true);
-            thumbVisual.UpdateVisual(true);
+            trackView.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding);
+            trackView.Position = calculator.CalculateTrackPosition(trackPadding);
+            thumbView.Size = calculator.CalculateThumbSize(ThumbThickness, trackView.Size);
+            thumbView.Position = calculator.CalculateThumbPaddingPosition(trackView.Size, thumbView.Size, thumbView.Position, trackPadding);
         }
 
-        /// <inheritdoc/>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public override bool ScrollEnabled
+        private Animation EnsureThumbPositionAnimation()
         {
-            get
+            if (thumbPositionAnimation == null)
             {
-                return mScrollEnabled;
+                thumbPositionAnimation = new Animation();
             }
-            set
+            else
             {
-                if (value != mScrollEnabled)
-                {
-                    mScrollEnabled = value;
-                }
+                thumbPositionAnimation.Stop();
+                thumbPositionAnimation.Clear();
             }
+            return thumbPositionAnimation;
         }
 
-        /// <inheritdoc/>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public override Position ScrollPosition
+        private Animation EnsureThumbSizeAnimation()
         {
-            get
+            if (thumbSizeAnimation == null)
             {
-                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);
-                }
+                thumbSizeAnimation = new Animation();
             }
+            else
+            {
+                thumbSizeAnimation.Stop();
+                thumbSizeAnimation.Clear();
+            }
+            return thumbSizeAnimation;
         }
 
-        /// <inheritdoc/>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public override Position ScrollCurrentPosition
+        private Animation EnsureOpacityAnimation()
         {
-            get
+            if (opacityAnimation == null)
             {
-                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);
-                }
+                opacityAnimation = new Animation();
+            }
+            else
+            {
+                opacityAnimation.Stop();
+                opacityAnimation.Clear();
             }
+            return opacityAnimation;
         }
 
-        // private PaddingType EnsurePadding(Extents padding) => padding == null ? new PaddingType(0, 0, 0, 0) : new PaddingType(padding.Start, padding.End, padding.Top, padding.Bottom);
-
         #endregion Methods
 
 
@@ -554,19 +536,19 @@ namespace Tizen.NUI.Components
                 this.currentPosition = currentPosition;
             }
 
-            public bool CalculateThumbVisibility()
+            public bool IsScrollable()
             {
                 return contentLength > visibleLength;
             }
 
-            public abstract Visual.AlignType CalculatorTrackAlign();
-            public abstract Visual.AlignType CalculatorThumbAlign();
+            public abstract Position CalculatorTrackAlign();
+            public abstract Position CalculatorThumbAlign();
             public abstract Size CalculateTrackSize(float thickness, Size containerSize, PaddingType trackPadding);
-            public abstract Vector2 CalculateTrackPosition(PaddingType trackPadding);
+            public abstract Position CalculateTrackPosition(PaddingType trackPadding);
             public abstract Size CalculateThumbSize(float thickness, Size trackSize);
-            public abstract Vector2 CalculateThumbPosition(Size trackSize, Size thumbSize, PaddingType trackPadding);
-            public abstract Vector2 CalculateThumbPaddingPosition(Size trackSize, Size thumbSize, Vector2 thumbCurrentPosition, PaddingType trackPadding);
-            public abstract Vector2 CalculateThumbScrollPosition(Size trackSize, Vector2 thumbCurrentPosition, PaddingType trackPadding);
+            public abstract Position CalculateThumbPosition(Size trackSize, Size thumbSize, PaddingType trackPadding);
+            public abstract Position CalculateThumbPaddingPosition(Size trackSize, Size thumbSize, Position thumbCurrentPosition, PaddingType trackPadding);
+            public abstract Position CalculateThumbScrollPosition(Size trackSize, Position thumbCurrentPosition, PaddingType trackPadding);
         }
 
         private class HorizontalCalculator : Calculator
@@ -575,14 +557,14 @@ namespace Tizen.NUI.Components
             {
             }
 
-            public override Visual.AlignType CalculatorTrackAlign()
+            public override Position CalculatorTrackAlign()
             {
-                return Visual.AlignType.BottomBegin;
+                return Tizen.NUI.ParentOrigin.BottomLeft;
             }
 
-            public override Visual.AlignType CalculatorThumbAlign()
+            public override Position CalculatorThumbAlign()
             {
-                return Visual.AlignType.BottomBegin;
+                return Tizen.NUI.ParentOrigin.BottomLeft;
             }
 
             public override Size CalculateTrackSize(float thickness, Size containerSize, PaddingType trackPadding)
@@ -590,33 +572,31 @@ namespace Tizen.NUI.Components
                 return new Size(containerSize.Width - trackPadding.Item1 - trackPadding.Item2, thickness);
             }
 
-            public override Vector2 CalculateTrackPosition(PaddingType trackPadding)
+            public override Position CalculateTrackPosition(PaddingType trackPadding)
             {
-                return new Vector2(trackPadding.Item1, -trackPadding.Item4);
+                return new Position(trackPadding.Item1, -trackPadding.Item4);
             }
 
             public override Size CalculateThumbSize(float thickness, Size trackSize)
             {
-                return new Size(trackSize.Width * visibleLength / contentLength, thickness);
+                return new Size(trackSize.Width * (IsScrollable() ? (visibleLength / contentLength) : 0.0f), thickness);
             }
 
-            public override Vector2 CalculateThumbPosition(Size trackSize, Size thumbSize, PaddingType trackPadding)
+            public override Position CalculateThumbPosition(Size trackSize, Size thumbSize, PaddingType trackPadding)
             {
                 float padding = ((trackSize.Height - thumbSize.Height) / 2.0f) + trackPadding.Item4;
-                float pos = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
-                return new Vector2(trackPadding.Item1 + trackSize.Width * pos / contentLength, -padding);
+                return new Position(trackPadding.Item1 + (IsScrollable() ? (trackSize.Width * (Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength)) / contentLength) : 0.0f), -padding);
             }
 
-            public override Vector2 CalculateThumbPaddingPosition(Size trackSize, Size thumbSize, Vector2 thumbCurrentPosition, PaddingType trackPadding)
+            public override Position CalculateThumbPaddingPosition(Size trackSize, Size thumbSize, Position thumbCurrentPosition, PaddingType trackPadding)
             {
                 float padding = ((trackSize.Height - thumbSize.Height) / 2.0f) + trackPadding.Item4;
-                return new Vector2(thumbCurrentPosition.X, -padding);
+                return new Position(thumbCurrentPosition.X, -padding);
             }
 
-            public override Vector2 CalculateThumbScrollPosition(Size trackSize, Vector2 thumbCurrentPosition, PaddingType trackPadding)
-            {
-                float pos = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
-                return new Vector2(trackPadding.Item1 + trackSize.Width * pos / contentLength, thumbCurrentPosition.Y);
+            public override Position CalculateThumbScrollPosition(Size trackSize, Position thumbCurrentPosition, PaddingType trackPadding)
+            { 
+                return new Position(trackPadding.Item1 + (IsScrollable() ? (trackSize.Width * (Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength)) / contentLength) : 0.0f), thumbCurrentPosition.Y);
             }
         }
 
@@ -626,14 +606,14 @@ namespace Tizen.NUI.Components
             {
             }
 
-            public override Visual.AlignType CalculatorTrackAlign()
+            public override Position CalculatorTrackAlign()
             {
-                return Visual.AlignType.TopEnd;
+                return Tizen.NUI.ParentOrigin.TopRight;
             }
 
-            public override Visual.AlignType CalculatorThumbAlign()
+            public override Position CalculatorThumbAlign()
             {
-                return Visual.AlignType.TopEnd;
+                return Tizen.NUI.ParentOrigin.TopRight;
             }
 
             public override Size CalculateTrackSize(float thickness, Size containerSize, PaddingType trackPadding)
@@ -641,33 +621,31 @@ namespace Tizen.NUI.Components
                 return new Size(thickness, containerSize.Height - trackPadding.Item3 - trackPadding.Item4);
             }
 
-            public override Vector2 CalculateTrackPosition(PaddingType trackPadding)
+            public override Position CalculateTrackPosition(PaddingType trackPadding)
             {
-                return new Vector2(-trackPadding.Item2, trackPadding.Item3);
+                return new Position(-trackPadding.Item2, trackPadding.Item3);
             }
 
             public override Size CalculateThumbSize(float thickness, Size trackSize)
             {
-                return new Size(thickness, trackSize.Height * visibleLength / contentLength);
+                return new Size(thickness, trackSize.Height * (IsScrollable() ? (visibleLength / contentLength) : 0.0f));
             }
 
-            public override Vector2 CalculateThumbPosition(Size trackSize, Size thumbSize, PaddingType trackPadding)
+            public override Position CalculateThumbPosition(Size trackSize, Size thumbSize, PaddingType trackPadding)
             {
                 float padding = ((trackSize.Width - thumbSize.Width) / 2.0f) + trackPadding.Item2;
-                float pos = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
-                return new Vector2(-padding, trackPadding.Item3 + trackSize.Height * pos / contentLength);
+                return new Position(-padding, trackPadding.Item3 + (IsScrollable() ? (trackSize.Height * Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength) / contentLength) : 0.0f));
             }
 
-            public override Vector2 CalculateThumbPaddingPosition(Size trackSize, Size thumbSize, Vector2 thumbCurrentPosition, PaddingType trackPadding)
+            public override Position CalculateThumbPaddingPosition(Size trackSize, Size thumbSize, Position thumbCurrentPosition, PaddingType trackPadding)
             {
                 float padding = ((trackSize.Width - thumbSize.Width) / 2.0f) + trackPadding.Item2;
-                return new Vector2(-padding, thumbCurrentPosition.Y);
+                return new Position(-padding, thumbCurrentPosition.Y);
             }
 
-            public override Vector2 CalculateThumbScrollPosition(Size trackSize, Vector2 thumbPosition, PaddingType trackPadding)
+            public override Position CalculateThumbScrollPosition(Size trackSize, Position thumbPosition, PaddingType trackPadding)
             {
-                float pos = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
-                return new Vector2(thumbPosition.X, trackPadding.Item3 + trackSize.Height * pos / contentLength);
+                return new Position(thumbPosition.X, trackPadding.Item3 + (IsScrollable() ? (trackSize.Height * Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength) / contentLength) : 0.0f));
             }
         }
 
index 7b862e01ceb47c8df182bcfd6bb43c2fbe2e144e..3a2ebeb7bf6ad410404646ee7a2c49910d4d8af7 100755 (executable)
@@ -64,6 +64,17 @@ namespace Tizen.NUI.Components
             (GetParent() as ScrollableBase)?.BaseRemove(this);
         }
 
+        /// <summary>
+        /// Update content length and position at once.
+        /// </summary>
+        /// <param name="contentLength">The total length of the content.</param>
+        /// <param name="viewportLength">The length of the viewport representing the amount of visible content.</param>
+        /// <param name="position">The destination position of the View in content length. This is the View's top position if the scroller is vertical, otherwise, View's left position.</param>
+        /// <param name="durationMs">The time it takes to scroll in milliseconds.</param>
+        /// <param name="alphaFunction">The timing function used in animation. It describes the rate of change of the animation parameter over time. (e.g. EaseOut)</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public abstract void Update(float contentLength, float viewportLength, float position, uint durationMs = 0, AlphaFunction alphaFunction = null);
+
         /// <summary>
         /// Update content length and position at once.
         /// </summary>
@@ -93,23 +104,17 @@ namespace Tizen.NUI.Components
         [EditorBrowsable(EditorBrowsableState.Never)]
         public abstract void Initialize(float contentLength, float viewportLength, float currentPosition, bool isHorizontal = false);
 
-        /// <summary>
-        /// Enable or disable scrolling.
-        /// </summary>
-        [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; }
+        public abstract float ScrollPosition { get; }
 
         /// <summary>
         /// Current scroll position in the middle of ScrollTo or Update animation.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public abstract Position ScrollCurrentPosition { get; }
+        public abstract float ScrollCurrentPosition { get; }
 
         #endregion Methods
     }
index 368e9c8a9da946708da356f6772b973329566a09..7beb5bc204b5500747b3b27aa9726c0652f8bbb3 100755 (executable)
@@ -97,7 +97,6 @@ namespace Tizen.NUI.Wearable
         private Size containerSize = new Size(0, 0);
         private Animation thumbStartAngleAnimation;
         private Animation thumbSweepAngleAnimation;
-        private bool mScrollEnabled = true;
 
         #endregion Fields
 
@@ -265,6 +264,14 @@ namespace Tizen.NUI.Wearable
             }
         }
 
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override void Update(float contentLength, float viewportLength, float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
+        {
+            this.visibleLength = viewportLength;
+            Update(contentLength, position, durationMs, alphaFunction);
+        }
+
         /// <inheritdoc/>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public override void Update(float contentLength, float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
@@ -308,7 +315,7 @@ namespace Tizen.NUI.Wearable
             previousPosition = currentPosition;
             currentPosition = position;
 
-            if (mScrollEnabled == false)
+            if (ControlState == ControlState.Disabled)
             {
                 return;
             }
@@ -464,41 +471,17 @@ namespace Tizen.NUI.Wearable
 
         /// <inheritdoc/>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public override bool ScrollEnabled
-        {
-            get
-            {
-                return mScrollEnabled;
-            }
-            set
-            {
-                if (value != mScrollEnabled)
-                {
-                    mScrollEnabled = value;
-                }
-            }
-        }
-
-        /// <inheritdoc/>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public override Position ScrollPosition
+        public override float 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));
-            }
+            get => Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
         }
 
         /// <inheritdoc/>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public override Position ScrollCurrentPosition
+        public override float ScrollCurrentPosition
         {
             get
             {
-                bool isHorizontal = (directionAlpha == 270.0f) ? true : false;
                 float length = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
 
                 if (thumbStartAngleAnimation != null)
@@ -509,7 +492,7 @@ namespace Tizen.NUI.Wearable
                     length = ((1.0f - progress) * previousLength) + (progress * length);
                 }
 
-                return (isHorizontal ? new Position(length, 0.0f) : new Position(0.0f, length));
+                return length;
             }
         }