Commit b0e8520a authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Make LayoutCallback generic and other minor changes (#7367)

LayoutCallback passes constraints to the callback, but the constraints
object has a different type for different subclasses. This lets you
call invokeLayoutCallback() with a specific type to verify that
everything is working as expected.

Other changes:

Slightly improve the error reporting in RenderObject.

Allow toStringShallow on RenderObject to have its separator configured.
parent ec9a6fbb
...@@ -520,7 +520,7 @@ class RenderGrid extends RenderVirtualViewport<GridParentData> { ...@@ -520,7 +520,7 @@ class RenderGrid extends RenderVirtualViewport<GridParentData> {
int virtualChildBase: 0, int virtualChildBase: 0,
int virtualChildCount, int virtualChildCount,
Offset paintOffset: Offset.zero, Offset paintOffset: Offset.zero,
LayoutCallback callback LayoutCallback<BoxConstraints> callback
}) : _delegate = delegate, _virtualChildBase = virtualChildBase, super( }) : _delegate = delegate, _virtualChildBase = virtualChildBase, super(
virtualChildCount: virtualChildCount, virtualChildCount: virtualChildCount,
paintOffset: paintOffset, paintOffset: paintOffset,
...@@ -643,7 +643,7 @@ class RenderGrid extends RenderVirtualViewport<GridParentData> { ...@@ -643,7 +643,7 @@ class RenderGrid extends RenderVirtualViewport<GridParentData> {
size = constraints.constrain(gridSize); size = constraints.constrain(gridSize);
if (callback != null) if (callback != null)
invokeLayoutCallback(callback); invokeLayoutCallback/*<BoxConstraints>*/(callback);
double gridTopPadding = 0.0; double gridTopPadding = 0.0;
double gridLeftPadding = 0.0; double gridLeftPadding = 0.0;
......
...@@ -33,7 +33,7 @@ class RenderList extends RenderVirtualViewport<ListParentData> { ...@@ -33,7 +33,7 @@ class RenderList extends RenderVirtualViewport<ListParentData> {
Offset paintOffset: Offset.zero, Offset paintOffset: Offset.zero,
Axis mainAxis: Axis.vertical, Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start, ViewportAnchor anchor: ViewportAnchor.start,
LayoutCallback callback LayoutCallback<BoxConstraints> callback
}) : _itemExtent = itemExtent, }) : _itemExtent = itemExtent,
_padding = padding, _padding = padding,
super( super(
...@@ -153,7 +153,7 @@ class RenderList extends RenderVirtualViewport<ListParentData> { ...@@ -153,7 +153,7 @@ class RenderList extends RenderVirtualViewport<ListParentData> {
} }
if (callback != null) if (callback != null)
invokeLayoutCallback(callback); invokeLayoutCallback/*<BoxConstraints>*/(callback);
double itemWidth; double itemWidth;
double itemHeight; double itemHeight;
......
...@@ -529,7 +529,7 @@ typedef void RenderObjectVisitor(RenderObject child); ...@@ -529,7 +529,7 @@ typedef void RenderObjectVisitor(RenderObject child);
/// Signature for a function that is called during layout. /// Signature for a function that is called during layout.
/// ///
/// Used by [RenderObject.invokeLayoutCallback]. /// Used by [RenderObject.invokeLayoutCallback].
typedef void LayoutCallback(Constraints constraints); typedef void LayoutCallback<T extends Constraints>(T constraints);
class _SemanticsGeometry { class _SemanticsGeometry {
_SemanticsGeometry() : transform = new Matrix4.identity(); _SemanticsGeometry() : transform = new Matrix4.identity();
...@@ -1314,9 +1314,8 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -1314,9 +1314,8 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
context: 'during $method()', context: 'during $method()',
renderObject: this, renderObject: this,
informationCollector: (StringBuffer information) { informationCollector: (StringBuffer information) {
information.writeln('The following RenderObject was being processed when the exception was fired:\n $this'); information.writeln('The following RenderObject was being processed when the exception was fired:');
if (debugCreator != null) information.writeln(' ${toStringShallow('\n ')}');
information.writeln('This RenderObject had the following creator information:\n $debugCreator');
List<String> descendants = <String>[]; List<String> descendants = <String>[];
const int maxDepth = 5; const int maxDepth = 5;
int depth = 0; int depth = 0;
...@@ -1825,7 +1824,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -1825,7 +1824,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
/// ///
/// This function can only be called during layout. /// This function can only be called during layout.
@protected @protected
void invokeLayoutCallback(LayoutCallback callback) { void invokeLayoutCallback/*<T extends Constraints>*/(LayoutCallback/*<T>*/ callback) {
assert(_debugMutationsLocked); assert(_debugMutationsLocked);
assert(_debugDoingThisLayout); assert(_debugDoingThisLayout);
assert(!_doingThisLayoutWithCallback); assert(!_doingThisLayoutWithCallback);
...@@ -2428,14 +2427,14 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -2428,14 +2427,14 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
/// ///
/// This includes the same information for this RenderObject as given by /// This includes the same information for this RenderObject as given by
/// [toStringDeep], but does not recurse to any children. /// [toStringDeep], but does not recurse to any children.
String toStringShallow() { String toStringShallow([String joiner = '; ']) {
RenderObject debugPreviousActiveLayout = _debugActiveLayout; RenderObject debugPreviousActiveLayout = _debugActiveLayout;
_debugActiveLayout = null; _debugActiveLayout = null;
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
result.write('$this; '); result.write('${this}$joiner'); // TODO(ianh): https://github.com/dart-lang/sdk/issues/28206
List<String> description = <String>[]; List<String> description = <String>[];
debugFillDescription(description); debugFillDescription(description);
result.write(description.join('; ')); result.write(description.join(joiner));
_debugActiveLayout = debugPreviousActiveLayout; _debugActiveLayout = debugPreviousActiveLayout;
return result.toString(); return result.toString();
} }
......
...@@ -358,7 +358,7 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende ...@@ -358,7 +358,7 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende
/// The [paintOffset] and [mainAxis] arguments must not be null. /// The [paintOffset] and [mainAxis] arguments must not be null.
RenderVirtualViewport({ RenderVirtualViewport({
int virtualChildCount, int virtualChildCount,
LayoutCallback callback, LayoutCallback<BoxConstraints> callback,
Offset paintOffset: Offset.zero, Offset paintOffset: Offset.zero,
Axis mainAxis: Axis.vertical, Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start ViewportAnchor anchor: ViewportAnchor.start
...@@ -382,9 +382,9 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende ...@@ -382,9 +382,9 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende
/// ///
/// Typically the callback will mutate the child list appropriately, for /// Typically the callback will mutate the child list appropriately, for
/// example so the child list contains only visible children. /// example so the child list contains only visible children.
LayoutCallback get callback => _callback; LayoutCallback<BoxConstraints> get callback => _callback;
LayoutCallback _callback; LayoutCallback<BoxConstraints> _callback;
set callback(LayoutCallback value) { set callback(LayoutCallback<BoxConstraints> value) {
if (value == _callback) if (value == _callback)
return; return;
_callback = value; _callback = value;
......
...@@ -151,12 +151,12 @@ class _LayoutBuilderElement extends RenderObjectElement { ...@@ -151,12 +151,12 @@ class _LayoutBuilderElement extends RenderObjectElement {
class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<RenderBox> { class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<RenderBox> {
_RenderLayoutBuilder({ _RenderLayoutBuilder({
LayoutCallback callback, LayoutCallback<BoxConstraints> callback,
}) : _callback = callback; }) : _callback = callback;
LayoutCallback get callback => _callback; LayoutCallback<BoxConstraints> get callback => _callback;
LayoutCallback _callback; LayoutCallback<BoxConstraints> _callback;
set callback(LayoutCallback value) { set callback(LayoutCallback<BoxConstraints> value) {
if (value == _callback) if (value == _callback)
return; return;
_callback = value; _callback = value;
......
...@@ -397,7 +397,7 @@ class _RenderLazyBlock extends RenderVirtualViewport<_LazyBlockParentData> { ...@@ -397,7 +397,7 @@ class _RenderLazyBlock extends RenderVirtualViewport<_LazyBlockParentData> {
_RenderLazyBlock({ _RenderLazyBlock({
Offset paintOffset: Offset.zero, Offset paintOffset: Offset.zero,
Axis mainAxis: Axis.vertical, Axis mainAxis: Axis.vertical,
LayoutCallback callback LayoutCallback<BoxConstraints> callback
}) : super( }) : super(
paintOffset: paintOffset, paintOffset: paintOffset,
mainAxis: mainAxis, mainAxis: mainAxis,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment