Commit cbb495c1 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Add more dartdocs for the sliver render objects (#8749)

This patch covers multi-box adaptor and the viewports.
parent cb2b89c3
...@@ -1225,9 +1225,9 @@ abstract class RenderSliverHelpers implements RenderSliver { ...@@ -1225,9 +1225,9 @@ abstract class RenderSliverHelpers implements RenderSliver {
/// ///
/// See also: /// See also:
/// ///
/// - [RenderSliver], which explains more about the Sliver protocol. /// * [RenderSliver], which explains more about the Sliver protocol.
/// - [RenderBox], which explains more about the Box protocol. /// * [RenderBox], which explains more about the Box protocol.
/// - [RenderViewport], which allows [RenderSliver] objects to be placed inside /// * [RenderViewport], which allows [RenderSliver] objects to be placed inside
/// a [RenderBox] (the opposite of this class). /// a [RenderBox] (the opposite of this class).
class RenderSliverToBoxAdapter extends RenderSliver with RenderObjectWithChildMixin<RenderBox>, RenderSliverHelpers { class RenderSliverToBoxAdapter extends RenderSliver with RenderObjectWithChildMixin<RenderBox>, RenderSliverHelpers {
/// Creates a [RenderSliver] that wraps a [RenderBox]. /// Creates a [RenderSliver] that wraps a [RenderBox].
......
...@@ -75,6 +75,17 @@ abstract class RenderSliverBoxChildManager { ...@@ -75,6 +75,17 @@ abstract class RenderSliverBoxChildManager {
/// the child list after this function returns. /// the child list after this function returns.
void didAdoptChild(RenderBox child); void didAdoptChild(RenderBox child);
/// Called during layout to indicate whether this object provided insufficient
/// children for the [RenderSliverMultiBoxAdaptor] to fill the
/// [SliverConstraints.remainingPaintExtent].
///
/// Typically called unconditionally at the start of layout with false and
/// then later called with true when the [RenderSliverMultiBoxAdaptor]
/// fails to create a child required to fill the
/// [SliverConstraints.remainingPaintExtent].
///
/// Useful for subclasses to determine whether newly added children could
/// affect the visible contents of the [RenderSliverMultiBoxAdaptor].
void setDidUnderflow(bool value); void setDidUnderflow(bool value);
/// In debug mode, asserts that this manager is not expecting any /// In debug mode, asserts that this manager is not expecting any
...@@ -88,25 +99,47 @@ abstract class RenderSliverBoxChildManager { ...@@ -88,25 +99,47 @@ abstract class RenderSliverBoxChildManager {
bool debugAssertChildListLocked() => true; bool debugAssertChildListLocked() => true;
} }
/// Parent data structure used by [RenderSliverMultiBoxAdaptor].
class SliverMultiBoxAdaptorParentData extends SliverLogicalParentData with ContainerParentDataMixin<RenderBox> { class SliverMultiBoxAdaptorParentData extends SliverLogicalParentData with ContainerParentDataMixin<RenderBox> {
/// The index of this child according to the [RenderSliverBoxChildManager].
int index; int index;
@override @override
String toString() => 'index=$index; ${super.toString()}'; String toString() => 'index=$index; ${super.toString()}';
} }
// /// The contract for adding and removing children from this render object is /// A sliver with multiple box children.
// /// more strict than for normal render objects: ///
// /// /// [RenderSliverMultiBoxAdaptor] is a base class for slivers that have multiple
// /// - Children can be removed except during a layout pass if they have already /// box children. The children are managed by a [RenderSliverBoxChildManager],
// /// been laid out during that layout pass. /// which lets subclasses create children lazily during layout. Typically
// /// - Children cannot be added except during a call to [childManager], and /// subclasses will create only those children that are actually needed to fill
// /// then only if there is no child correspending to that index (or the child /// the [SliverConstraints.remainingPaintExtent].
// /// child corresponding to that index was first removed). ///
/// The contract for adding and removing children from this render object is
/// more strict than for normal render objects:
///
/// * Children can be removed except during a layout pass if they have already
/// been laid out during that layout pass.
/// * Children cannot be added except during a call to [childManager], and
/// then only if there is no child correspending to that index (or the child
/// child corresponding to that index was first removed).
///
/// See also:
///
/// * [RenderSliverToBoxAdapter], which has a single box child.
/// * [RenderSliverList], which places its children in a linear
/// array.
/// * [RenderSliverFixedExtentList], which places its children in a linear
/// array with a fixed extent in the main axis.
/// * [RenderSliverGrid], which places its children in arbitrary positions.
abstract class RenderSliverMultiBoxAdaptor extends RenderSliver abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
with ContainerRenderObjectMixin<RenderBox, SliverMultiBoxAdaptorParentData>, with ContainerRenderObjectMixin<RenderBox, SliverMultiBoxAdaptorParentData>,
RenderSliverHelpers { RenderSliverHelpers {
/// Creates a sliver with multiple box children.
///
/// The [childManager] argument must not be null.
RenderSliverMultiBoxAdaptor({ RenderSliverMultiBoxAdaptor({
@required RenderSliverBoxChildManager childManager @required RenderSliverBoxChildManager childManager
}) : _childManager = childManager { }) : _childManager = childManager {
...@@ -119,6 +152,12 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver ...@@ -119,6 +152,12 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
child.parentData = new SliverMultiBoxAdaptorParentData(); child.parentData = new SliverMultiBoxAdaptorParentData();
} }
/// The delegate that manages the children of this object.
///
/// Rather than having a concrete list of children, a
/// [RenderSliverMultiBoxAdaptor] uses a [RenderSliverBoxChildManager] to
/// create children during layout in order to fill the
/// [SliverConstraints.remainingPaintExtent].
@protected @protected
RenderSliverBoxChildManager get childManager => _childManager; RenderSliverBoxChildManager get childManager => _childManager;
final RenderSliverBoxChildManager _childManager; final RenderSliverBoxChildManager _childManager;
...@@ -379,6 +418,10 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver ...@@ -379,6 +418,10 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
} }
} }
/// Asserts that the reified child list is not empty and has a contiguous
/// sequence of indices.
///
/// Always returns true.
bool debugAssertChildListIsNonEmptyAndContiguous() { bool debugAssertChildListIsNonEmptyAndContiguous() {
assert(() { assert(() {
assert(firstChild != null); assert(firstChild != null);
......
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