Beispiel #1
0
 //[MethodImpl(MethodImplOptions.AggressiveInlining)]
 public void Activate()
 {
     activeStack.Add(this);
     current = this;
 }
Beispiel #2
0
        public void CalculateSubRects()
        /// Sets finalPixelSize for child cells
        /// From parent to children
        {
            if (subCells == null)
            {
                return;
            }
            int subCount = subCells.Count;

            if (subCount == 0)
            {
                return;
            }

            //calculating relative sum
            float relativeSizeSumX = 0; float relativeSizeSumY = 0;                 //Vector2 relativeSizeSum = new Vector2();

            for (int s = 0; s < subCount; s++)
            {
                Cell sub = subCells[s];
                if (sub.stackHor)
                {
                    relativeSizeSumX += sub.relativeSize.x;
                }
                if (sub.stackVer)
                {
                    relativeSizeSumY += sub.relativeSize.y;
                }
            }

            //calculating the number of remaining pixels for relative
            float subsPixelsSumX = 0; float subsPixelsSumY = 0;                 //Vector2 subsPixelsSum = new Vector2();

            for (int s = 0; s < subCount; s++)
            {
                Cell sub = subCells[s];
                subsPixelsSumX += sub.pixelSize.x;                         //using assigned size, ignoring subs min contents size
                subsPixelsSumY += sub.pixelSize.y;
            }
            //Vector2 relativePixelsLeft = new Vector2(finalSize.x - subsPixelsSum.x, finalSize.y - subsPixelsSum.y);
            float relativePixelsLeftX = finalSize.x - subsPixelsSumX;
            float relativePixelsLeftY = finalSize.y - subsPixelsSumY;

            //setting rects
            float currentPosX = 0; float currentPosY = 0;                  //Vector2 currentPos = new Vector2();

            for (int s = 0; s < subCount; s++)
            {
                Cell sub = subCells[s];

                //horizontal
                if (sub.stackHor)
                {
                    float relativePixelsX = 0;
                    if (relativeSizeSumX != 0 && sub.relativeSize.x != 0)
                    {
                        relativePixelsX = sub.relativeSize.x / relativeSizeSumX * relativePixelsLeftX;
                    }

                    sub.finalSize.x    = sub.minPixelSize.x > relativePixelsX ? sub.minPixelSize.x : relativePixelsX;                         //Mathf.Max(sub.minPixelSize.x, relativePixelsX);
                    sub.cellPosition.x = currentPosX;

                    currentPosX += sub.finalSize.x;
                }
                else
                {
                    sub.finalSize.x =                             //Mathf.Max(sub.minPixelSize.x, finalSize.x*sub.relativeSize.x+sub.pixelSize.x);
                                      sub.minPixelSize.x > finalSize.x * sub.relativeSize.x + sub.pixelSize.x ?
                                      sub.minPixelSize.x :
                                      finalSize.x * sub.relativeSize.x + sub.pixelSize.x;
                    sub.cellPosition.x = finalSize.x * sub.relativeOffset.x;
                }

                //vertical
                if (sub.stackVer)
                {
                    float relativePixelsY = 0;
                    if (relativeSizeSumY != 0 && sub.relativeSize.y != 0)
                    {
                        relativePixelsY = sub.relativeSize.y / relativeSizeSumY * relativePixelsLeftY;
                    }

                    sub.finalSize.y    = sub.minPixelSize.y > relativePixelsY ? sub.minPixelSize.y : relativePixelsY;                        //Mathf.Max(sub.minPixelSize.y, relativePixelsY);
                    sub.cellPosition.y = currentPosY;

                    currentPosY += sub.finalSize.y;
                }
                else
                {
                    sub.finalSize.y =                             //Mathf.Max(sub.minPixelSize.y, finalSize.y*sub.relativeSize.y+sub.pixelSize.y);
                                      sub.minPixelSize.y > finalSize.y * sub.relativeSize.y + sub.pixelSize.y ?
                                      sub.minPixelSize.y :
                                      finalSize.y * sub.relativeSize.y + sub.pixelSize.y;
                    sub.cellPosition.y = finalSize.y * sub.relativeOffset.y;
                }

                sub.cellPosition += sub.pixelOffset;
                sub.worldPosition = worldPosition + sub.cellPosition;

                ///sub.finalSize += sub.pixelResize;

                if (sub.subCells != null)
                {
                    sub.CalculateSubRects();
                }
            }
        }