Example #1
0
            protected void OnMouseDown(MouseDownEvent e)
            {
                if (CanStartManipulation(e))
                {
                    VisualSplitter visualSplitter = target as VisualSplitter;
                    FlexDirection  flexDirection  = visualSplitter.style.flexDirection;

                    if (m_AffectedElements != null)
                    {
                        VisualElementListPool.Release(m_AffectedElements);
                    }
                    m_AffectedElements = visualSplitter.GetAffectedVisualElements();

                    for (int i = 0; i < m_AffectedElements.Count - 1; ++i)
                    {
                        VisualElement visualElement = m_AffectedElements[i];

                        Rect splitterRect = visualSplitter.GetSplitterRect(visualElement);

                        if (splitterRect.Contains(e.localMousePosition))
                        {
                            bool isReverse = flexDirection == FlexDirection.RowReverse || flexDirection == FlexDirection.ColumnReverse;

                            if (isReverse)
                            {
                                m_ActiveVisualElementIndex = i + 1;
                                m_NextVisualElementIndex   = i;
                            }
                            else
                            {
                                m_ActiveVisualElementIndex = i;
                                m_NextVisualElementIndex   = i + 1;
                            }

                            m_Active = true;
                            target.CaptureMouse();
                            e.StopPropagation();
                        }
                    }
                }
            }
Example #2
0
            protected void OnMouseMove(MouseMoveEvent e)
            {
                if (m_Active)
                {
                    // These calculations should only work if flex-basis is auto.
                    // However, Yoga implementation of flex-basis 0 is broken and behaves much like
                    // flex-basis auto, so it currently works with flex-basis 0 too.

                    VisualSplitter visualSplitter    = target as VisualSplitter;
                    VisualElement  visualElement     = m_AffectedElements[m_ActiveVisualElementIndex];
                    VisualElement  nextVisualElement = m_AffectedElements[m_NextVisualElementIndex];

                    FlexDirection flexDirection = visualSplitter.style.flexDirection;
                    bool          isVertical    = flexDirection == FlexDirection.Column || flexDirection == FlexDirection.ColumnReverse;

                    float relativeMousePosition;
                    if (isVertical)
                    {
                        relativeMousePosition = (e.localMousePosition.y - visualElement.layout.yMin - visualElement.style.minHeight) /
                                                (visualElement.layout.height + nextVisualElement.layout.height -
                                                 visualElement.style.minHeight - nextVisualElement.style.minHeight);
                    }
                    else
                    {
                        relativeMousePosition = (e.localMousePosition.x - visualElement.layout.xMin - visualElement.style.minWidth) /
                                                (visualElement.layout.width + nextVisualElement.layout.width -
                                                 visualElement.style.minWidth - nextVisualElement.style.minWidth);
                    }

                    relativeMousePosition = Math.Max(0.0f, Math.Min(1.0f, relativeMousePosition));

                    float totalFlex = visualElement.style.flexGrow + nextVisualElement.style.flexGrow;
                    visualElement.style.flexGrow     = relativeMousePosition * totalFlex;
                    nextVisualElement.style.flexGrow = (1.0f - relativeMousePosition) * totalFlex;

                    e.StopPropagation();
                }
            }