Commit e95aee27 authored by Adam Barth's avatar Adam Barth

Add the ability to draw borders on circles

We now support uniform borders on circular box decorations.

Fixes #741
parent ac7c3a00
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/widgets.dart';
import 'package:sky/theme/colors.dart' as colors;
class BigCircleApp extends App {
Widget build() {
return new Container(
padding: new EdgeDims.all(50.0),
decoration: new BoxDecoration(
shape: Shape.circle,
border: new Border.all(width: 10.0, color: const Color(0x80FF00FF)),
backgroundColor: colors.Teal[600]
)
);
}
}
void main() {
runApp(new BigCircleApp());
}
......@@ -516,9 +516,15 @@ class BoxPainter {
if (_decoration.border == null)
return;
if (_hasUniformBorder && _decoration.borderRadius != null) {
_paintBorderWithRadius(canvas, rect);
return;
if (_hasUniformBorder) {
if (_decoration.borderRadius != null) {
_paintBorderWithRadius(canvas, rect);
return;
}
if (_decoration.shape == Shape.circle) {
_paintBorderWithCircle(canvas, rect);
return;
}
}
assert(_decoration.borderRadius == null); // TODO(abarth): Support non-uniform rounded borders.
......@@ -571,6 +577,7 @@ class BoxPainter {
void _paintBorderWithRadius(sky.Canvas canvas, Rect rect) {
assert(_hasUniformBorder);
assert(_decoration.shape == Shape.rectangle);
Color color = _decoration.border.top.color;
double width = _decoration.border.top.width;
double radius = _decoration.borderRadius;
......@@ -580,6 +587,20 @@ class BoxPainter {
canvas.drawDRRect(outer, inner, new Paint()..color = color);
}
void _paintBorderWithCircle(sky.Canvas canvas, Rect rect) {
assert(_hasUniformBorder);
assert(_decoration.shape == Shape.circle);
assert(_decoration.borderRadius == null);
double width = _decoration.border.top.width;
Paint paint = new Paint()
..color = _decoration.border.top.color
..strokeWidth = width
..setStyle(sky.PaintingStyle.stroke);
Point center = rect.center;
double radius = (rect.shortestSide - width) / 2.0;
canvas.drawCircle(center, radius, paint);
}
void paint(sky.Canvas canvas, Rect rect) {
_paintBackgroundColor(canvas, rect);
_paintBackgroundImage(canvas, rect);
......
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