Generalize _cleanRelayoutSubtreeRootChildren into visitChildren
This generalization will let us implement other alogorithims that need to walk the RenderObject tree.
This commit is contained in:
parent
0c05c97e20
commit
53884a37de
@ -90,6 +90,7 @@ abstract class Constraints {
|
|||||||
bool get isTight;
|
bool get isTight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef void RenderObjectVisitor(RenderObject child);
|
||||||
typedef void LayoutCallback(Constraints constraints);
|
typedef void LayoutCallback(Constraints constraints);
|
||||||
|
|
||||||
abstract class RenderObject extends AbstractNode implements HitTestTarget {
|
abstract class RenderObject extends AbstractNode implements HitTestTarget {
|
||||||
@ -125,6 +126,9 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
|
|||||||
markNeedsLayout();
|
markNeedsLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override in subclasses with children and call the visitor for each child.
|
||||||
|
void visitChildren(RenderObjectVisitor visitor) { }
|
||||||
|
|
||||||
static bool _debugDoingLayout = false;
|
static bool _debugDoingLayout = false;
|
||||||
static bool get debugDoingLayout => _debugDoingLayout;
|
static bool get debugDoingLayout => _debugDoingLayout;
|
||||||
bool _debugDoingThisResize = false;
|
bool _debugDoingThisResize = false;
|
||||||
@ -193,10 +197,11 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
|
|||||||
if (_relayoutSubtreeRoot != this) {
|
if (_relayoutSubtreeRoot != this) {
|
||||||
_relayoutSubtreeRoot = null;
|
_relayoutSubtreeRoot = null;
|
||||||
_needsLayout = true;
|
_needsLayout = true;
|
||||||
_cleanRelayoutSubtreeRootChildren();
|
visitChildren((RenderObject child) {
|
||||||
|
child._cleanRelayoutSubtreeRoot();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void _cleanRelayoutSubtreeRootChildren() { } // workaround for lack of inter-class mixins in Dart
|
|
||||||
void scheduleInitialLayout() {
|
void scheduleInitialLayout() {
|
||||||
assert(attached);
|
assert(attached);
|
||||||
assert(parent == null);
|
assert(parent == null);
|
||||||
@ -541,9 +546,9 @@ abstract class RenderObjectWithChildMixin<ChildType extends RenderObject> implem
|
|||||||
if (_child != null)
|
if (_child != null)
|
||||||
_child.detach();
|
_child.detach();
|
||||||
}
|
}
|
||||||
void _cleanRelayoutSubtreeRootChildren() {
|
void visitChildren(RenderObjectVisitor visitor) {
|
||||||
if (_child != null)
|
if (_child != null)
|
||||||
_child._cleanRelayoutSubtreeRoot();
|
visitor(_child);
|
||||||
}
|
}
|
||||||
String debugDescribeChildren(String prefix) {
|
String debugDescribeChildren(String prefix) {
|
||||||
if (child != null)
|
if (child != null)
|
||||||
@ -734,10 +739,10 @@ abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, Parent
|
|||||||
child = child.parentData.nextSibling;
|
child = child.parentData.nextSibling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void _cleanRelayoutSubtreeRootChildren() {
|
void visitChildren(RenderObjectVisitor visitor) {
|
||||||
ChildType child = _firstChild;
|
ChildType child = _firstChild;
|
||||||
while (child != null) {
|
while (child != null) {
|
||||||
child._cleanRelayoutSubtreeRoot();
|
visitor(child);
|
||||||
assert(child.parentData is ParentDataType);
|
assert(child.parentData is ParentDataType);
|
||||||
child = child.parentData.nextSibling;
|
child = child.parentData.nextSibling;
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,14 @@ class RenderScaffold extends RenderBox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void visitChildren(RenderObjectVisitor visitor) {
|
||||||
|
for (ScaffoldSlots slot in ScaffoldSlots.values) {
|
||||||
|
RenderBox box = _slots[slot];
|
||||||
|
if (box != null)
|
||||||
|
visitor(box);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ScaffoldSlots remove(RenderBox child) {
|
ScaffoldSlots remove(RenderBox child) {
|
||||||
assert(child != null);
|
assert(child != null);
|
||||||
for (ScaffoldSlots slot in ScaffoldSlots.values) {
|
for (ScaffoldSlots slot in ScaffoldSlots.values) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user