pass through scaleStart/Update/End to mobile gesture detector
This commit is contained in:
@@ -146,12 +146,13 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future setDimensions(Rect rect, double pixelRatio) async {
|
Future setDimensions(Rect rect, double pixelRatio) async {
|
||||||
|
_pixelRatio = pixelRatio;
|
||||||
this._rect.value = Rect.fromLTWH(
|
this._rect.value = Rect.fromLTWH(
|
||||||
(rect.left * _pixelRatio).floor().toDouble(),
|
(rect.left * _pixelRatio).floor().toDouble(),
|
||||||
rect.top * _pixelRatio.floor().toDouble(),
|
rect.top * _pixelRatio.floor().toDouble(),
|
||||||
(rect.width * _pixelRatio).ceil().toDouble(),
|
(rect.width * _pixelRatio).ceil().toDouble(),
|
||||||
(rect.height * _pixelRatio).ceil().toDouble());
|
(rect.height * _pixelRatio).ceil().toDouble());
|
||||||
_pixelRatio = pixelRatio;
|
print("Using dimensions ${_rect.value} (pixel ratio : $_pixelRatio)");
|
||||||
if (!_rectCompleter.isCompleted) {
|
if (!_rectCompleter.isCompleted) {
|
||||||
_rectCompleter.complete(this._rect.value);
|
_rectCompleter.complete(this._rect.value);
|
||||||
}
|
}
|
||||||
@@ -1404,7 +1405,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
textureDetails.value!.height - (y * _pixelRatio).toInt(), outPtr);
|
textureDetails.value!.height - (y * _pixelRatio).toInt(), outPtr);
|
||||||
int wait = 0;
|
int wait = 0;
|
||||||
while (outPtr.value == 0) {
|
while (outPtr.value == 0) {
|
||||||
await Future.delayed(const Duration(milliseconds: 32));
|
await Future.delayed(const Duration(milliseconds: 16));
|
||||||
wait++;
|
wait++;
|
||||||
if (wait > 10) {
|
if (wait > 10) {
|
||||||
allocator.free(outPtr);
|
allocator.free(outPtr);
|
||||||
|
|||||||
@@ -41,13 +41,20 @@ class FilamentGestureDetector extends StatelessWidget {
|
|||||||
///
|
///
|
||||||
final bool enablePicking;
|
final bool enablePicking;
|
||||||
|
|
||||||
|
final void Function(ScaleStartDetails)? onScaleStart;
|
||||||
|
final void Function(ScaleUpdateDetails)? onScaleUpdate;
|
||||||
|
final void Function(ScaleEndDetails)? onScaleEnd;
|
||||||
|
|
||||||
const FilamentGestureDetector(
|
const FilamentGestureDetector(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
this.child,
|
this.child,
|
||||||
this.showControlOverlay = false,
|
this.showControlOverlay = false,
|
||||||
this.enableCamera = true,
|
this.enableCamera = true,
|
||||||
this.enablePicking = true})
|
this.enablePicking = true,
|
||||||
|
this.onScaleStart,
|
||||||
|
this.onScaleUpdate,
|
||||||
|
this.onScaleEnd})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -64,12 +71,14 @@ class FilamentGestureDetector extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return FilamentGestureDetectorMobile(
|
return FilamentGestureDetectorMobile(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
child: child,
|
child: child,
|
||||||
showControlOverlay: showControlOverlay,
|
showControlOverlay: showControlOverlay,
|
||||||
enableCamera: enableCamera,
|
enableCamera: enableCamera,
|
||||||
enablePicking: enablePicking,
|
enablePicking: enablePicking,
|
||||||
);
|
onScaleStart: onScaleStart,
|
||||||
|
onScaleUpdate: onScaleUpdate,
|
||||||
|
onScaleEnd: onScaleEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ class FilamentGestureDetectorMobile extends StatefulWidget {
|
|||||||
|
|
||||||
final double zoomDelta;
|
final double zoomDelta;
|
||||||
|
|
||||||
|
final void Function(ScaleStartDetails)? onScaleStart;
|
||||||
|
final void Function(ScaleUpdateDetails)? onScaleUpdate;
|
||||||
|
final void Function(ScaleEndDetails)? onScaleEnd;
|
||||||
|
|
||||||
const FilamentGestureDetectorMobile(
|
const FilamentGestureDetectorMobile(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
@@ -46,6 +50,9 @@ class FilamentGestureDetectorMobile extends StatefulWidget {
|
|||||||
this.showControlOverlay = false,
|
this.showControlOverlay = false,
|
||||||
this.enableCamera = true,
|
this.enableCamera = true,
|
||||||
this.enablePicking = true,
|
this.enablePicking = true,
|
||||||
|
this.onScaleStart,
|
||||||
|
this.onScaleUpdate,
|
||||||
|
this.onScaleEnd,
|
||||||
this.zoomDelta = 1})
|
this.zoomDelta = 1})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@@ -132,11 +139,12 @@ class _FilamentGestureDetectorMobileState
|
|||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
behavior: HitTestBehavior.translucent,
|
behavior: HitTestBehavior.translucent,
|
||||||
onTapDown: (d) {
|
onTapDown: (d) {
|
||||||
if (widget.enablePicking) {
|
if (!widget.enablePicking) {
|
||||||
print("PICK");
|
return;
|
||||||
widget.controller.pick(
|
|
||||||
d.globalPosition.dx.toInt(), d.globalPosition.dy.toInt());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widget.controller.pick(
|
||||||
|
d.globalPosition.dx.toInt(), d.globalPosition.dy.toInt());
|
||||||
},
|
},
|
||||||
onDoubleTap: () {
|
onDoubleTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -144,6 +152,10 @@ class _FilamentGestureDetectorMobileState
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
onScaleStart: (d) async {
|
onScaleStart: (d) async {
|
||||||
|
if (widget.onScaleStart != null) {
|
||||||
|
widget.onScaleStart!.call(d);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (d.pointerCount == 2 && widget.enableCamera) {
|
if (d.pointerCount == 2 && widget.enableCamera) {
|
||||||
_scaling = true;
|
_scaling = true;
|
||||||
await widget.controller.zoomBegin();
|
await widget.controller.zoomBegin();
|
||||||
@@ -158,6 +170,10 @@ class _FilamentGestureDetectorMobileState
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onScaleUpdate: (ScaleUpdateDetails d) async {
|
onScaleUpdate: (ScaleUpdateDetails d) async {
|
||||||
|
if (widget.onScaleUpdate != null) {
|
||||||
|
widget.onScaleUpdate!.call(d);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (d.pointerCount == 2 && widget.enableCamera) {
|
if (d.pointerCount == 2 && widget.enableCamera) {
|
||||||
if (d.horizontalScale != _lastScale) {
|
if (d.horizontalScale != _lastScale) {
|
||||||
widget.controller.zoomUpdate(
|
widget.controller.zoomUpdate(
|
||||||
@@ -177,6 +193,11 @@ class _FilamentGestureDetectorMobileState
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onScaleEnd: (d) async {
|
onScaleEnd: (d) async {
|
||||||
|
if (widget.onScaleEnd != null) {
|
||||||
|
widget.onScaleEnd!.call(d);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (d.pointerCount == 2 && widget.enableCamera) {
|
if (d.pointerCount == 2 && widget.enableCamera) {
|
||||||
widget.controller.zoomEnd();
|
widget.controller.zoomEnd();
|
||||||
} else if (!_scaling && widget.enableCamera) {
|
} else if (!_scaling && widget.enableCamera) {
|
||||||
|
|||||||
Reference in New Issue
Block a user