From a54ee77b88863cb957e78993c1fa0d8d4a32f110 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Mon, 11 Jan 2016 23:20:50 -0800 Subject: [PATCH] Tweaks near Material, BoxDecoration, implicit animations. Some more asserts and toString info. Reorder some code to group lerp-related functions. --- .../flutter/lib/src/material/material.dart | 9 ++++ .../flutter/lib/src/painting/box_painter.dart | 52 +++++++++---------- .../lib/src/widgets/implicit_animations.dart | 25 +++++++++ 3 files changed, 60 insertions(+), 26 deletions(-) diff --git a/packages/flutter/lib/src/material/material.dart b/packages/flutter/lib/src/material/material.dart index 6c470fcfb5..056720580a 100644 --- a/packages/flutter/lib/src/material/material.dart +++ b/packages/flutter/lib/src/material/material.dart @@ -84,6 +84,7 @@ class Material extends StatefulComponent { this.color, this.textStyle }) : super(key: key) { + assert(type != null); assert(elevation != null); } @@ -100,6 +101,14 @@ class Material extends StatefulComponent { } _MaterialState createState() => new _MaterialState(); + + void debugFillDescription(List description) { + super.debugFillDescription(description); + description.add('$type'); + description.add('elevation: $elevation'); + if (color != null) + description.add('color: $color'); + } } class _MaterialState extends State { diff --git a/packages/flutter/lib/src/painting/box_painter.dart b/packages/flutter/lib/src/painting/box_painter.dart index bc05ca89d0..3a028b3e49 100644 --- a/packages/flutter/lib/src/painting/box_painter.dart +++ b/packages/flutter/lib/src/painting/box_painter.dart @@ -726,32 +726,6 @@ class BoxDecoration extends Decoration { ); } - double getEffectiveBorderRadius(Rect rect) { - double shortestSide = rect.shortestSide; - // In principle, we should use shortestSide / 2.0, but we don't want to - // run into floating point rounding errors. Instead, we just use - // shortestSide and let ui.Canvas do any remaining clamping. - return borderRadius > shortestSide ? shortestSide : borderRadius; - } - - bool hitTest(Size size, Point position) { - assert(shape != null); - assert((Point.origin & size).contains(position)); - switch (shape) { - case BoxShape.rectangle: - if (borderRadius != null) { - ui.RRect bounds = new ui.RRect.fromRectXY(Point.origin & size, borderRadius, borderRadius); - return bounds.contains(position); - } - return true; - case BoxShape.circle: - // Circles are inscribed into our smallest dimension. - Point center = size.center(Point.origin); - double distance = (position - center).distance; - return distance <= math.min(size.width, size.height) / 2.0; - } - } - /// Linearly interpolate between two box decorations. /// /// Interpolates each parameter of the box decoration separately. @@ -843,6 +817,32 @@ class BoxDecoration extends Decoration { backgroundImage?._removeChangeListener(listener); } + double getEffectiveBorderRadius(Rect rect) { + double shortestSide = rect.shortestSide; + // In principle, we should use shortestSide / 2.0, but we don't want to + // run into floating point rounding errors. Instead, we just use + // shortestSide and let ui.Canvas do any remaining clamping. + return borderRadius > shortestSide ? shortestSide : borderRadius; + } + + bool hitTest(Size size, Point position) { + assert(shape != null); + assert((Point.origin & size).contains(position)); + switch (shape) { + case BoxShape.rectangle: + if (borderRadius != null) { + ui.RRect bounds = new ui.RRect.fromRectXY(Point.origin & size, borderRadius, borderRadius); + return bounds.contains(position); + } + return true; + case BoxShape.circle: + // Circles are inscribed into our smallest dimension. + Point center = size.center(Point.origin); + double distance = (position - center).distance; + return distance <= math.min(size.width, size.height) / 2.0; + } + } + _BoxDecorationPainter createBoxPainter() => new _BoxDecorationPainter(this); } diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index c8e3df2c4e..0973cc8271 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -75,6 +75,11 @@ abstract class AnimatedWidgetBase extends StatefulComponent { final Duration duration; AnimatedWidgetBaseState createState(); + + void debugFillDescription(List description) { + super.debugFillDescription(description); + description.add('duration: ${duration.inMilliseconds}ms'); + } } typedef AnimatedValue VariableConstructor(T targetValue); @@ -232,6 +237,26 @@ class AnimatedContainer extends AnimatedWidgetBase { final double height; _AnimatedContainerState createState() => new _AnimatedContainerState(); + + void debugFillDescription(List description) { + super.debugFillDescription(description); + if (constraints != null) + description.add('$constraints'); + if (decoration != null) + description.add('has background'); + if (foregroundDecoration != null) + description.add('has foreground'); + if (margin != null) + description.add('margin: $margin'); + if (padding != null) + description.add('padding: $padding'); + if (transform != null) + description.add('has transform'); + if (width != null) + description.add('width: $width'); + if (height != null) + description.add('height: $height'); + } } class _AnimatedContainerState extends AnimatedWidgetBaseState {