adjust cursor position for keyboard

This commit is contained in:
open-trade 2020-11-25 11:20:40 +08:00
parent ed3fd81ef7
commit e3b0ee9caf
2 changed files with 12 additions and 3 deletions

View File

@ -252,6 +252,13 @@ class CursorModel with ChangeNotifier {
return Rect.fromLTWH(x0, y0, size.width / scale, size.height / scale);
}
double adjustForKeyboard() {
var keyboardHeight = MediaQueryData.fromWindow(ui.window).viewInsets.bottom;
if (keyboardHeight < 100) return 0;
var h = _y - getVisibleRect().top;
return h > 200 ? h - 200 : 0;
}
void updatePan(double dx, double dy) {
final scale = FFI.canvasModel.scale;
dx /= scale;

View File

@ -221,10 +221,11 @@ class ImagePaint extends StatelessWidget {
Widget build(BuildContext context) {
final m = Provider.of<ImageModel>(context);
final c = Provider.of<CanvasModel>(context);
final adjust = FFI.cursorModel.adjustForKeyboard();
var s = c.scale;
return CustomPaint(
painter:
new ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s),
painter: new ImagePainter(
image: m.image, x: c.x / s, y: (c.y - adjust) / s, scale: s),
);
}
}
@ -234,12 +235,13 @@ class CursorPaint extends StatelessWidget {
Widget build(BuildContext context) {
final m = Provider.of<CursorModel>(context);
final c = Provider.of<CanvasModel>(context);
final adjust = FFI.cursorModel.adjustForKeyboard();
var s = c.scale;
return CustomPaint(
painter: new ImagePainter(
image: m.image,
x: m.x * s - m.hotx + c.x,
y: m.y * s - m.hoty + c.y,
y: m.y * s - m.hoty + c.y - adjust,
scale: 1),
);
}