From 650c4a64f5e8b604fd7e3df089e7c4d46f5a8a12 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 28 Aug 2015 20:58:34 -0700 Subject: [PATCH] BoxDecoration's borderRadius should be able to handle a value of double.INIFINITY We just need to enforce some finite clamp and Skia will do the rest. Fixes #939 --- packages/flutter/lib/painting/box_painter.dart | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/painting/box_painter.dart b/packages/flutter/lib/painting/box_painter.dart index cb44b484c0b..bfe73e895b9 100644 --- a/packages/flutter/lib/painting/box_painter.dart +++ b/packages/flutter/lib/painting/box_painter.dart @@ -474,6 +474,14 @@ class BoxPainter { return hasUniformWidth; } + 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 sky.Canvas do any remaning clamping. + return _decoration.borderRadius > shortestSide ? shortestSide : _decoration.borderRadius; + } + void _paintBackgroundColor(sky.Canvas canvas, Rect rect) { if (_decoration.backgroundColor != null || _decoration.boxShadow != null || @@ -486,10 +494,12 @@ class BoxPainter { canvas.drawCircle(center, radius, _backgroundPaint); break; case Shape.rectangle: - if (_decoration.borderRadius == null) + if (_decoration.borderRadius == null) { canvas.drawRect(rect, _backgroundPaint); - else - canvas.drawRRect(new sky.RRect()..setRectXY(rect, _decoration.borderRadius, _decoration.borderRadius), _backgroundPaint); + } else { + double radius = _getEffectiveBorderRadius(rect); + canvas.drawRRect(new sky.RRect()..setRectXY(rect, radius, radius), _backgroundPaint); + } break; } } @@ -580,7 +590,7 @@ class BoxPainter { assert(_decoration.shape == Shape.rectangle); Color color = _decoration.border.top.color; double width = _decoration.border.top.width; - double radius = _decoration.borderRadius; + double radius = _getEffectiveBorderRadius(rect); sky.RRect outer = new sky.RRect()..setRectXY(rect, radius, radius); sky.RRect inner = new sky.RRect()..setRectXY(rect.deflate(width), radius - width, radius - width);