Commit 87e6a5cc authored by Adam Barth's avatar Adam Barth

Add more dartdoc for basic widgets

parent f92cd476
...@@ -23,7 +23,7 @@ abstract class MultiChildLayoutDelegate { ...@@ -23,7 +23,7 @@ abstract class MultiChildLayoutDelegate {
Map<Object, RenderBox> _idToChild; Map<Object, RenderBox> _idToChild;
Set<RenderBox> _debugChildrenNeedingLayout; Set<RenderBox> _debugChildrenNeedingLayout;
/// Returns the size of this object given the incomming constraints. /// Returns the size of this object given the incoming constraints.
/// The size cannot reflect the instrinsic sizes of the children. /// The size cannot reflect the instrinsic sizes of the children.
/// If this layout has a fixed width or height the returned size /// If this layout has a fixed width or height the returned size
/// can reflect that. /// can reflect that.
......
...@@ -164,13 +164,15 @@ class RenderConstrainedBox extends RenderProxyBox { ...@@ -164,13 +164,15 @@ class RenderConstrainedBox extends RenderProxyBox {
} }
} }
/// A render object that, for both width and height, imposes a tight constraint /// Sizes itself to a fraction of the total available space.
/// on its child that is a multiple (typically less than 1.0) of the maximum
/// constraint it received from its parent on that axis. If the factor for a
/// given axis is null, then the constraints from the parent are just passed
/// through instead.
/// ///
/// It then tries to size itself the size of its child. /// For both its width and width height, this render object imposes a tight
/// constraint on its child that is a multiple (typically less than 1.0) of the
/// maximum constraint it received from its parent on that axis. If the factor
/// for a given axis is null, then the constraints from the parent are just
/// passed through instead.
///
/// It then tries to size itself t the size of its child.
class RenderFractionallySizedBox extends RenderProxyBox { class RenderFractionallySizedBox extends RenderProxyBox {
RenderFractionallySizedBox({ RenderFractionallySizedBox({
RenderBox child, RenderBox child,
...@@ -181,9 +183,11 @@ class RenderFractionallySizedBox extends RenderProxyBox { ...@@ -181,9 +183,11 @@ class RenderFractionallySizedBox extends RenderProxyBox {
assert(_heightFactor == null || _heightFactor >= 0.0); assert(_heightFactor == null || _heightFactor >= 0.0);
} }
/// The multiple to apply to the incoming maximum width constraint to use as /// If non-null, the factor of the incoming width to use.
/// the tight width constraint for the child, or null to pass through the ///
/// constraints given by the parent. /// If non-null, the child is given a tight width constraint that is the max
/// incoming width constraint multipled by this factor. If null, the child is
/// given the incoming width constraings.
double get widthFactor => _widthFactor; double get widthFactor => _widthFactor;
double _widthFactor; double _widthFactor;
void set widthFactor (double value) { void set widthFactor (double value) {
...@@ -194,9 +198,11 @@ class RenderFractionallySizedBox extends RenderProxyBox { ...@@ -194,9 +198,11 @@ class RenderFractionallySizedBox extends RenderProxyBox {
markNeedsLayout(); markNeedsLayout();
} }
/// The multiple to apply to the incoming maximum height constraint to use as /// If non-null, the factor of the incoming height to use.
/// the tight height constraint for the child, or null to pass through the ///
/// constraints given by the parent. /// If non-null, the child is given a tight height constraint that is the max
/// incoming width constraint multipled by this factor. If null, the child is
/// given the incoming width constraings.
double get heightFactor => _heightFactor; double get heightFactor => _heightFactor;
double _heightFactor; double _heightFactor;
void set heightFactor (double value) { void set heightFactor (double value) {
......
...@@ -249,10 +249,10 @@ class RenderPositionedBox extends RenderShiftedBox { ...@@ -249,10 +249,10 @@ class RenderPositionedBox extends RenderShiftedBox {
/// A delegate for computing the layout of a render object with a single child. /// A delegate for computing the layout of a render object with a single child.
class OneChildLayoutDelegate { class OneChildLayoutDelegate {
/// Returns the size of this object given the incomming constraints. /// Returns the size of this object given the incoming constraints.
Size getSize(BoxConstraints constraints) => constraints.biggest; Size getSize(BoxConstraints constraints) => constraints.biggest;
/// Returns the box constraints for the child given the incomming constraints. /// Returns the box constraints for the child given the incoming constraints.
BoxConstraints getConstraintsForChild(BoxConstraints constraints) => constraints; BoxConstraints getConstraintsForChild(BoxConstraints constraints) => constraints;
/// Returns the position where the child should be placed given the size of this object and the size of the child. /// Returns the position where the child should be placed given the size of this object and the size of the child.
...@@ -325,6 +325,7 @@ class RenderCustomOneChildLayoutBox extends RenderShiftedBox { ...@@ -325,6 +325,7 @@ class RenderCustomOneChildLayoutBox extends RenderShiftedBox {
} }
} }
/// Positions its child vertically according to the child's baseline.
class RenderBaseline extends RenderShiftedBox { class RenderBaseline extends RenderShiftedBox {
RenderBaseline({ RenderBaseline({
...@@ -338,8 +339,10 @@ class RenderBaseline extends RenderShiftedBox { ...@@ -338,8 +339,10 @@ class RenderBaseline extends RenderShiftedBox {
assert(baselineType != null); assert(baselineType != null);
} }
double _baseline; /// The number of logical pixels from the top of this box at which to position
/// the child's baseline.
double get baseline => _baseline; double get baseline => _baseline;
double _baseline;
void set baseline (double value) { void set baseline (double value) {
assert(value != null); assert(value != null);
if (_baseline == value) if (_baseline == value)
...@@ -348,8 +351,9 @@ class RenderBaseline extends RenderShiftedBox { ...@@ -348,8 +351,9 @@ class RenderBaseline extends RenderShiftedBox {
markNeedsLayout(); markNeedsLayout();
} }
TextBaseline _baselineType; /// The type of baseline to use for positioning the child.
TextBaseline get baselineType => _baselineType; TextBaseline get baselineType => _baselineType;
TextBaseline _baselineType;
void set baselineType (TextBaseline value) { void set baselineType (TextBaseline value) {
assert(value != null); assert(value != null);
if (_baselineType == value) if (_baselineType == value)
......
...@@ -126,7 +126,9 @@ class ShaderMask extends OneChildRenderObjectWidget { ...@@ -126,7 +126,9 @@ class ShaderMask extends OneChildRenderObjectWidget {
} }
} }
/// Paints a [BoxDecoration] either before or after its child paints. /// Paints a [Decoration] either before or after its child paints.
///
/// Commonly used with [BoxDecoration].
class DecoratedBox extends OneChildRenderObjectWidget { class DecoratedBox extends OneChildRenderObjectWidget {
DecoratedBox({ DecoratedBox({
Key key, Key key,
...@@ -139,6 +141,8 @@ class DecoratedBox extends OneChildRenderObjectWidget { ...@@ -139,6 +141,8 @@ class DecoratedBox extends OneChildRenderObjectWidget {
} }
/// What decoration to paint. /// What decoration to paint.
///
/// Commonly a [BoxDecoration].
final Decoration decoration; final Decoration decoration;
/// Where to paint the box decoration. /// Where to paint the box decoration.
...@@ -541,11 +545,23 @@ class ConstrainedBox extends OneChildRenderObjectWidget { ...@@ -541,11 +545,23 @@ class ConstrainedBox extends OneChildRenderObjectWidget {
} }
} }
/// Sizes itself to a fraction of the total available space.
///
/// See [RenderFractionallySizedBox] for details.
class FractionallySizedBox extends OneChildRenderObjectWidget { class FractionallySizedBox extends OneChildRenderObjectWidget {
FractionallySizedBox({ Key key, this.width, this.height, Widget child }) FractionallySizedBox({ Key key, this.width, this.height, Widget child })
: super(key: key, child: child); : super(key: key, child: child);
/// If non-null, the factor of the incoming width to use.
///
/// If non-null, the child is given a tight width constraint that is the max
/// incoming width constraint multipled by this factor.
final double width; final double width;
/// If non-null, the factor of the incoming height to use.
///
/// If non-null, the child is given a tight height constraint that is the max
/// incoming height constraint multipled by this factor.
final double height; final double height;
RenderFractionallySizedBox createRenderObject() => new RenderFractionallySizedBox( RenderFractionallySizedBox createRenderObject() => new RenderFractionallySizedBox(
...@@ -567,13 +583,28 @@ class FractionallySizedBox extends OneChildRenderObjectWidget { ...@@ -567,13 +583,28 @@ class FractionallySizedBox extends OneChildRenderObjectWidget {
} }
} }
/// A render object that imposes different constraints on its child than it gets
/// from its parent, possibly allowing the child to overflow the parent.
///
/// See [RenderOverflowBox] for details.
class OverflowBox extends OneChildRenderObjectWidget { class OverflowBox extends OneChildRenderObjectWidget {
OverflowBox({ Key key, this.minWidth, this.maxWidth, this.minHeight, this.maxHeight, Widget child }) OverflowBox({ Key key, this.minWidth, this.maxWidth, this.minHeight, this.maxHeight, Widget child })
: super(key: key, child: child); : super(key: key, child: child);
/// The minimum width constraint to give the child. Set this to null (the
/// default) to use the constraint from the parent instead.
final double minWidth; final double minWidth;
/// The maximum width constraint to give the child. Set this to null (the
/// default) to use the constraint from the parent instead.
final double maxWidth; final double maxWidth;
/// The minimum height constraint to give the child. Set this to null (the
/// default) to use the constraint from the parent instead.
final double minHeight; final double minHeight;
/// The maximum height constraint to give the child. Set this to null (the
/// default) to use the constraint from the parent instead.
final double maxHeight; final double maxHeight;
RenderOverflowBox createRenderObject() => new RenderOverflowBox( RenderOverflowBox createRenderObject() => new RenderOverflowBox(
...@@ -614,12 +645,19 @@ class OffStage extends OneChildRenderObjectWidget { ...@@ -614,12 +645,19 @@ class OffStage extends OneChildRenderObjectWidget {
RenderOffStage createRenderObject() => new RenderOffStage(); RenderOffStage createRenderObject() => new RenderOffStage();
} }
/// Forces child to layout at a specific aspect ratio.
///
/// See [RenderAspectRatio] for details.
class AspectRatio extends OneChildRenderObjectWidget { class AspectRatio extends OneChildRenderObjectWidget {
AspectRatio({ Key key, this.aspectRatio, Widget child }) AspectRatio({ Key key, this.aspectRatio, Widget child })
: super(key: key, child: child) { : super(key: key, child: child) {
assert(aspectRatio != null); assert(aspectRatio != null);
} }
/// The aspect ratio to use when computing the height from the width.
///
/// The aspect ratio is expressed as a ratio of width to height. For example,
/// a 16:9 width:height aspect ratio would have a value of 16.0/9.0.
final double aspectRatio; final double aspectRatio;
RenderAspectRatio createRenderObject() => new RenderAspectRatio(aspectRatio: aspectRatio); RenderAspectRatio createRenderObject() => new RenderAspectRatio(aspectRatio: aspectRatio);
...@@ -676,6 +714,7 @@ class IntrinsicHeight extends OneChildRenderObjectWidget { ...@@ -676,6 +714,7 @@ class IntrinsicHeight extends OneChildRenderObjectWidget {
RenderIntrinsicHeight createRenderObject() => new RenderIntrinsicHeight(); RenderIntrinsicHeight createRenderObject() => new RenderIntrinsicHeight();
} }
/// Positions its child vertically according to the child's baseline.
class Baseline extends OneChildRenderObjectWidget { class Baseline extends OneChildRenderObjectWidget {
Baseline({ Key key, this.baseline, this.baselineType: TextBaseline.alphabetic, Widget child }) Baseline({ Key key, this.baseline, this.baselineType: TextBaseline.alphabetic, Widget child })
: super(key: key, child: child) { : super(key: key, child: child) {
...@@ -683,7 +722,11 @@ class Baseline extends OneChildRenderObjectWidget { ...@@ -683,7 +722,11 @@ class Baseline extends OneChildRenderObjectWidget {
assert(baselineType != null); assert(baselineType != null);
} }
final double baseline; // in pixels /// The number of logical pixels from the top of this box at which to position
/// the child's baseline.
final double baseline;
/// The type of baseline to use for positioning the child.
final TextBaseline baselineType; final TextBaseline baselineType;
RenderBaseline createRenderObject() => new RenderBaseline(baseline: baseline, baselineType: baselineType); RenderBaseline createRenderObject() => new RenderBaseline(baseline: baseline, baselineType: baselineType);
...@@ -760,10 +803,10 @@ class SizeObserver extends OneChildRenderObjectWidget { ...@@ -760,10 +803,10 @@ class SizeObserver extends OneChildRenderObjectWidget {
} }
// CONVENIENCE CLASS TO COMBINE COMMON PAINTING, POSITIONING, AND SIZING NODES // CONTAINER
/// A convenience widget that combines common painting, positioning, and sizing widgets.
class Container extends StatelessComponent { class Container extends StatelessComponent {
Container({ Container({
Key key, Key key,
this.child, this.child,
...@@ -879,12 +922,17 @@ class Container extends StatelessComponent { ...@@ -879,12 +922,17 @@ class Container extends StatelessComponent {
if (height != null) if (height != null)
description.add('height: $height'); description.add('height: $height');
} }
} }
// LAYOUT NODES // LAYOUT NODES
/// Uses the block layout algorithm for its children.
///
/// This widget is rarely used directly. Instead, consider using [Block], which
/// combines the block layout algorithm with scrolling behavior.
///
/// For details about the block layout algorithm, see [RenderBlockBase].
class BlockBody extends MultiChildRenderObjectWidget { class BlockBody extends MultiChildRenderObjectWidget {
BlockBody(List<Widget> children, { BlockBody(List<Widget> children, {
Key key, Key key,
...@@ -893,6 +941,7 @@ class BlockBody extends MultiChildRenderObjectWidget { ...@@ -893,6 +941,7 @@ class BlockBody extends MultiChildRenderObjectWidget {
assert(direction != null); assert(direction != null);
} }
/// The direction to use as the main axis.
final BlockDirection direction; final BlockDirection direction;
RenderBlock createRenderObject() => new RenderBlock(direction: direction); RenderBlock createRenderObject() => new RenderBlock(direction: direction);
...@@ -1183,8 +1232,12 @@ class Flexible extends ParentDataWidget { ...@@ -1183,8 +1232,12 @@ class Flexible extends ParentDataWidget {
} }
} }
class Paragraph extends LeafRenderObjectWidget { /// A raw paragraph of text.
Paragraph({ Key key, this.text }) : super(key: key) { ///
/// This class is rarely used directly. Instead, consider using [Text], which
/// integrates with [DefaultTextStyle].
class RawText extends LeafRenderObjectWidget {
RawText({ Key key, this.text }) : super(key: key) {
assert(text != null); assert(text != null);
} }
...@@ -1192,19 +1245,26 @@ class Paragraph extends LeafRenderObjectWidget { ...@@ -1192,19 +1245,26 @@ class Paragraph extends LeafRenderObjectWidget {
RenderParagraph createRenderObject() => new RenderParagraph(text); RenderParagraph createRenderObject() => new RenderParagraph(text);
void updateRenderObject(RenderParagraph renderObject, Paragraph oldWidget) { void updateRenderObject(RenderParagraph renderObject, RawText oldWidget) {
renderObject.text = text; renderObject.text = text;
} }
} }
/// A convience widget for paragraphs of text with heterogeneous style.
///
/// The elements paramter is a recusrive list of lists that matches the
/// following grammar:
///
/// `elements ::= "string" | [<text-style> <elements>*]``
///
/// Where "string" is text to display and text-style is an instance of
/// TextStyle. The text-style applies to all of the elements that follow.
class StyledText extends StatelessComponent { class StyledText extends StatelessComponent {
// elements ::= "string" | [<text-style> <elements>*]
// Where "string" is text to display and text-style is an instance of
// TextStyle. The text-style applies to all of the elements that follow.
StyledText({ this.elements, Key key }) : super(key: key) { StyledText({ this.elements, Key key }) : super(key: key) {
assert(_toSpan(elements) != null); assert(_toSpan(elements) != null);
} }
/// The recursive list of lists that describes the text and style to paint.
final dynamic elements; final dynamic elements;
TextSpan _toSpan(dynamic element) { TextSpan _toSpan(dynamic element) {
...@@ -1220,10 +1280,11 @@ class StyledText extends StatelessComponent { ...@@ -1220,10 +1280,11 @@ class StyledText extends StatelessComponent {
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Paragraph(text: _toSpan(elements)); return new RawText(text: _toSpan(elements));
} }
} }
/// The text style to apply to descendant [Text] widgets without explicit style.
class DefaultTextStyle extends InheritedWidget { class DefaultTextStyle extends InheritedWidget {
DefaultTextStyle({ DefaultTextStyle({
Key key, Key key,
...@@ -1234,8 +1295,10 @@ class DefaultTextStyle extends InheritedWidget { ...@@ -1234,8 +1295,10 @@ class DefaultTextStyle extends InheritedWidget {
assert(child != null); assert(child != null);
} }
/// The text style to apply.
final TextStyle style; final TextStyle style;
/// The closest instance of this class that encloses the given context.
static TextStyle of(BuildContext context) { static TextStyle of(BuildContext context) {
DefaultTextStyle result = context.inheritFromWidgetOfType(DefaultTextStyle); DefaultTextStyle result = context.inheritFromWidgetOfType(DefaultTextStyle);
return result?.style; return result?.style;
...@@ -1249,12 +1312,23 @@ class DefaultTextStyle extends InheritedWidget { ...@@ -1249,12 +1312,23 @@ class DefaultTextStyle extends InheritedWidget {
} }
} }
/// A run of text.
///
/// By default, the text will be styled using the closest enclosing
/// [DefaultTextStyle].
class Text extends StatelessComponent { class Text extends StatelessComponent {
Text(this.data, { Key key, this.style }) : super(key: key) { Text(this.data, { Key key, this.style }) : super(key: key) {
assert(data != null); assert(data != null);
} }
/// The text to display.
final String data; final String data;
/// If non-null, the style to use for this text.
///
/// If the style's "inherit" property is true, the style will be merged with
/// the closest enclosing [DefaultTextStyle]. Otherwise, the style will
/// replace the closest enclosing [DefaultTextStyle].
final TextStyle style; final TextStyle style;
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -1267,7 +1341,7 @@ class Text extends StatelessComponent { ...@@ -1267,7 +1341,7 @@ class Text extends StatelessComponent {
} }
if (combinedStyle != null) if (combinedStyle != null)
text = new StyledTextSpan(combinedStyle, <TextSpan>[text]); text = new StyledTextSpan(combinedStyle, <TextSpan>[text]);
return new Paragraph(text: text); return new RawText(text: text);
} }
void debugFillDescription(List<String> description) { void debugFillDescription(List<String> description) {
......
...@@ -14,7 +14,11 @@ import 'framework.dart'; ...@@ -14,7 +14,11 @@ import 'framework.dart';
import 'homogeneous_viewport.dart'; import 'homogeneous_viewport.dart';
import 'scrollable.dart'; import 'scrollable.dart';
enum ItemsSnapAlignment { item, adjacentItem } /// Controls what alignment items use when settling.
enum ItemsSnapAlignment {
item,
adjacentItem
}
typedef void PageChangedCallback(int newPage); typedef void PageChangedCallback(int newPage);
......
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