Exemplo n.º 1
0
        /// <summary>
        /// update layout of this view and all views effected
        /// </summary>
        public void UpdateLayout(Vector2 startPos)
        {
            XY   = startPos;
            Size = CalculateSize();

            switch (Type)
            {
            case ViewType.Field:
            case ViewType.Input:
            case ViewType.ConnectionInput:
            case ViewType.LineGroup:
            {
                if (m_Next == null /*|| (!changePos && !changeSize)*/)
                {
                    //reach the last child, or no change in current hierarchy, update it's parent view
                    m_Parent.UpdateLayout(m_Parent.SiblingIndex == 0 ? m_Parent.HeaderXY : m_Parent.XY);
                }
                else
                {
                    //update next
                    if (Type != ViewType.LineGroup)
                    {
                        // same line
                        startPos.x += Size.x + BlockViewSettings.Get().ContentSpace.x;
                    }
                    else
                    {
                        // start a new line
                        startPos.y -= Size.y + BlockViewSettings.Get().ContentSpace.y;
                    }

                    BaseView topmostChild = m_Next.GetTopmostChild();
                    if (topmostChild != m_Next)
                    {
                        //need to update from its topmost child
                        m_Next.XY = startPos;
                        topmostChild.UpdateLayout(topmostChild.HeaderXY);
                    }
                    else
                    {
                        m_Next.UpdateLayout(startPos);
                    }
                }
                break;
            }

            case ViewType.Connection:
            case ViewType.Block:
            {
                //no need to update its m_Next, as it is handled by Unity's Transform autolayout
                //update its parent directly
                if (m_Parent != null)
                {
                    m_Parent.UpdateLayout(m_Parent.SiblingIndex == 0 ? m_Parent.HeaderXY : m_Parent.XY);
                }
                break;
            }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Build the layout of the block view from its topmost child
        /// </summary>
        public void BuildLayout()
        {
            BaseView startView = this.GetLineGroup(0).GetTopmostChild();

            startView.UpdateLayout(startView.HeaderXY);
        }
Exemplo n.º 3
0
        /// <summary>
        /// update layout of this view and all views effected
        /// </summary>
        public void UpdateLayout(Vector2 startPos)
        {
            Vector2 newSize    = CalculateSize();
            bool    changePos  = XY != startPos;
            bool    changeSize = Size != newSize;

            if (changePos)
            {
                XY = startPos;
            }
            if (changeSize)
            {
                Size = newSize;
            }

            switch (Type)
            {
            case ViewType.Field:
            case ViewType.Input:
            case ViewType.ConnectionInput:
            case ViewType.LineGroup:
            {
                if (m_Next == null /*|| (!changePos && !changeSize)*/)
                {
                    //reach the last child, or no change in current hierarchy, update it's parent view
                    m_Parent.UpdateLayout(m_Parent.SiblingIndex == 0 ? m_Parent.HeaderXY : m_Parent.XY);
                }
                else
                {
                    //update next
                    if (Type != ViewType.LineGroup)
                    {
                        // same line
                        startPos.x += Size.x + BlockViewSettings.Get().ContentSpace.x;
                    }
                    else
                    {
                        // start a new line
                        startPos.y -= Size.y + BlockViewSettings.Get().ContentSpace.y;
                    }

                    BaseView topmostChild = m_Next.GetTopmostChild();
                    if (topmostChild != m_Next)
                    {
                        //need to update from its topmost child
                        m_Next.XY = startPos;
                        topmostChild.UpdateLayout(topmostChild.HeaderXY);
                    }
                    else
                    {
                        m_Next.UpdateLayout(startPos);
                    }
                }
                // update connection location in ConnectionDB
                if (Type == ViewType.ConnectionInput)
                {
                    ConnectionView connectionView = (ConnectionView)this;
                    if (connectionView != null)
                    {
                        connectionView.OnXYUpdated();
                    }
                }

                break;
            }

            case ViewType.Connection:
            case ViewType.Block:
            {
                //no need to update its m_Next, as it is handled by Unity's Transform autolayout
                //update its parent directly
                if (m_Parent != null)
                {
                    m_Parent.UpdateLayout(m_Parent.SiblingIndex == 0 ? m_Parent.HeaderXY : m_Parent.XY);
                }

                // update connection location in ConnectionDB
                if (Type == ViewType.Block)
                {
                    BlockView blockView = (BlockView)this;
                    if (blockView != null)
                    {
                        foreach (var view in blockView.Childs)
                        {
                            if (view.Type == ViewType.Connection)
                            {
                                view.OnXYUpdated();
                            }
                        }
                    }
                }

                break;
            }
            }
        }