コード例 #1
0
        private void Rec_PanUpdated(object sender, PanUpdatedEventArgs e)
        {
            if (DisableTouchScroll)
            {
                return;
            }

            if (Config == null)
            {
                return;
            }

            var currentId = e.GestureId;

            if (!(m_lastId == SlideProperties.HoldId || !SlideProperties.IsHeld || currentId == m_lastId))
            {
                return;
            }

            if (e.StatusType == GestureStatus.Started)
            {
                // Start tracking time
                m_startSlideLocation = CalculateDist(SlideProperties.Position);
            }

            var currentPos = m_startSlideLocation - e.TotalX;

            m_lastId = currentId;
            var index = Math.Max(Config.MinValue - 0.45, Math.Min(Config.MaxValue + 0.45, CalculateIndex(currentPos)));

            if (e.StatusType == GestureStatus.Completed || e.StatusType == GestureStatus.Canceled)
            {
                index = SlideProperties.Position;
                m_accelerator.OnDrag(index);
                SlideProperties = new SlidableProperties(index, m_lastId, e.StatusType != GestureStatus.Completed && e.StatusType != GestureStatus.Canceled);
            }
            else
            {
                SlideProperties = new SlidableProperties(index, m_lastId, e.StatusType != GestureStatus.Completed && e.StatusType != GestureStatus.Canceled);
                OnScrolledInternal();
            }

            if (e.StatusType == GestureStatus.Completed || e.StatusType == GestureStatus.Canceled)
            {
                m_accelerator.EndDrag();
                Device.StartTimer(TimeSpan.FromMilliseconds(20), () => // ~40 fps
                {
                    if (currentId != SlideProperties.HoldId)
                    {
                        return(false);
                    }
                    m_accelerator.Min = Config.MinValue - 0.45;
                    m_accelerator.Max = Config.MaxValue + 0.45;
                    var next          = m_accelerator.GetValue(out bool isDone);
                    index             = next;
                    if (SlideProperties.IsHeld)
                    {
                        return(false);
                    }
                    SlideProperties = new SlidableProperties(index, m_lastId, false);
                    OnScrolledInternal();
                    return(!isDone);
                });
            }
            else if (e.StatusType == GestureStatus.Started)
            {
                m_accelerator.StartDrag(index);
            }
            else
            {
                m_accelerator.OnDrag(index);
            }
        }
コード例 #2
0
 /// <summary>
 /// Scrolls to the index
 /// </summary>
 /// <param name="index">Index to scroll to</param>
 /// <param name="length">Time used on the scrolling</param>
 public void ScrollTo(int index, int length = 250)
 {
     SlidableProperties.ScrollTo(s => SlideProperties = s, () => SlideProperties, index, length);
 }