From c8c325d0950bb389cab3ea90d86f9837d72bdc2c Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 24 Mar 2016 13:36:07 -0700 Subject: [PATCH] Replace EdgeInsets.TRBL with EdgeInsets.fromLTRB This matches the pattern from Rect. I've left EdgeInsets.TRBL marked as deprecated to give clients a chance to update. Fixes #2860 --- .../lib/demo/tabs_fab_demo.dart | 2 +- examples/stocks/lib/stock_row.dart | 2 +- .../flutter/lib/src/material/constants.dart | 2 +- packages/flutter/lib/src/material/dialog.dart | 4 +- .../flutter/lib/src/painting/box_painter.dart | 2 +- .../flutter/lib/src/painting/edge_insets.dart | 53 +++++++++++-------- packages/flutter/lib/src/widgets/app.dart | 2 +- .../scrollable_list_hit_testing_test.dart | 4 +- 8 files changed, 39 insertions(+), 32 deletions(-) diff --git a/examples/material_gallery/lib/demo/tabs_fab_demo.dart b/examples/material_gallery/lib/demo/tabs_fab_demo.dart index 710393a9d2..cb5556a13b 100644 --- a/examples/material_gallery/lib/demo/tabs_fab_demo.dart +++ b/examples/material_gallery/lib/demo/tabs_fab_demo.dart @@ -78,7 +78,7 @@ class _TabsFabDemoState extends State { return new Container( key: new ValueKey(page.label), - padding: const EdgeInsets.TRBL(48.0, 48.0, 96.0, 48.0), + padding: const EdgeInsets.fromLTRB(48.0, 48.0, 48.0, 96.0), child: new Card( child: new Center( child: new Text(page.label, style: textStyle) diff --git a/examples/stocks/lib/stock_row.dart b/examples/stocks/lib/stock_row.dart index bc69a22d6c..c3ff432326 100644 --- a/examples/stocks/lib/stock_row.dart +++ b/examples/stocks/lib/stock_row.dart @@ -72,7 +72,7 @@ class StockRow extends StatelessWidget { onDoubleTap: _getHandler(onDoubleTap), onLongPress: _getHandler(onLongPressed), child: new Container( - padding: const EdgeInsets.TRBL(16.0, 16.0, 20.0, 16.0), + padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 20.0), decoration: new BoxDecoration( border: new Border( bottom: new BorderSide(color: Theme.of(context).dividerColor) diff --git a/packages/flutter/lib/src/material/constants.dart b/packages/flutter/lib/src/material/constants.dart index e7f19fa155..952b4ba187 100644 --- a/packages/flutter/lib/src/material/constants.dart +++ b/packages/flutter/lib/src/material/constants.dart @@ -33,7 +33,7 @@ const double kFadingEdgeLength = 12.0; const double kPressedStateDuration = 64.0; // units? const Duration kThemeChangeDuration = const Duration(milliseconds: 200); -const EdgeInsets kDialogHeadingPadding = const EdgeInsets.TRBL(24.0, 24.0, 20.0, 24.0); +const EdgeInsets kDialogHeadingPadding = const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 20.0); const double kRadialReactionRadius = 24.0; // Pixels const Duration kRadialReactionDuration = const Duration(milliseconds: 200); diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index 078bba5fab..5bcdd71d34 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -62,7 +62,7 @@ class Dialog extends StatelessWidget { if (title != null) { EdgeInsets padding = titlePadding; if (padding == null) - padding = new EdgeInsets.TRBL(24.0, 24.0, content == null ? 20.0 : 0.0, 24.0); + padding = new EdgeInsets.fromLTRB(24.0, 24.0, 24.0, content == null ? 20.0 : 0.0); dialogBody.add(new Padding( padding: padding, child: new DefaultTextStyle( @@ -75,7 +75,7 @@ class Dialog extends StatelessWidget { if (content != null) { EdgeInsets padding = contentPadding; if (padding == null) - padding = const EdgeInsets.TRBL(20.0, 24.0, 24.0, 24.0); + padding = const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0); dialogBody.add(new Padding( padding: padding, child: new DefaultTextStyle( diff --git a/packages/flutter/lib/src/painting/box_painter.dart b/packages/flutter/lib/src/painting/box_painter.dart index 50cd3981a3..651cefb9de 100644 --- a/packages/flutter/lib/src/painting/box_painter.dart +++ b/packages/flutter/lib/src/painting/box_painter.dart @@ -112,7 +112,7 @@ class Border { /// The widths of the sides of this border represented as an EdgeInsets. EdgeInsets get dimensions { - return new EdgeInsets.TRBL(top.width, right.width, bottom.width, left.width); + return new EdgeInsets.fromLTRB(left.width, top.width, right.width, bottom.width); } /// Whether all four sides of the border are identical. diff --git a/packages/flutter/lib/src/painting/edge_insets.dart b/packages/flutter/lib/src/painting/edge_insets.dart index 3d9dcca8d5..619b67c822 100644 --- a/packages/flutter/lib/src/painting/edge_insets.dart +++ b/packages/flutter/lib/src/painting/edge_insets.dart @@ -12,8 +12,15 @@ import 'basic_types.dart'; /// example, the padding inside a box can be represented using this class. class EdgeInsets { /// Constructs insets from offsets from the top, right, bottom and left. + /// + /// We'll be removing this function sometime soon. Please use + /// [EdgeInsets.fromLTRB] instead. + @Deprecated('soon. Use fromLTRB instead.') const EdgeInsets.TRBL(this.top, this.right, this.bottom, this.left); + /// Constructs insets from offsets from the left, top, right, and bottom. + const EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom); + /// Constructs insets where all the offsets are value. const EdgeInsets.all(double value) : top = value, right = value, bottom = value, left = value; @@ -56,63 +63,63 @@ class EdgeInsets { Size get collapsedSize => new Size(horizontal, vertical); /// An EdgeInsets with top and bottom as well as left and right flipped. - EdgeInsets get flipped => new EdgeInsets.TRBL(bottom, left, top, right); + EdgeInsets get flipped => new EdgeInsets.fromLTRB(left, top, right, bottom); Rect inflateRect(Rect rect) { return new Rect.fromLTRB(rect.left - left, rect.top - top, rect.right + right, rect.bottom + bottom); } EdgeInsets operator -(EdgeInsets other) { - return new EdgeInsets.TRBL( + return new EdgeInsets.fromLTRB( + left - other.left, top - other.top, right - other.right, - bottom - other.bottom, - left - other.left + bottom - other.bottom ); } EdgeInsets operator +(EdgeInsets other) { - return new EdgeInsets.TRBL( + return new EdgeInsets.fromLTRB( + left + other.left, top + other.top, right + other.right, - bottom + other.bottom, - left + other.left + bottom + other.bottom ); } EdgeInsets operator *(double other) { - return new EdgeInsets.TRBL( + return new EdgeInsets.fromLTRB( + left * other, top * other, right * other, - bottom * other, - left * other + bottom * other ); } EdgeInsets operator /(double other) { - return new EdgeInsets.TRBL( + return new EdgeInsets.fromLTRB( + left / other, top / other, right / other, - bottom / other, - left / other + bottom / other ); } EdgeInsets operator ~/(double other) { - return new EdgeInsets.TRBL( + return new EdgeInsets.fromLTRB( + (left ~/ other).toDouble(), (top ~/ other).toDouble(), (right ~/ other).toDouble(), - (bottom ~/ other).toDouble(), - (left ~/ other).toDouble() + (bottom ~/ other).toDouble() ); } EdgeInsets operator %(double other) { - return new EdgeInsets.TRBL( + return new EdgeInsets.fromLTRB( + left % other, top % other, right % other, - bottom % other, - left % other + bottom % other ); } @@ -126,16 +133,16 @@ class EdgeInsets { return b * t; if (b == null) return a * (1.0 - t); - return new EdgeInsets.TRBL( + return new EdgeInsets.fromLTRB( + ui.lerpDouble(a.left, b.left, t), ui.lerpDouble(a.top, b.top, t), ui.lerpDouble(a.right, b.right, t), - ui.lerpDouble(a.bottom, b.bottom, t), - ui.lerpDouble(a.left, b.left, t) + ui.lerpDouble(a.bottom, b.bottom, t) ); } /// An EdgeInsets with zero offsets in each direction. - static const EdgeInsets zero = const EdgeInsets.TRBL(0.0, 0.0, 0.0, 0.0); + static const EdgeInsets zero = const EdgeInsets.all(0.0); @override bool operator ==(dynamic other) { diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart index 03f035d786..30d436af62 100644 --- a/packages/flutter/lib/src/widgets/app.dart +++ b/packages/flutter/lib/src/widgets/app.dart @@ -105,7 +105,7 @@ class WidgetsApp extends StatefulWidget { } EdgeInsets _getPadding(ui.WindowPadding padding) { - return new EdgeInsets.TRBL(padding.top, padding.right, padding.bottom, padding.left); + return new EdgeInsets.fromLTRB(padding.left, padding.top, padding.right, padding.bottom); } class WidgetsAppState extends State implements BindingObserver { diff --git a/packages/flutter/test/widget/scrollable_list_hit_testing_test.dart b/packages/flutter/test/widget/scrollable_list_hit_testing_test.dart index bbdd92ec5d..9adf39c73b 100644 --- a/packages/flutter/test/widget/scrollable_list_hit_testing_test.dart +++ b/packages/flutter/test/widget/scrollable_list_hit_testing_test.dart @@ -100,7 +100,7 @@ void main() { new ScrollableList( key: new GlobalKey(), itemExtent: 290.0, - padding: new EdgeInsets.TRBL(20.0, 15.0, 10.0, 5.0), + padding: new EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), children: items.map((int item) { return new Container( child: new GestureDetector( @@ -135,7 +135,7 @@ void main() { key: new GlobalKey(), itemExtent: 290.0, scrollAnchor: ViewportAnchor.end, - padding: new EdgeInsets.TRBL(20.0, 15.0, 10.0, 5.0), + padding: new EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), children: items.map((int item) { return new Container( child: new GestureDetector(