Пример #1
0
        public void Init(int fixedPaneIndex, float fixedPaneInitialDimension, Orientation orientation)
        {
            m_Orientation               = orientation;
            m_FixedPaneIndex            = fixedPaneIndex;
            m_FixedPaneInitialDimension = fixedPaneInitialDimension;

            m_Content.RemoveFromClassList(s_HorizontalClassName);
            m_Content.RemoveFromClassList(s_VerticalClassName);
            if (m_Orientation == Orientation.Horizontal)
            {
                m_Content.AddToClassList(s_HorizontalClassName);
            }
            else
            {
                m_Content.AddToClassList(s_VerticalClassName);
            }

            // Create drag anchor line.
            m_DragLineAnchor.RemoveFromClassList(s_HandleDragLineAnchorHorizontalClassName);
            m_DragLineAnchor.RemoveFromClassList(s_HandleDragLineAnchorVerticalClassName);
            if (m_Orientation == Orientation.Horizontal)
            {
                m_DragLineAnchor.AddToClassList(s_HandleDragLineAnchorHorizontalClassName);
            }
            else
            {
                m_DragLineAnchor.AddToClassList(s_HandleDragLineAnchorVerticalClassName);
            }

            // Create drag
            m_DragLine.RemoveFromClassList(s_HandleDragLineHorizontalClassName);
            m_DragLine.RemoveFromClassList(s_HandleDragLineVerticalClassName);
            if (m_Orientation == Orientation.Horizontal)
            {
                m_DragLine.AddToClassList(s_HandleDragLineHorizontalClassName);
            }
            else
            {
                m_DragLine.AddToClassList(s_HandleDragLineVerticalClassName);
            }

            if (m_Resizer != null)
            {
                m_DragLineAnchor.RemoveManipulator(m_Resizer);
                m_Resizer = null;
            }

            if (m_Content.childCount != 2)
            {
                RegisterCallback <GeometryChangedEvent>(OnPostDisplaySetup);
            }
            else
            {
                PostDisplaySetup();
            }
        }
Пример #2
0
        void PostDisplaySetup()
        {
            if (m_Content.childCount != 2)
            {
                Debug.LogError("TwoPaneSplitView needs exactly 2 children.");
                return;
            }

            m_LeftPane = m_Content[0];
            if (m_FixedPaneIndex == 0)
            {
                m_FixedPane = m_LeftPane;
                if (m_Orientation == Orientation.Horizontal)
                {
                    m_LeftPane.style.width = m_FixedPaneInitialDimension;
                }
                else
                {
                    m_LeftPane.style.height = m_FixedPaneInitialDimension;
                }
            }
            else
            {
                m_FlexedPane = m_LeftPane;
            }

            m_RightPane = m_Content[1];
            if (m_FixedPaneIndex == 1)
            {
                m_FixedPane = m_RightPane;
                if (m_Orientation == Orientation.Horizontal)
                {
                    m_RightPane.style.width = m_FixedPaneInitialDimension;
                }
                else
                {
                    m_RightPane.style.height = m_FixedPaneInitialDimension;
                }
            }
            else
            {
                m_FlexedPane = m_RightPane;
            }

            m_FixedPane.style.flexShrink  = 0;
            m_FixedPane.style.flexGrow    = 0;
            m_FlexedPane.style.flexGrow   = 1;
            m_FlexedPane.style.flexShrink = 0;
            m_FlexedPane.style.flexBasis  = 0;

            if (m_Orientation == Orientation.Horizontal)
            {
                if (m_FixedPaneIndex == 0)
                {
                    m_DragLineAnchor.style.left = m_FixedPaneInitialDimension;
                }
                else
                {
                    m_DragLineAnchor.style.left = this.resolvedStyle.width - m_FixedPaneInitialDimension;
                }
            }
            else
            {
                if (m_FixedPaneIndex == 0)
                {
                    m_DragLineAnchor.style.top = m_FixedPaneInitialDimension;
                }
                else
                {
                    m_DragLineAnchor.style.top = this.resolvedStyle.height - m_FixedPaneInitialDimension;
                }
            }

            int direction = 1;

            if (m_FixedPaneIndex == 0)
            {
                direction = 1;
            }
            else
            {
                direction = -1;
            }

            if (m_FixedPaneIndex == 0)
            {
                m_Resizer = new Spliter(this, direction, m_Orientation);
            }
            else
            {
                m_Resizer = new Spliter(this, direction, m_Orientation);
            }

            m_DragLineAnchor.AddManipulator(m_Resizer);

            UnregisterCallback <GeometryChangedEvent>(OnPostDisplaySetup);
            RegisterCallback <GeometryChangedEvent>(OnSizeChange);
        }