Ejemplo n.º 1
0
        void OnMouseMove(MouseMoveEvent evt)
        {
            if (!m_Dragging)
            {
                return;
            }

            // We don't freeze immediately as it breaks focus when we refresh the list.
            if (!m_ListFrozen)
            {
                m_DragAreaBottom = FreezeScrollView();
                m_ListFrozen     = true;
            }

            var newPos = Mathf.Clamp(m_Item.style.top.value.value + evt.mouseDelta.y, m_DragAreaTop, m_DragAreaBottom - m_Item.layout.height);

            int   index  = 0;
            float y      = 0;
            float offset = 0;

            m_CurrentIndex = -1;
            foreach (ListItem child in m_Children)
            {
                if (child == m_Item)
                {
                    continue;
                }

                if (m_CurrentIndex == -1 && newPos < y + child.layout.height * 0.5f)
                {
                    offset        += m_Item.layout.height;
                    m_CurrentIndex = index;
                }

                if (child.Animator?.to.top != offset)
                {
                    child.Animator?.Stop();
                    child.Animator?.Recycle();
                    child.Animator = child.experimental.animation.Start(new StyleValues {
                        top = offset
                    }, 500);
                    child.Animator.KeepAlive();
                }

                y      += child.layout.height;
                offset += child.layout.height;
                index++;
            }

            if (m_CurrentIndex == -1)
            {
                m_CurrentIndex = m_Children.Count - 1;
            }

            m_Item.style.top = newPos;
            m_Item.BringToFront();
            evt.StopPropagation();
        }