コード例 #1
0
ファイル: Container.cs プロジェクト: Paramecium13/Nez
        public override void Layout()
        {
            if (_element == null)
            {
                return;
            }

            float padLeft = _padLeft.Get(this), padBottom = _padBottom.Get(this);
            float containerWidth = GetWidth() - padLeft - _padRight.Get(this);
            float containerHeight = GetHeight() - padBottom - _padTop.Get(this);
            float minWidth = _minWidthValue.Get(_element), minHeight = _minHeightValue.Get(_element);
            float prefWidth = _prefWidthValue.Get(_element), prefHeight = _prefHeightValue.Get(_element);
            float maxWidth = _maxWidthValue.Get(_element), maxHeight = _maxHeightValue.Get(_element);

            float width;

            if (_fillX > 0)
            {
                width = containerWidth * _fillX;
            }
            else
            {
                width = Math.Min(prefWidth, containerWidth);
            }
            if (width < minWidth)
            {
                width = minWidth;
            }
            if (maxWidth > 0 && width > maxWidth)
            {
                width = maxWidth;
            }

            float height;

            if (_fillY > 0)
            {
                height = containerHeight * _fillY;
            }
            else
            {
                height = Math.Min(prefHeight, containerHeight);
            }

            if (height < minHeight)
            {
                height = minHeight;
            }
            if (maxHeight > 0 && height > maxHeight)
            {
                height = maxHeight;
            }

            var x = padLeft;

            if ((_align & AlignInternal.Right) != 0)
            {
                x += containerWidth - width;
            }
            else if ((_align & AlignInternal.Left) == 0)             // center
            {
                x += (containerWidth - width) / 2;
            }

            var y = padBottom;

            if ((_align & AlignInternal.Top) != 0)
            {
                y += containerHeight - height;
            }
            else if ((_align & AlignInternal.Bottom) == 0)             // center
            {
                y += (containerHeight - height) / 2;
            }

            if (_round)
            {
                x      = Mathf.Round(x);
                y      = Mathf.Round(y);
                width  = Mathf.Round(width);
                height = Mathf.Round(height);
            }

            _element.SetBounds(x, y, width, height);
            if (_element is ILayout)
            {
                ((ILayout)_element).Validate();
            }
        }
コード例 #2
0
 public float GetPadTop()
 {
     return(padTop.Get(element));
 }
コード例 #3
0
 public float GetSpaceTop()
 {
     return(spaceTop.Get(element));
 }
コード例 #4
0
 public float GetMaxWidth()
 {
     return(maxWidth.Get(element));
 }
コード例 #5
0
 public float GetPrefWidth()
 {
     return(prefWidth.Get(element));
 }
コード例 #6
0
 public float GetMinWidth()
 {
     return(minWidth.Get(element));
 }