From fc26452f64b7afc72c53d48f2ff5d46a6f64ab16 Mon Sep 17 00:00:00 2001 From: Sinai Date: Thu, 22 Apr 2021 03:57:34 +1000 Subject: [PATCH] Add elasticity to ScrollPool, stop movement on mouse scroll or slider change --- src/UI/UIFactory.cs | 3 ++- src/UI/Widgets/ScrollPool/ScrollPool.cs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/UI/UIFactory.cs b/src/UI/UIFactory.cs index 056e35f..86a2066 100644 --- a/src/UI/UIFactory.cs +++ b/src/UI/UIFactory.cs @@ -752,7 +752,8 @@ namespace UnityExplorer.UI var scrollRect = mainObj.AddComponent(); scrollRect.movementType = ScrollRect.MovementType.Clamped; - scrollRect.inertia = false; + scrollRect.inertia = true; + scrollRect.elasticity = 0.125f; scrollRect.scrollSensitivity = 15; scrollRect.horizontal = false; scrollRect.vertical = true; diff --git a/src/UI/Widgets/ScrollPool/ScrollPool.cs b/src/UI/Widgets/ScrollPool/ScrollPool.cs index 5ae50f5..249f46b 100644 --- a/src/UI/Widgets/ScrollPool/ScrollPool.cs +++ b/src/UI/Widgets/ScrollPool/ScrollPool.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using UnityEngine; using UnityEngine.UI; +using UnityExplorer.Core.Input; using UnityExplorer.UI.Models; namespace UnityExplorer.UI.Widgets @@ -350,6 +351,9 @@ namespace UnityExplorer.UI.Widgets if (WritingLocked) return; + if (InputManager.MouseScrollDelta != Vector2.zero) + ScrollRect.StopMovement(); + if (!SetRecycleViewBounds(true)) RefreshCells(); @@ -506,6 +510,8 @@ namespace UnityExplorer.UI.Widgets return; this.WritingLocked = true; + ScrollRect.StopMovement(); + // normalize the scroll position for the scroll bounds. // this translates the value into saying "point at the center of the height of the viewport" var scrollHeight = NormalizedScrollBounds.y - NormalizedScrollBounds.x;