Commit aa87ab6f authored by Ian Hickson's avatar Ian Hickson

Merge pull request #1238 from Hixie/material-tweaks

Tweaks near Material, BoxDecoration, implicit animations.
parents 4507a7fa a54ee77b
......@@ -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<String> description) {
super.debugFillDescription(description);
description.add('$type');
description.add('elevation: $elevation');
if (color != null)
description.add('color: $color');
}
}
class _MaterialState extends State<Material> {
......
......@@ -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);
}
......
......@@ -75,6 +75,11 @@ abstract class AnimatedWidgetBase extends StatefulComponent {
final Duration duration;
AnimatedWidgetBaseState createState();
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
description.add('duration: ${duration.inMilliseconds}ms');
}
}
typedef AnimatedValue<T> VariableConstructor<T>(T targetValue);
......@@ -232,6 +237,26 @@ class AnimatedContainer extends AnimatedWidgetBase {
final double height;
_AnimatedContainerState createState() => new _AnimatedContainerState();
void debugFillDescription(List<String> 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<AnimatedContainer> {
......
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