pass through scaleStart/Update/End to mobile gesture detector

This commit is contained in:
Nick Fisher
2024-03-08 18:00:30 +08:00
parent adfb607eb7
commit 3cbf796248
3 changed files with 44 additions and 13 deletions

View File

@@ -146,12 +146,13 @@ class FilamentControllerFFI extends FilamentController {
@override
Future setDimensions(Rect rect, double pixelRatio) async {
_pixelRatio = pixelRatio;
this._rect.value = Rect.fromLTWH(
(rect.left * _pixelRatio).floor().toDouble(),
rect.top * _pixelRatio.floor().toDouble(),
(rect.width * _pixelRatio).ceil().toDouble(),
(rect.height * _pixelRatio).ceil().toDouble());
_pixelRatio = pixelRatio;
print("Using dimensions ${_rect.value} (pixel ratio : $_pixelRatio)");
if (!_rectCompleter.isCompleted) {
_rectCompleter.complete(this._rect.value);
}
@@ -1404,7 +1405,7 @@ class FilamentControllerFFI extends FilamentController {
textureDetails.value!.height - (y * _pixelRatio).toInt(), outPtr);
int wait = 0;
while (outPtr.value == 0) {
await Future.delayed(const Duration(milliseconds: 32));
await Future.delayed(const Duration(milliseconds: 16));
wait++;
if (wait > 10) {
allocator.free(outPtr);

View File

@@ -41,13 +41,20 @@ class FilamentGestureDetector extends StatelessWidget {
///
final bool enablePicking;
final void Function(ScaleStartDetails)? onScaleStart;
final void Function(ScaleUpdateDetails)? onScaleUpdate;
final void Function(ScaleEndDetails)? onScaleEnd;
const FilamentGestureDetector(
{Key? key,
required this.controller,
this.child,
this.showControlOverlay = false,
this.enableCamera = true,
this.enablePicking = true})
this.enablePicking = true,
this.onScaleStart,
this.onScaleUpdate,
this.onScaleEnd})
: super(key: key);
@override
@@ -64,12 +71,14 @@ class FilamentGestureDetector extends StatelessWidget {
);
} else {
return FilamentGestureDetectorMobile(
controller: controller,
child: child,
showControlOverlay: showControlOverlay,
enableCamera: enableCamera,
enablePicking: enablePicking,
);
controller: controller,
child: child,
showControlOverlay: showControlOverlay,
enableCamera: enableCamera,
enablePicking: enablePicking,
onScaleStart: onScaleStart,
onScaleUpdate: onScaleUpdate,
onScaleEnd: onScaleEnd);
}
}
}

View File

@@ -39,6 +39,10 @@ class FilamentGestureDetectorMobile extends StatefulWidget {
final double zoomDelta;
final void Function(ScaleStartDetails)? onScaleStart;
final void Function(ScaleUpdateDetails)? onScaleUpdate;
final void Function(ScaleEndDetails)? onScaleEnd;
const FilamentGestureDetectorMobile(
{Key? key,
required this.controller,
@@ -46,6 +50,9 @@ class FilamentGestureDetectorMobile extends StatefulWidget {
this.showControlOverlay = false,
this.enableCamera = true,
this.enablePicking = true,
this.onScaleStart,
this.onScaleUpdate,
this.onScaleEnd,
this.zoomDelta = 1})
: super(key: key);
@@ -132,11 +139,12 @@ class _FilamentGestureDetectorMobileState
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTapDown: (d) {
if (widget.enablePicking) {
print("PICK");
widget.controller.pick(
d.globalPosition.dx.toInt(), d.globalPosition.dy.toInt());
if (!widget.enablePicking) {
return;
}
widget.controller.pick(
d.globalPosition.dx.toInt(), d.globalPosition.dy.toInt());
},
onDoubleTap: () {
setState(() {
@@ -144,6 +152,10 @@ class _FilamentGestureDetectorMobileState
});
},
onScaleStart: (d) async {
if (widget.onScaleStart != null) {
widget.onScaleStart!.call(d);
return;
}
if (d.pointerCount == 2 && widget.enableCamera) {
_scaling = true;
await widget.controller.zoomBegin();
@@ -158,6 +170,10 @@ class _FilamentGestureDetectorMobileState
}
},
onScaleUpdate: (ScaleUpdateDetails d) async {
if (widget.onScaleUpdate != null) {
widget.onScaleUpdate!.call(d);
return;
}
if (d.pointerCount == 2 && widget.enableCamera) {
if (d.horizontalScale != _lastScale) {
widget.controller.zoomUpdate(
@@ -177,6 +193,11 @@ class _FilamentGestureDetectorMobileState
}
},
onScaleEnd: (d) async {
if (widget.onScaleEnd != null) {
widget.onScaleEnd!.call(d);
return;
}
if (d.pointerCount == 2 && widget.enableCamera) {
widget.controller.zoomEnd();
} else if (!_scaling && widget.enableCamera) {