예제 #1
0
        public void positionChild(object childId, Offset offset)
        {
            RenderBox child = this._idToChild[childId];

            D.assert(() => {
                if (child == null)
                {
                    throw new UIWidgetsError(
                        $"The {this} custom multichild layout delegate tried to position out a non-existent child:\n" +
                        $"There is no child with the id \"{childId}\"."
                        );
                }

                if (offset == null)
                {
                    throw new UIWidgetsError(
                        $"The {this} custom multichild layout delegate provided a null position for the child with id \"{childId}\"."
                        );
                }

                return(true);
            });
            MultiChildLayoutParentData childParentData = (MultiChildLayoutParentData)child.parentData;

            childParentData.offset = offset;
        }
예제 #2
0
        internal void _callPerformLayout(Size size, RenderBox firstChild)
        {
            Dictionary <object, RenderBox> previousIdToChild = this._idToChild;

            HashSet <RenderBox> debugPreviousChildrenNeedingLayout = null;

            D.assert(() => {
                debugPreviousChildrenNeedingLayout = this._debugChildrenNeedingLayout;
                this._debugChildrenNeedingLayout   = new HashSet <RenderBox>();
                return(true);
            });

            try {
                this._idToChild = new Dictionary <object, RenderBox>();
                RenderBox child = firstChild;
                while (child != null)
                {
                    MultiChildLayoutParentData childParentData = (MultiChildLayoutParentData)child.parentData;
                    D.assert(() => {
                        if (childParentData.id == null)
                        {
                            throw new UIWidgetsError(
                                "The following child has no ID:\n" +
                                $"  {child}\n" +
                                "Every child of a RenderCustomMultiChildLayoutBox must have an ID in its parent data."
                                );
                        }

                        return(true);
                    });
                    this._idToChild[childParentData.id] = child;
                    D.assert(() => {
                        this._debugChildrenNeedingLayout.Add(child);
                        return(true);
                    });
                    child = childParentData.nextSibling;
                }

                this.performLayout(size);
                D.assert(() => {
                    if (this._debugChildrenNeedingLayout.isNotEmpty())
                    {
                        if (this._debugChildrenNeedingLayout.Count > 1)
                        {
                            throw new UIWidgetsError(
                                $"The $this custom multichild layout delegate forgot to lay out the following children:\n" +
                                $"  {string.Join("\n  ", this._debugChildrenNeedingLayout.Select(this._debugDescribeChild))}\n" +
                                "Each child must be laid out exactly once."
                                );
                        }
                        else
                        {
                            throw new UIWidgetsError(
                                $"The $this custom multichild layout delegate forgot to lay out the following child:\n" +
                                $"  {this._debugDescribeChild(this._debugChildrenNeedingLayout.First())}\n" +
                                "Each child must be laid out exactly once."
                                );
                        }
                    }

                    return(true);
                });
            }
            finally {
                this._idToChild = previousIdToChild;
                D.assert(() => {
                    this._debugChildrenNeedingLayout = debugPreviousChildrenNeedingLayout;
                    return(true);
                });
            }
        }
예제 #3
0
        string _debugDescribeChild(RenderBox child)
        {
            MultiChildLayoutParentData childParentData = (MultiChildLayoutParentData)child.parentData;

            return($"{childParentData.id}: {child}");
        }
예제 #4
0
        internal void _callPerformLayout(Size size, RenderBox firstChild)
        {
            Dictionary <object, RenderBox> previousIdToChild = _idToChild;

            HashSet <RenderBox> debugPreviousChildrenNeedingLayout = null;

            D.assert(() => {
                debugPreviousChildrenNeedingLayout = _debugChildrenNeedingLayout;
                _debugChildrenNeedingLayout        = new HashSet <RenderBox>();
                return(true);
            });

            try {
                _idToChild = new Dictionary <object, RenderBox>();
                RenderBox child = firstChild;
                while (child != null)
                {
                    MultiChildLayoutParentData childParentData = (MultiChildLayoutParentData)child.parentData;
                    D.assert(() => {
                        if (childParentData.id == null)
                        {
                            throw new UIWidgetsError(new List <DiagnosticsNode> {
                                new ErrorSummary("Every child of a RenderCustomMultiChildLayoutBox must have an ID in its parent data."),
                                child.describeForError("The following child has no ID")
                            });
                        }

                        return(true);
                    });
                    _idToChild[childParentData.id] = child;
                    D.assert(() => {
                        _debugChildrenNeedingLayout.Add(child);
                        return(true);
                    });
                    child = childParentData.nextSibling;
                }

                performLayout(size);
                D.assert(() => {
                    List <DiagnosticsNode> renderBoxes = new List <DiagnosticsNode>();
                    foreach (var renderBox in _debugChildrenNeedingLayout)
                    {
                        renderBoxes.Add(_debugDescribeChild(renderBox));
                    }
                    if (_debugChildrenNeedingLayout.isNotEmpty())
                    {
                        throw new UIWidgetsError(new List <DiagnosticsNode> {
                            new ErrorSummary("Each child must be laid out exactly once."),
                            new DiagnosticsBlock(
                                name: "The $this custom multichild layout delegate forgot " +
                                "to lay out the following child(ren)",
                                properties: renderBoxes,
                                style: DiagnosticsTreeStyle.whitespace
                                )
                        });
                    }

                    return(true);
                });
            }
            finally {
                _idToChild = previousIdToChild;
                D.assert(() => {
                    _debugChildrenNeedingLayout = debugPreviousChildrenNeedingLayout;
                    return(true);
                });
            }
        }
예제 #5
0
        DiagnosticsNode _debugDescribeChild(RenderBox child)
        {
            MultiChildLayoutParentData childParentData = (MultiChildLayoutParentData)child.parentData;

            return(new DiagnosticsProperty <RenderBox>($"{childParentData.id}", child));
        }