コード例 #1
0
        protected override void performLayout()
        {
            SliverConstraints constraints = this.constraints;
            float             extent      = constraints.remainingPaintExtent - Mathf.Min(constraints.overlap, 0.0f);

            if (child != null)
            {
                child.layout(constraints.asBoxConstraints(
                                 minExtent: extent,
                                 maxExtent: extent
                                 ));
            }

            float paintedChildSize = calculatePaintOffset(constraints, from: 0.0f, to: extent);

            D.assert(paintedChildSize.isFinite());
            D.assert(paintedChildSize >= 0.0);
            geometry = new SliverGeometry(
                scrollExtent: constraints.viewportMainAxisExtent,
                paintExtent: paintedChildSize,
                maxPaintExtent: paintedChildSize,
                hasVisualOverflow: extent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0
                );
            if (child != null)
            {
                setChildParentData(child, constraints, geometry);
            }
        }
コード例 #2
0
        protected override void performLayout()
        {
            SliverConstraints constraints = this.constraints;
            float             extent      = constraints.viewportMainAxisExtent - constraints.precedingScrollExtent;

            if (child != null)
            {
                float childExtent = 0f;
                switch (constraints.axis)
                {
                case Axis.horizontal:
                    childExtent = child.getMaxIntrinsicWidth(constraints.crossAxisExtent);
                    break;

                case Axis.vertical:
                    childExtent = child.getMaxIntrinsicHeight(constraints.crossAxisExtent);
                    break;
                }
                extent = Mathf.Max(extent, childExtent);
                child.layout(constraints.asBoxConstraints(
                                 minExtent: extent,
                                 maxExtent: extent
                                 ));
            }

            D.assert(extent.isFinite(), () =>
                     "The calculated extent for the child of SliverFillRemaining is not finite. " +
                     "This can happen if the child is a scrollable, in which case, the " +
                     "hasScrollBody property of SliverFillRemaining should not be set to " +
                     "false."
                     );
            float paintedChildSize = calculatePaintOffset(constraints, from: 0.0f, to: extent);

            D.assert(paintedChildSize.isFinite());
            D.assert(paintedChildSize >= 0.0);
            geometry = new SliverGeometry(
                scrollExtent: extent,
                paintExtent: paintedChildSize,
                maxPaintExtent: paintedChildSize,
                hasVisualOverflow: extent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0
                );
            if (child != null)
            {
                setChildParentData(child, constraints, geometry);
            }
        }
コード例 #3
0
        protected override void performLayout()
        {
            if (child == null)
            {
                geometry = SliverGeometry.zero;
                return;
            }

            SliverConstraints constraints = this.constraints;

            child.layout(constraints.asBoxConstraints(), parentUsesSize: true);

            float childExtent = 0.0f;

            switch (constraints.axis)
            {
            case Axis.horizontal:
                childExtent = child.size.width;
                break;

            case Axis.vertical:
                childExtent = child.size.height;
                break;
            }

            float paintedChildSize = calculatePaintOffset(constraints, from: 0.0f, to: childExtent);
            float cacheExtent      = calculateCacheOffset(constraints, from: 0.0f, to: childExtent);

            D.assert(paintedChildSize.isFinite());
            D.assert(paintedChildSize >= 0.0f);

            geometry = new SliverGeometry(
                scrollExtent: childExtent,
                paintExtent: paintedChildSize,
                cacheExtent: cacheExtent,
                maxPaintExtent: childExtent,
                hitTestExtent: paintedChildSize,
                hasVisualOverflow: childExtent > constraints.remainingPaintExtent ||
                constraints.scrollOffset > 0.0f
                );

            setChildParentData(child, constraints, geometry);
        }
コード例 #4
0
        protected override void performLayout()
        {
            SliverConstraints constraints = this.constraints;

            childManager.didStartLayout();
            childManager.setDidUnderflow(false);

            float itemExtent = this.itemExtent;

            float scrollOffset = constraints.scrollOffset + constraints.cacheOrigin;

            D.assert(scrollOffset >= 0.0);
            float remainingExtent = constraints.remainingCacheExtent;

            D.assert(remainingExtent >= 0.0);
            float targetEndScrollOffset = scrollOffset + remainingExtent;

            BoxConstraints childConstraints = constraints.asBoxConstraints(
                minExtent: itemExtent,
                maxExtent: itemExtent
                );

            int firstIndex      = getMinChildIndexForScrollOffset(scrollOffset, itemExtent);
            int?targetLastIndex = targetEndScrollOffset.isFinite()
                ? getMaxChildIndexForScrollOffset(targetEndScrollOffset, itemExtent)
                : (int?)null;

            if (firstChild != null)
            {
                int leadingGarbage  = _calculateLeadingGarbage(firstIndex);
                int trailingGarbage = targetLastIndex == null ? 0: _calculateTrailingGarbage(targetLastIndex.Value);
                collectGarbage(leadingGarbage, trailingGarbage);
            }
            else
            {
                collectGarbage(0, 0);
            }

            if (firstChild == null)
            {
                if (!addInitialChild(index: firstIndex,
                                     layoutOffset: indexToLayoutOffset(itemExtent, firstIndex)))
                {
                    float max;

                    if (childManager.childCount != null)
                    {
                        max = computeMaxScrollOffset(constraints, itemExtent);
                    }
                    else if (firstIndex <= 0)
                    {
                        max = 0.0f;
                    }
                    else
                    {
                        // We will have to find it manually.
                        int possibleFirstIndex = firstIndex - 1;
                        while (
                            possibleFirstIndex > 0 &&
                            !addInitialChild(
                                index: possibleFirstIndex,
                                layoutOffset: indexToLayoutOffset(itemExtent, possibleFirstIndex)
                                )
                            )
                        {
                            possibleFirstIndex -= 1;
                        }

                        max = possibleFirstIndex * itemExtent;
                    }

                    geometry = new SliverGeometry(
                        scrollExtent: max,
                        maxPaintExtent: max
                        );
                    childManager.didFinishLayout();
                    return;
                }
            }

            RenderBox trailingChildWithLayout = null;

            for (int index = indexOf(firstChild) - 1; index >= firstIndex; --index)
            {
                RenderBox child = insertAndLayoutLeadingChild(childConstraints);
                if (child == null)
                {
                    geometry = new SliverGeometry(scrollOffsetCorrection: index * itemExtent);
                    return;
                }

                var childParentData = (SliverMultiBoxAdaptorParentData)child.parentData;
                childParentData.layoutOffset = indexToLayoutOffset(itemExtent, index);
                D.assert(childParentData.index == index);
                trailingChildWithLayout = trailingChildWithLayout ?? child;
            }

            if (trailingChildWithLayout == null)
            {
                firstChild.layout(childConstraints);
                var childParentData = (SliverMultiBoxAdaptorParentData)firstChild.parentData;
                childParentData.layoutOffset = indexToLayoutOffset(itemExtent, firstIndex);
                trailingChildWithLayout      = firstChild;
            }

            float estimatedMaxScrollOffset = float.PositiveInfinity;

            for (int index = indexOf(trailingChildWithLayout) + 1;
                 targetLastIndex == null || index <= targetLastIndex;
                 ++index)
            {
                RenderBox child = childAfter(trailingChildWithLayout);
                if (child == null || indexOf(child) != index)
                {
                    child = insertAndLayoutChild(childConstraints, after: trailingChildWithLayout);
                    if (child == null)
                    {
                        estimatedMaxScrollOffset = index * itemExtent;
                        break;
                    }
                }
                else
                {
                    child.layout(childConstraints);
                }

                trailingChildWithLayout = child;
                var childParentData = (SliverMultiBoxAdaptorParentData)child.parentData;
                D.assert(childParentData.index == index);
                childParentData.layoutOffset = indexToLayoutOffset(itemExtent, childParentData.index);
            }

            int   lastIndex            = indexOf(lastChild);
            float leadingScrollOffset  = indexToLayoutOffset(itemExtent, firstIndex);
            float trailingScrollOffset = indexToLayoutOffset(itemExtent, lastIndex + 1);

            D.assert(firstIndex == 0 ||
                     childScrollOffset(firstChild) - scrollOffset <= foundation_.precisionErrorTolerance);
            D.assert(debugAssertChildListIsNonEmptyAndContiguous());
            D.assert(indexOf(firstChild) == firstIndex);
            D.assert(targetLastIndex == null || lastIndex <= targetLastIndex);


            estimatedMaxScrollOffset = Mathf.Min(
                estimatedMaxScrollOffset,
                estimateMaxScrollOffset(
                    constraints,
                    firstIndex: firstIndex,
                    lastIndex: lastIndex,
                    leadingScrollOffset: leadingScrollOffset,
                    trailingScrollOffset: trailingScrollOffset
                    )
                );

            float paintExtent = calculatePaintOffset(
                constraints,
                from: leadingScrollOffset,
                to: trailingScrollOffset
                );

            float cacheExtent = calculateCacheOffset(
                constraints,
                from: leadingScrollOffset,
                to: trailingScrollOffset
                );

            float targetEndScrollOffsetForPaint =
                constraints.scrollOffset + constraints.remainingPaintExtent;
            int?targetLastIndexForPaint = targetEndScrollOffsetForPaint.isFinite()
                ? getMaxChildIndexForScrollOffset(targetEndScrollOffsetForPaint, itemExtent)
                : (int?)null;

            geometry = new SliverGeometry(
                scrollExtent: estimatedMaxScrollOffset,
                paintExtent: paintExtent,
                cacheExtent: cacheExtent,
                maxPaintExtent: estimatedMaxScrollOffset,
                hasVisualOverflow: (targetLastIndexForPaint != null && lastIndex >= targetLastIndexForPaint) ||
                constraints.scrollOffset > 0.0
                );

            if (estimatedMaxScrollOffset == trailingScrollOffset)
            {
                childManager.setDidUnderflow(true);
            }

            childManager.didFinishLayout();
        }