mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #1220 from collinjackson/scaling_focus
Ensure that the item under the focal point stays in the same place despite zooming
This commit is contained in:
commit
b05d42c3b9
@ -35,13 +35,16 @@ class ScaleAppState extends State<ScaleApp> {
|
||||
|
||||
void _handleScaleUpdate(double scale, Point focalPoint) {
|
||||
setState(() {
|
||||
_zoom = _previousZoom * scale;
|
||||
_offset = _previousOffset + (focalPoint - _startingFocalPoint) / _zoom;
|
||||
_zoom = (_previousZoom * scale);
|
||||
|
||||
// Ensure that item under the focal point stays in the same place despite zooming
|
||||
Offset normalizedOffset = (_startingFocalPoint.toOffset() - _previousOffset) / _previousZoom;
|
||||
_offset = focalPoint.toOffset() - normalizedOffset * _zoom;
|
||||
});
|
||||
}
|
||||
|
||||
void paint(PaintingCanvas canvas, Size size) {
|
||||
Point center = size.center(Point.origin) + _offset * _zoom;
|
||||
Point center = (size.center(Point.origin).toOffset() * _zoom + _offset).toPoint();
|
||||
double radius = size.width / 2.0 * _zoom;
|
||||
Gradient gradient = new RadialGradient(
|
||||
center: center, radius: radius,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user