Exemple #1
0
        protected override void performLayout()
        {
            BoxConstraints constraints = this.constraints;

            size = constraints.biggest;

            if (child == null)
            {
                return;
            }
            BoxConstraints enforcedConstraint = constraints
                                                .deflate(EdgeInsets.symmetric(horizontal: CupertinoTextSelectionUtils._kToolbarScreenPadding))
                                                .loosen();

            child.layout(heightConstraint.enforce(enforcedConstraint), parentUsesSize: true);
            _ToolbarParentData childParentData = child.parentData as _ToolbarParentData;


            float lowerBound      = child.size.width / 2 + CupertinoTextSelectionUtils._kToolbarScreenPadding;
            float upperBound      = size.width - child.size.width / 2 - CupertinoTextSelectionUtils._kToolbarScreenPadding;
            float adjustedCenterX = _arrowTipX.clamp(lowerBound, upperBound);

            childParentData.offset = new Offset(adjustedCenterX - child.size.width / 2, _barTopY);
            childParentData.arrowXOffsetFromCenter = _arrowTipX - adjustedCenterX;
        }
Exemple #2
0
        protected override void performLayout()
        {
            BoxConstraints constraints             = this.constraints;
            bool           hasLeading              = leading != null;
            bool           hasSubtitle             = subtitle != null;
            bool           hasTrailing             = trailing != null;
            bool           isTwoLine               = !isThreeLine && hasSubtitle;
            bool           isOneLine               = !isThreeLine && !hasSubtitle;
            BoxConstraints maxIconHeightConstrains = new BoxConstraints(
                maxHeight: isDense ? 48.0f : 56.0f
                );
            BoxConstraints looseConstraints = constraints.loosen();
            BoxConstraints iconConstraints  = looseConstraints.enforce(maxIconHeightConstrains);

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

            D.assert(
                tileWidth != leadingSize.width,
                () => "Leading widget consumes entire width. Please use a sized widget."
                );
            D.assert(
                tileWidth != trailingSize.width,
                () => "Trailing widget consumes entire width. Please use a sized widget."
                );

            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(title, textConstraints);
            Size subtitleSize = _layoutBox(subtitle, textConstraints);

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

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

            float defaultTileHeight = _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(subtitleBaselineType != null);
                titleY    = titleBaseline - _boxBaseline(title, titleBaselineType);
                subtitleY = subtitleBaseline -
                            _boxBaseline(subtitle, 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(leading, new Offset(0.0f, leadingY));
            }

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

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

            size = constraints.constrain(new Size(tileWidth, tileHeight));
            D.assert(size.width == constraints.constrainWidth(tileWidth));
            D.assert(size.height == constraints.constrainHeight(tileHeight));
        }