Move Point to Offset (#9277)
* Manually fix every use of Point.x and Point.y
Some of these were moved to dx/dy, but not all.
* Manually convert uses of the old gradient API
* Remove old reference to Point.
* Mechanical changes
I applied the following at the root of the Flutter repository:
git ls-files -z | xargs -0 sed -i 's/\bPoint[.]origin\b/Offset.zero/g'
git ls-files -z | xargs -0 sed -i 's/\bPoint[.]lerp\b/Offset.lerp/g'
git ls-files -z | xargs -0 sed -i 's/\bnew Point\b/new Offset/g'
git ls-files -z | xargs -0 sed -i 's/\bconst Point\b/const Offset/g'
git ls-files -z | xargs -0 sed -i 's/\bstatic Point /static Offset /g'
git ls-files -z | xargs -0 sed -i 's/\bfinal Point /final Offset /g'
git ls-files -z | xargs -0 sed -i 's/^\( *\)Point /\1Offset /g'
git ls-files -z | xargs -0 sed -i 's/ui[.]Point\b/ui.Offset/g'
git ls-files -z | xargs -0 sed -i 's/(Point\b/(Offset/g'
git ls-files -z | xargs -0 sed -i 's/\([[{,]\) Point\b/\1 Offset/g'
git ls-files -z | xargs -0 sed -i 's/@required Point\b/@required Offset/g'
git ls-files -z | xargs -0 sed -i 's/<Point>/<Offset>/g'
git ls-files -z | xargs -0 sed -i 's/[.]toOffset()//g'
git ls-files -z | xargs -0 sed -i 's/[.]toPoint()//g'
git ls-files -z | xargs -0 sed -i 's/\bshow Point, /show /g'
git ls-files -z | xargs -0 sed -i 's/\bshow Point;/show Offset;/g'
* Mechanical changes - dartdocs
I applied the following at the root of the Flutter repository:
git ls-files -z | xargs -0 sed -i 's/\ba \[Point\]/an [Offset]/g'
git ls-files -z | xargs -0 sed -i 's/\[Point\]/[Offset]/g'
* Further improvements and a test
* Fix minor errors from rebasing...
* Roll engine
This commit is contained in:
@@ -178,8 +178,8 @@ class _AllSectionsLayout extends MultiChildLayoutDelegate {
|
||||
return Rect.lerp(begin, end, tColumnToRow);
|
||||
}
|
||||
|
||||
Point _interpolatePoint(Point begin, Point end) {
|
||||
return Point.lerp(begin, end, tColumnToRow);
|
||||
Offset _interpolatePoint(Offset begin, Offset end) {
|
||||
return Offset.lerp(begin, end, tColumnToRow);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -220,30 +220,30 @@ class _AllSectionsLayout extends MultiChildLayoutDelegate {
|
||||
cardRect.left + 0.5, cardRect.top, cardRect.width - 1.0, cardRect.height
|
||||
);
|
||||
layoutChild(cardId, new BoxConstraints.tight(insetRect.size));
|
||||
positionChild(cardId, insetRect.topLeft.toOffset());
|
||||
positionChild(cardId, insetRect.topLeft);
|
||||
}
|
||||
|
||||
// Layout the title for index.
|
||||
final Size titleSize = layoutChild('title$index', new BoxConstraints.loose(cardRect.size));
|
||||
final double columnTitleY = columnCardRect.centerLeft.y - titleSize.height / 2.0;
|
||||
final double rowTitleY = rowCardRect.centerLeft.y - titleSize.height / 2.0;
|
||||
final double columnTitleY = columnCardRect.centerLeft.dy - titleSize.height / 2.0;
|
||||
final double rowTitleY = rowCardRect.centerLeft.dy - titleSize.height / 2.0;
|
||||
final double centeredRowTitleX = rowTitleX + (rowTitleWidth - titleSize.width) / 2.0;
|
||||
final Point columnTitleOrigin = new Point(columnTitleX, columnTitleY);
|
||||
final Point rowTitleOrigin = new Point(centeredRowTitleX, rowTitleY);
|
||||
final Point titleOrigin = _interpolatePoint(columnTitleOrigin, rowTitleOrigin);
|
||||
positionChild('title$index', titleOrigin.toOffset() + offset);
|
||||
final Offset columnTitleOrigin = new Offset(columnTitleX, columnTitleY);
|
||||
final Offset rowTitleOrigin = new Offset(centeredRowTitleX, rowTitleY);
|
||||
final Offset titleOrigin = _interpolatePoint(columnTitleOrigin, rowTitleOrigin);
|
||||
positionChild('title$index', titleOrigin + offset);
|
||||
|
||||
// Layout the selection indicator for index.
|
||||
final Size indicatorSize = layoutChild('indicator$index', new BoxConstraints.loose(cardRect.size));
|
||||
final double columnIndicatorX = cardRect.centerRight.x - indicatorSize.width - 16.0;
|
||||
final double columnIndicatorY = cardRect.bottomRight.y - indicatorSize.height - 16.0;
|
||||
final Point columnIndicatorOrigin = new Point(columnIndicatorX, columnIndicatorY);
|
||||
final double columnIndicatorX = cardRect.centerRight.dx - indicatorSize.width - 16.0;
|
||||
final double columnIndicatorY = cardRect.bottomRight.dy - indicatorSize.height - 16.0;
|
||||
final Offset columnIndicatorOrigin = new Offset(columnIndicatorX, columnIndicatorY);
|
||||
final Rect titleRect = new Rect.fromPoints(titleOrigin, titleSize.bottomRight(titleOrigin));
|
||||
final double centeredRowIndicatorX = rowIndicatorX + (rowIndicatorWidth - indicatorSize.width) / 2.0;
|
||||
final double rowIndicatorY = titleRect.bottomCenter.y + 16.0;
|
||||
final Point rowIndicatorOrigin = new Point(centeredRowIndicatorX, rowIndicatorY);
|
||||
final Point indicatorOrigin = _interpolatePoint(columnIndicatorOrigin, rowIndicatorOrigin);
|
||||
positionChild('indicator$index', indicatorOrigin.toOffset() + offset);
|
||||
final double rowIndicatorY = titleRect.bottomCenter.dy + 16.0;
|
||||
final Offset rowIndicatorOrigin = new Offset(centeredRowIndicatorX, rowIndicatorY);
|
||||
final Offset indicatorOrigin = _interpolatePoint(columnIndicatorOrigin, rowIndicatorOrigin);
|
||||
positionChild('indicator$index', indicatorOrigin + offset);
|
||||
|
||||
columnCardY += columnCardHeight;
|
||||
rowCardX += rowCardWidth;
|
||||
@@ -434,7 +434,7 @@ class _AnimationDemoHomeState extends State<AnimationDemoHome> {
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: new SectionCard(section: allSections[index]),
|
||||
onTapUp: (TapUpDetails details) {
|
||||
final double xOffset = details.globalPosition.x;
|
||||
final double xOffset = details.globalPosition.dx;
|
||||
setState(() {
|
||||
_maybeScroll(midScrollOffset, index, xOffset);
|
||||
});
|
||||
|
||||
@@ -90,7 +90,7 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
|
||||
void _handleOnScaleStart(ScaleStartDetails details) {
|
||||
setState(() {
|
||||
_previousScale = _scale;
|
||||
_normalizedOffset = (details.focalPoint.toOffset() - _offset) / _scale;
|
||||
_normalizedOffset = (details.focalPoint - _offset) / _scale;
|
||||
// The fling animation stops if an input gesture starts.
|
||||
_controller.stop();
|
||||
});
|
||||
@@ -100,7 +100,7 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
|
||||
setState(() {
|
||||
_scale = (_previousScale * details.scale).clamp(1.0, 4.0);
|
||||
// Ensure that image location under the focal point stays in the same place despite scaling.
|
||||
_offset = _clampOffset(details.focalPoint.toOffset() - _normalizedOffset * _scale);
|
||||
_offset = _clampOffset(details.focalPoint - _normalizedOffset * _scale);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
|
||||
if (magnitude < _kMinFlingVelocity)
|
||||
return;
|
||||
final Offset direction = details.velocity.pixelsPerSecond / magnitude;
|
||||
final double distance = (Point.origin & context.size).shortestSide;
|
||||
final double distance = (Offset.zero & context.size).shortestSide;
|
||||
_flingAnimation = new Tween<Offset>(
|
||||
begin: _offset,
|
||||
end: _clampOffset(_offset + direction * distance)
|
||||
|
||||
@@ -20,7 +20,7 @@ void main() {
|
||||
|
||||
|
||||
// Scroll the Buttons demo into view so that a tap will succeed
|
||||
final Point allDemosOrigin = tester.getTopRight(find.text('Demos'));
|
||||
final Offset allDemosOrigin = tester.getTopRight(find.text('Demos'));
|
||||
final Finder button = find.text('Buttons');
|
||||
while (button.evaluate().isEmpty) {
|
||||
await tester.dragFrom(allDemosOrigin, const Offset(0.0, -100.0));
|
||||
|
||||
@@ -77,8 +77,8 @@ Future<Null> smokeDemo(WidgetTester tester, String routeName) async {
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
|
||||
// Scroll the demo around a bit.
|
||||
await tester.flingFrom(const Point(400.0, 300.0), const Offset(-100.0, 0.0), 500.0);
|
||||
await tester.flingFrom(const Point(400.0, 300.0), const Offset(0.0, -100.0), 500.0);
|
||||
await tester.flingFrom(const Offset(400.0, 300.0), const Offset(-100.0, 0.0), 500.0);
|
||||
await tester.flingFrom(const Offset(400.0, 300.0), const Offset(0.0, -100.0), 500.0);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
@@ -90,15 +90,15 @@ Future<Null> smokeDemo(WidgetTester tester, String routeName) async {
|
||||
verifyToStringOutput('debugDumpLayerTree', routeName, RendererBinding.instance?.renderView?.debugLayer?.toStringDeep());
|
||||
|
||||
// Scroll the demo around a bit more.
|
||||
await tester.flingFrom(const Point(400.0, 300.0), const Offset(-200.0, 0.0), 500.0);
|
||||
await tester.flingFrom(const Offset(400.0, 300.0), const Offset(-200.0, 0.0), 500.0);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
await tester.flingFrom(const Point(400.0, 300.0), const Offset(100.0, 0.0), 500.0);
|
||||
await tester.flingFrom(const Offset(400.0, 300.0), const Offset(100.0, 0.0), 500.0);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
await tester.flingFrom(const Point(400.0, 300.0), const Offset(0.0, 400.0), 1000.0);
|
||||
await tester.flingFrom(const Offset(400.0, 300.0), const Offset(0.0, 400.0), 1000.0);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user