示例#1
0
 public AnimatedContainer(
     Key key = null,
     AlignmentGeometry alignment = null,
     EdgeInsetsGeometry padding  = null,
     Color color                     = null,
     Decoration decoration           = null,
     Decoration foregroundDecoration = null,
     float?width                     = null,
     float?height                    = null,
     BoxConstraints constraints      = null,
     EdgeInsetsGeometry margin       = null,
     Matrix4 transform               = null,
     Widget child                    = null,
     Curve curve                     = null,
     TimeSpan?duration               = null,
     VoidCallback onEnd              = null
     ) : base(key: key, curve: curve ?? Curves.linear, duration: duration, onEnd: onEnd)
 {
     D.assert(duration != null);
     D.assert(margin == null || margin.isNonNegative);
     D.assert(padding == null || padding.isNonNegative);
     D.assert(decoration == null || decoration.debugAssertIsValid());
     D.assert(constraints == null || constraints.debugAssertIsValid());
     D.assert(color == null || decoration == null,
              () => "Cannot provide both a color and a decoration\n" +
              "The color argument is just a shorthand for \"decoration: new BoxDecoration(backgroundColor: color)\".");
     this.alignment            = alignment;
     this.padding              = padding;
     this.foregroundDecoration = foregroundDecoration;
     this.margin      = margin;
     this.transform   = transform;
     this.child       = child;
     this.decoration  = decoration ?? (color != null ? new BoxDecoration(color: color) : null);
     this.constraints =
         (width != null || height != null)
             ? constraints?.tighten(width: width, height: height)
         ?? BoxConstraints.tightFor(width: width, height: height)
             : constraints;
 }
示例#2
0
        public Container(
            Key key = null,
            AlignmentGeometry alignment = null,
            EdgeInsetsGeometry padding  = null,
            Color color                     = null,
            Decoration decoration           = null,
            Decoration foregroundDecoration = null,
            float?width                     = null,
            float?height                    = null,
            BoxConstraints constraints      = null,
            EdgeInsetsGeometry margin       = null,
            Matrix4 transform               = null,
            Widget child                    = null,
            Clip clipBehavior               = Clip.none
            ) : base(key: key)
        {
            D.assert(margin == null || margin.isNonNegative);
            D.assert(padding == null || padding.isNonNegative);
            D.assert(decoration == null || decoration.debugAssertIsValid());
            D.assert(constraints == null || constraints.debugAssertIsValid());
            D.assert(color == null || decoration == null,
                     () => "Cannot provide both a color and a decoration\n" +
                     "The color argument is just a shorthand for \"decoration: new BoxDecoration(color: color)\"."
                     );
            D.assert(clipBehavior != null);

            this.alignment            = alignment;
            this.padding              = padding;
            this.foregroundDecoration = foregroundDecoration;
            this.color       = color;
            this.decoration  = decoration;// ?? (color != null ? new BoxDecoration(color) : null);
            this.constraints = (width != null || height != null)
                ? (constraints != null ? constraints.tighten(width, height) : BoxConstraints.tightFor(width, height))
                : constraints;
            this.margin       = margin;
            this.transform    = transform;
            this.child        = child;
            this.clipBehavior = clipBehavior;
        }
示例#3
0
        public Container(
            Key key                        = null,
            Alignment alignment            = null,
            EdgeInsets padding             = null,
            Color color                    = null,
            Decoration decoration          = null,
            Decoration forgroundDecoration = null,
            double?width                   = null,
            double?height                  = null,
            BoxConstraints constraints     = null,
            EdgeInsets margin              = null,
            Matrix3 transfrom              = null,
            Widget child                   = null
            ) : base(key)
        {
            D.assert(margin == null || margin.isNonNegative);
            D.assert(padding == null || padding.isNonNegative);
            D.assert(decoration == null || decoration.debugAssertIsValid());
            D.assert(constraints == null || constraints.debugAssertIsValid());
            D.assert(color == null || decoration == null,
                     "Cannot provide both a color and a decoration\n" +
                     "The color argument is just a shorthand for \"decoration: new BoxDecoration(color: color)\"."
                     );

            this.alignment            = alignment;
            this.padding              = padding;
            this.foregroundDecoration = forgroundDecoration;
            this.margin    = margin;
            this.transform = transfrom;
            this.child     = child;

            this.decoration  = decoration ?? (color != null ? new BoxDecoration(color) : null);
            this.constraints = (width != null || height != null)
                ? (constraints != null ? constraints.tighten(width, height) : BoxConstraints.tightFor(width, height))
                : constraints;
        }
示例#4
0
        protected override void performLayout()
        {
            bool           hasLeading       = this.leading != null;
            bool           hasSubtitle      = this.subtitle != null;
            bool           hasTrailing      = this.trailing != null;
            bool           isTwoLine        = !this.isThreeLine && hasSubtitle;
            bool           isOneLine        = !this.isThreeLine && !hasSubtitle;
            BoxConstraints looseConstraints = this.constraints.loosen();

            float tileWidth    = looseConstraints.maxWidth;
            Size  leadingSize  = _layoutBox(this.leading, looseConstraints);
            Size  trailingSize = _layoutBox(this.trailing, looseConstraints);

            float titleStart = hasLeading
                ? Mathf.Max(_minLeadingWidth, leadingSize.width) + _horizontalTitleGap
                : 0.0f;
            BoxConstraints textConstraints = looseConstraints.tighten(
                width: tileWidth - titleStart - (hasTrailing ? trailingSize.width + _horizontalTitleGap : 0.0f));
            Size titleSize    = _layoutBox(this.title, textConstraints);
            Size subtitleSize = _layoutBox(this.subtitle, textConstraints);

            float titleBaseline    = 0.0f;
            float subtitleBaseline = 0.0f;

            if (isTwoLine)
            {
                titleBaseline    = this.isDense ? 28.0f : 32.0f;
                subtitleBaseline = this.isDense ? 48.0f : 52.0f;
            }
            else if (this.isThreeLine)
            {
                titleBaseline    = this.isDense ? 22.0f : 28.0f;
                subtitleBaseline = this.isDense ? 42.0f : 48.0f;
            }
            else
            {
                D.assert(isOneLine);
            }

            float defaultTileHeight = this._defaultTileHeight;

            float tileHeight = 0.0f;
            float titleY     = 0.0f;
            float subtitleY  = 0.0f;

            if (!hasSubtitle)
            {
                tileHeight = Mathf.Max(defaultTileHeight, titleSize.height + 2.0f * _minVerticalPadding);
                titleY     = (tileHeight - titleSize.height) / 2.0f;
            }
            else
            {
                D.assert(this.subtitleBaselineType != null);
                titleY    = titleBaseline - _boxBaseline(this.title, this.titleBaselineType);
                subtitleY = subtitleBaseline -
                            _boxBaseline(this.subtitle, this.subtitleBaselineType ?? TextBaseline.alphabetic);
                tileHeight = defaultTileHeight;

                float titleOverlap = titleY + titleSize.height - subtitleY;
                if (titleOverlap > 0.0f)
                {
                    titleY    -= titleOverlap / 2.0f;
                    subtitleY += titleOverlap / 2.0f;
                }

                if (titleY < _minVerticalPadding ||
                    (subtitleY + subtitleSize.height + _minVerticalPadding) > tileHeight)
                {
                    tileHeight = titleSize.height + subtitleSize.height + 2.0f * _minVerticalPadding;
                    titleY     = _minVerticalPadding;
                    subtitleY  = titleSize.height + _minVerticalPadding;
                }
            }

            float leadingY;
            float trailingY;

            if (tileHeight > 72.0f)
            {
                leadingY  = 16.0f;
                trailingY = 16.0f;
            }
            else
            {
                leadingY  = Mathf.Min((tileHeight - leadingSize.height) / 2.0f, 16.0f);
                trailingY = (tileHeight - trailingSize.height) / 2.0f;
            }

            if (hasLeading)
            {
                _positionBox(this.leading, new Offset(0.0f, leadingY));
            }

            _positionBox(this.title, new Offset(titleStart, titleY));
            if (hasSubtitle)
            {
                _positionBox(this.subtitle, new Offset(titleStart, subtitleY));
            }

            if (hasTrailing)
            {
                _positionBox(this.trailing, new Offset(tileWidth - trailingSize.width, trailingY));
            }

            this.size = this.constraints.constrain(new Size(tileWidth, tileHeight));
            D.assert(this.size.width == this.constraints.constrainWidth(tileWidth));
            D.assert(this.size.height == this.constraints.constrainHeight(tileHeight));
        }
示例#5
0
 public override BoxConstraints getConstraintsForChild(BoxConstraints constraints)
 {
     return(constraints.tighten(height: Constants.kToolbarHeight));
 }
示例#6
0
文件: stack.cs 项目: JC-ut0/CubeGame
        protected override void performLayout()
        {
            this._hasVisualOverflow = false;
            bool hasNonPositionedChildren = false;

            if (this.childCount == 0)
            {
                this.size = this.constraints.biggest;
                return;
            }

            float width  = this.constraints.minWidth;
            float height = this.constraints.minHeight;

            BoxConstraints nonPositionedConstraints = null;

            switch (this.fit)
            {
            case StackFit.loose:
                nonPositionedConstraints = this.constraints.loosen();
                break;

            case StackFit.expand:
                nonPositionedConstraints = BoxConstraints.tight(this.constraints.biggest);
                break;

            case StackFit.passthrough:
                nonPositionedConstraints = this.constraints;
                break;
            }


            RenderBox child = this.firstChild;

            while (child != null)
            {
                StackParentData childParentData = (StackParentData)child.parentData;

                if (!childParentData.isPositioned)
                {
                    hasNonPositionedChildren = true;

                    child.layout(nonPositionedConstraints, parentUsesSize: true);

                    Size childSize = child.size;
                    width  = Mathf.Max(width, childSize.width);
                    height = Mathf.Max(height, childSize.height);
                }

                child = childParentData.nextSibling;
            }

            if (hasNonPositionedChildren)
            {
                this.size = new Size(width, height);
                D.assert(this.size.width == this.constraints.constrainWidth(width));
                D.assert(this.size.height == this.constraints.constrainHeight(height));
            }
            else
            {
                this.size = this.constraints.biggest;
            }

            child = this.firstChild;
            while (child != null)
            {
                StackParentData childParentData = (StackParentData)child.parentData;

                if (!childParentData.isPositioned)
                {
                    childParentData.offset = this._alignment.alongOffset(this.size - child.size);
                }
                else
                {
                    BoxConstraints childConstraints = new BoxConstraints();

                    if (childParentData.left != null && childParentData.right != null)
                    {
                        childConstraints =
                            childConstraints.tighten(
                                width: this.size.width - childParentData.right - childParentData.left);
                    }
                    else if (childParentData.width != null)
                    {
                        childConstraints = childConstraints.tighten(width: childParentData.width);
                    }

                    if (childParentData.top != null && childParentData.bottom != null)
                    {
                        childConstraints =
                            childConstraints.tighten(
                                height: this.size.height - childParentData.bottom - childParentData.top);
                    }
                    else if (childParentData.height != null)
                    {
                        childConstraints = childConstraints.tighten(height: childParentData.height);
                    }

                    child.layout(childConstraints, parentUsesSize: true);

                    float x;
                    if (childParentData.left != null)
                    {
                        x = childParentData.left.Value;
                    }
                    else if (childParentData.right != null)
                    {
                        x = this.size.width - childParentData.right.Value - child.size.width;
                    }
                    else
                    {
                        x = this._alignment.alongOffset(this.size - child.size).dx;
                    }

                    if (x < 0.0 || x + child.size.width > this.size.width)
                    {
                        this._hasVisualOverflow = true;
                    }

                    float y;
                    if (childParentData.top != null)
                    {
                        y = childParentData.top.Value;
                    }
                    else if (childParentData.bottom != null)
                    {
                        y = this.size.height - childParentData.bottom.Value - child.size.height;
                    }
                    else
                    {
                        y = this._alignment.alongOffset(this.size - child.size).dy;
                    }

                    if (y < 0.0 || y + child.size.height > this.size.height)
                    {
                        this._hasVisualOverflow = true;
                    }

                    childParentData.offset = new Offset(x, y);
                }

                D.assert(child.parentData == childParentData);
                child = childParentData.nextSibling;
            }
        }
示例#7
0
        public static bool layoutPositionedChild(RenderBox child, StackParentData childParentData, Size size,
                                                 Alignment alignment)
        {
            D.assert(childParentData.isPositioned);
            D.assert(child.parentData == childParentData);

            bool           hasVisualOverflow = false;
            BoxConstraints childConstraints  = new BoxConstraints();

            if (childParentData.left != null && childParentData.right != null)
            {
                childConstraints =
                    childConstraints.tighten(width: size.width - childParentData.right - childParentData.left);
            }
            else if (childParentData.width != null)
            {
                childConstraints = childConstraints.tighten(width: childParentData.width);
            }

            if (childParentData.top != null && childParentData.bottom != null)
            {
                childConstraints =
                    childConstraints.tighten(height: size.height - childParentData.bottom - childParentData.top);
            }
            else if (childParentData.height != null)
            {
                childConstraints = childConstraints.tighten(height: childParentData.height);
            }

            child.layout(childConstraints, parentUsesSize: true);

            float?x;

            if (childParentData.left != null)
            {
                x = childParentData.left;
            }
            else if (childParentData.right != null)
            {
                x = size.width - childParentData.right - child.size.width;
            }
            else
            {
                x = alignment.alongOffset(size - child.size as Offset).dx;
            }

            if (x < 0.0 || x + child.size.width > size.width)
            {
                hasVisualOverflow = true;
            }

            float?y;

            if (childParentData.top != null)
            {
                y = childParentData.top;
            }
            else if (childParentData.bottom != null)
            {
                y = size.height - childParentData.bottom - child.size.height;
            }
            else
            {
                y = alignment.alongOffset(size - child.size as Offset).dy;
            }

            if (y < 0.0 || y + child.size.height > size.height)
            {
                hasVisualOverflow = true;
            }

            childParentData.offset = new Offset(x ?? 0, y ?? 0);

            return(hasVisualOverflow);
        }