mirror of
https://github.com/flutter/flutter.git
synced 2026-02-11 21:33:08 +08:00
Add the ability to draw borders on circles
We now support uniform borders on circular box decorations. Fixes #741
This commit is contained in:
parent
ac7c3a00fa
commit
e95aee2715
23
examples/widgets/big_circle.dart
Normal file
23
examples/widgets/big_circle.dart
Normal file
@ -0,0 +1,23 @@
|
||||
// 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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user