Unverified Commit e100ddfe authored by xster's avatar xster Committed by GitHub

Rename SuperellipseShare ContinuousRectangleBorder (#28183)

parent 39b1ff1a
316817d949c1f7051e8a4898486ae7643ce31167 8587c2409ec1b674a7d451c8bcd8d37ed5175fdc
...@@ -32,6 +32,7 @@ export 'src/painting/box_shadow.dart'; ...@@ -32,6 +32,7 @@ export 'src/painting/box_shadow.dart';
export 'src/painting/circle_border.dart'; export 'src/painting/circle_border.dart';
export 'src/painting/clip.dart'; export 'src/painting/clip.dart';
export 'src/painting/colors.dart'; export 'src/painting/colors.dart';
export 'src/painting/continuous_rectangle_border.dart';
export 'src/painting/debug.dart'; export 'src/painting/debug.dart';
export 'src/painting/decoration.dart'; export 'src/painting/decoration.dart';
export 'src/painting/decoration_image.dart'; export 'src/painting/decoration_image.dart';
...@@ -52,7 +53,6 @@ export 'src/painting/rounded_rectangle_border.dart'; ...@@ -52,7 +53,6 @@ export 'src/painting/rounded_rectangle_border.dart';
export 'src/painting/shape_decoration.dart'; export 'src/painting/shape_decoration.dart';
export 'src/painting/stadium_border.dart'; export 'src/painting/stadium_border.dart';
export 'src/painting/strut_style.dart'; export 'src/painting/strut_style.dart';
export 'src/painting/superellipse_shape.dart';
export 'src/painting/text_painter.dart'; export 'src/painting/text_painter.dart';
export 'src/painting/text_span.dart'; export 'src/painting/text_span.dart';
export 'src/painting/text_style.dart'; export 'src/painting/text_style.dart';
...@@ -265,8 +265,9 @@ class BorderSide { ...@@ -265,8 +265,9 @@ class BorderSide {
/// ///
/// This class handles how to add multiple borders together. Subclasses define /// This class handles how to add multiple borders together. Subclasses define
/// various shapes, like circles ([CircleBorder]), rounded rectangles /// various shapes, like circles ([CircleBorder]), rounded rectangles
/// ([RoundedRectangleBorder]), superellipses ([SuperellipseShape]), or beveled /// ([RoundedRectangleBorder]), continuous rectangles
/// rectangles ([BeveledRectangleBorder]). /// ([ContinuousRectangleBorder]), or beveled rectangles
/// ([BeveledRectangleBorder]).
/// ///
/// See also: /// See also:
/// ///
......
...@@ -9,15 +9,14 @@ import 'border_radius.dart'; ...@@ -9,15 +9,14 @@ import 'border_radius.dart';
import 'borders.dart'; import 'borders.dart';
import 'edge_insets.dart'; import 'edge_insets.dart';
/// Creates a superellipse - a shape similar to a rounded rectangle, but with /// A rectangular border with smooth continuous transitions between the straight
/// a smoother transition from the sides to the rounded corners and greater /// sides and the rounded corners.
/// curve continuity.
/// ///
/// {@tool sample} /// {@tool sample}
/// ```dart /// ```dart
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
/// return Material( /// return Material(
/// shape: SuperellipseShape( /// shape: ContinuousRectangleBorder(
/// borderRadius: BorderRadius.circular(28.0), /// borderRadius: BorderRadius.circular(28.0),
/// ), /// ),
/// ); /// );
...@@ -27,12 +26,13 @@ import 'edge_insets.dart'; ...@@ -27,12 +26,13 @@ import 'edge_insets.dart';
/// ///
/// See also: /// See also:
/// ///
/// * [RoundedRectangleBorder] Which creates a square with rounded corners, /// * [RoundedRectangleBorder] Which creates rectangles with rounded corners,
/// however it doesn't allow the corners to bend the sides of the square /// however its straight sides change into a rounded corner with a circular
/// like a superellipse, resulting in a more square shape. /// radius in a step function instead of gradually like the
class SuperellipseShape extends ShapeBorder { /// [ContinuousRectangleBorder].
class ContinuousRectangleBorder extends ShapeBorder {
/// The arguments must not be null. /// The arguments must not be null.
const SuperellipseShape({ const ContinuousRectangleBorder({
this.side = BorderSide.none, this.side = BorderSide.none,
this.borderRadius = BorderRadius.zero, this.borderRadius = BorderRadius.zero,
}) : assert(side != null), }) : assert(side != null),
...@@ -52,7 +52,7 @@ class SuperellipseShape extends ShapeBorder { ...@@ -52,7 +52,7 @@ class SuperellipseShape extends ShapeBorder {
@override @override
ShapeBorder scale(double t) { ShapeBorder scale(double t) {
return SuperellipseShape( return ContinuousRectangleBorder(
side: side.scale(t), side: side.scale(t),
borderRadius: borderRadius * t, borderRadius: borderRadius * t,
); );
...@@ -61,8 +61,8 @@ class SuperellipseShape extends ShapeBorder { ...@@ -61,8 +61,8 @@ class SuperellipseShape extends ShapeBorder {
@override @override
ShapeBorder lerpFrom(ShapeBorder a, double t) { ShapeBorder lerpFrom(ShapeBorder a, double t) {
assert(t != null); assert(t != null);
if (a is SuperellipseShape) { if (a is ContinuousRectangleBorder) {
return SuperellipseShape( return ContinuousRectangleBorder(
side: BorderSide.lerp(a.side, side, t), side: BorderSide.lerp(a.side, side, t),
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t), borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t),
); );
...@@ -73,8 +73,8 @@ class SuperellipseShape extends ShapeBorder { ...@@ -73,8 +73,8 @@ class SuperellipseShape extends ShapeBorder {
@override @override
ShapeBorder lerpTo(ShapeBorder b, double t) { ShapeBorder lerpTo(ShapeBorder b, double t) {
assert(t != null); assert(t != null);
if (b is SuperellipseShape) { if (b is ContinuousRectangleBorder) {
return SuperellipseShape( return ContinuousRectangleBorder(
side: BorderSide.lerp(side, b.side, t), side: BorderSide.lerp(side, b.side, t),
borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t), borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t),
); );
...@@ -151,7 +151,7 @@ class SuperellipseShape extends ShapeBorder { ...@@ -151,7 +151,7 @@ class SuperellipseShape extends ShapeBorder {
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
if (runtimeType != other.runtimeType) if (runtimeType != other.runtimeType)
return false; return false;
final SuperellipseShape typedOther = other; final ContinuousRectangleBorder typedOther = other;
return side == typedOther.side return side == typedOther.side
&& borderRadius == typedOther.borderRadius; && borderRadius == typedOther.borderRadius;
} }
......
...@@ -56,7 +56,7 @@ void main() { ...@@ -56,7 +56,7 @@ void main() {
bottomNavigationBar: BottomAppBar( bottomNavigationBar: BottomAppBar(
shape: AutomaticNotchedShape( shape: AutomaticNotchedShape(
BeveledRectangleBorder(borderRadius: BorderRadius.circular(50.0)), BeveledRectangleBorder(borderRadius: BorderRadius.circular(50.0)),
SuperellipseShape(borderRadius: BorderRadius.circular(30.0)), ContinuousRectangleBorder(borderRadius: BorderRadius.circular(30.0)),
), ),
notchMargin: 10.0, notchMargin: 10.0,
color: Colors.green, color: Colors.green,
......
...@@ -10,10 +10,10 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -10,10 +10,10 @@ import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
void main() { void main() {
test('SuperellipseShape scale and lerp', () { test('ContinuousRectangleBorder scale and lerp', () {
final SuperellipseShape c10 = SuperellipseShape(side: const BorderSide(width: 10.0), borderRadius: BorderRadius.circular(100.0)); final ContinuousRectangleBorder c10 = ContinuousRectangleBorder(side: const BorderSide(width: 10.0), borderRadius: BorderRadius.circular(100.0));
final SuperellipseShape c15 = SuperellipseShape(side: const BorderSide(width: 15.0), borderRadius: BorderRadius.circular(150.0)); final ContinuousRectangleBorder c15 = ContinuousRectangleBorder(side: const BorderSide(width: 15.0), borderRadius: BorderRadius.circular(150.0));
final SuperellipseShape c20 = SuperellipseShape(side: const BorderSide(width: 20.0), borderRadius: BorderRadius.circular(200.0)); final ContinuousRectangleBorder c20 = ContinuousRectangleBorder(side: const BorderSide(width: 20.0), borderRadius: BorderRadius.circular(200.0));
expect(c10.dimensions, const EdgeInsets.all(10.0)); expect(c10.dimensions, const EdgeInsets.all(10.0));
expect(c10.scale(2.0), c20); expect(c10.scale(2.0), c20);
expect(c20.scale(0.5), c10); expect(c20.scale(0.5), c10);
...@@ -22,7 +22,7 @@ void main() { ...@@ -22,7 +22,7 @@ void main() {
expect(ShapeBorder.lerp(c10, c20, 1.0), c20); expect(ShapeBorder.lerp(c10, c20, 1.0), c20);
}); });
test('SuperellipseShape BorderRadius.zero', () { test('ContinuousRectangleBorder BorderRadius.zero', () {
final Rect rect1 = Rect.fromLTRB(10.0, 20.0, 30.0, 40.0); final Rect rect1 = Rect.fromLTRB(10.0, 20.0, 30.0, 40.0);
final Matcher looksLikeRect1 = isPathThat( final Matcher looksLikeRect1 = isPathThat(
includes: const <Offset>[ Offset(10.0, 20.0), Offset(20.0, 30.0) ], includes: const <Offset>[ Offset(10.0, 20.0), Offset(20.0, 30.0) ],
...@@ -30,8 +30,8 @@ void main() { ...@@ -30,8 +30,8 @@ void main() {
); );
// Default border radius and border side are zero, i.e. just a rectangle. // Default border radius and border side are zero, i.e. just a rectangle.
expect(const SuperellipseShape().getOuterPath(rect1), looksLikeRect1); expect(const ContinuousRectangleBorder().getOuterPath(rect1), looksLikeRect1);
expect(const SuperellipseShape().getInnerPath(rect1), looksLikeRect1); expect(const ContinuousRectangleBorder().getInnerPath(rect1), looksLikeRect1);
// Represents the inner path when borderSide.width = 4, which is just rect1 // Represents the inner path when borderSide.width = 4, which is just rect1
// inset by 4 on all sides. // inset by 4 on all sides.
...@@ -41,17 +41,17 @@ void main() { ...@@ -41,17 +41,17 @@ void main() {
); );
const BorderSide side = BorderSide(width: 4.0); const BorderSide side = BorderSide(width: 4.0);
expect(const SuperellipseShape(side: side).getOuterPath(rect1), looksLikeRect1); expect(const ContinuousRectangleBorder(side: side).getOuterPath(rect1), looksLikeRect1);
expect(const SuperellipseShape(side: side).getInnerPath(rect1), looksLikeInnerPath); expect(const ContinuousRectangleBorder(side: side).getInnerPath(rect1), looksLikeInnerPath);
}); });
test('SuperellipseShape non-zero BorderRadius', () { test('ContinuousRectangleBorder non-zero BorderRadius', () {
final Rect rect = Rect.fromLTRB(10.0, 20.0, 30.0, 40.0); final Rect rect = Rect.fromLTRB(10.0, 20.0, 30.0, 40.0);
final Matcher looksLikeRect = isPathThat( final Matcher looksLikeRect = isPathThat(
includes: const <Offset>[ Offset(15.0, 25.0), Offset(20.0, 30.0) ], includes: const <Offset>[ Offset(15.0, 25.0), Offset(20.0, 30.0) ],
excludes: const <Offset>[ Offset(10.0, 20.0), Offset(30.0, 40.0) ], excludes: const <Offset>[ Offset(10.0, 20.0), Offset(30.0, 40.0) ],
); );
const SuperellipseShape border = SuperellipseShape( const ContinuousRectangleBorder border = ContinuousRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5.0)) borderRadius: BorderRadius.all(Radius.circular(5.0))
); );
expect(border.getOuterPath(rect), looksLikeRect); expect(border.getOuterPath(rect), looksLikeRect);
...@@ -62,7 +62,7 @@ void main() { ...@@ -62,7 +62,7 @@ void main() {
await tester.pumpWidget(RepaintBoundary( await tester.pumpWidget(RepaintBoundary(
child: Material( child: Material(
color: Colors.blueAccent[400], color: Colors.blueAccent[400],
shape: SuperellipseShape( shape: ContinuousRectangleBorder(
borderRadius: BorderRadius.circular(28.0), borderRadius: BorderRadius.circular(28.0),
), ),
), ),
...@@ -72,7 +72,7 @@ void main() { ...@@ -72,7 +72,7 @@ void main() {
await expectLater( await expectLater(
find.byType(RepaintBoundary), find.byType(RepaintBoundary),
matchesGoldenFile('superellipse_shape.golden_test_even_radii.png'), matchesGoldenFile('continuous_rectangle_border.golden_test_even_radii.png'),
skip: !Platform.isLinux, skip: !Platform.isLinux,
); );
}); });
...@@ -81,7 +81,7 @@ void main() { ...@@ -81,7 +81,7 @@ void main() {
await tester.pumpWidget(RepaintBoundary( await tester.pumpWidget(RepaintBoundary(
child: Material( child: Material(
color: Colors.greenAccent[400], color: Colors.greenAccent[400],
shape: const SuperellipseShape( shape: const ContinuousRectangleBorder(
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
topLeft: Radius.circular(28.0), topLeft: Radius.circular(28.0),
bottomRight: Radius.circular(14.0), bottomRight: Radius.circular(14.0),
...@@ -94,7 +94,7 @@ void main() { ...@@ -94,7 +94,7 @@ void main() {
await expectLater( await expectLater(
find.byType(RepaintBoundary), find.byType(RepaintBoundary),
matchesGoldenFile('superellipse_shape.golden_test_varying_radii.png'), matchesGoldenFile('continuous_rectangle_border.golden_test_varying_radii.png'),
skip: !Platform.isLinux, skip: !Platform.isLinux,
); );
}); });
...@@ -103,7 +103,7 @@ void main() { ...@@ -103,7 +103,7 @@ void main() {
await tester.pumpWidget(RepaintBoundary( await tester.pumpWidget(RepaintBoundary(
child: Material( child: Material(
color: Colors.redAccent[400], color: Colors.redAccent[400],
shape: SuperellipseShape( shape: ContinuousRectangleBorder(
borderRadius: BorderRadius.circular(50.0), borderRadius: BorderRadius.circular(50.0),
), ),
), ),
...@@ -113,7 +113,7 @@ void main() { ...@@ -113,7 +113,7 @@ void main() {
await expectLater( await expectLater(
find.byType(RepaintBoundary), find.byType(RepaintBoundary),
matchesGoldenFile('superellipse_shape.golden_test_large_radii.png'), matchesGoldenFile('continuous_rectangle_border.golden_test_large_radii.png'),
skip: !Platform.isLinux, skip: !Platform.isLinux,
); );
}); });
......
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