correct offset for notification bar

correct offset when opening page
This commit is contained in:
lukas-heiligenbrunner 2022-10-28 00:55:37 +02:00
parent d91a834126
commit 327cc1bf02
4 changed files with 109 additions and 66 deletions

View File

@ -13,8 +13,8 @@ class _AllNotesPageState extends State<AllNotesPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
children: [ children: [
const SizedBox( SizedBox(
height: 10, height: 10 + MediaQuery.of(context).viewPadding.top,
), ),
Row( Row(
children: [ children: [

View File

@ -8,6 +8,10 @@ class Stroke {
return 'Stroke{points: $points}'; return 'Stroke{points: $points}';
} }
void addPoint(Point point) {
points.add(point);
}
Stroke.fromPoints(this.points); Stroke.fromPoints(this.points);
Stroke(); Stroke();
} }

View File

@ -20,10 +20,33 @@ class _DrawingPageState extends State<DrawingPage> {
double basezoom = 1.0; double basezoom = 1.0;
Offset offset = const Offset(.0, .0); Offset offset = const Offset(.0, .0);
// todo better pen system
bool eraseractive = false;
@override
void initState() {
super.initState();
// todo might be weird behaviour if used with short side
final screenWidth =
(window.physicalSize.longestSide / window.devicePixelRatio);
_calcNewPageOffset(const Offset(.0, .0), screenWidth);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(backgroundColor: Colors.blueGrey), appBar: AppBar(backgroundColor: Colors.blueGrey, actions: [
// todo temp icon only
IconButton(
icon: const Icon(Icons.edit),
onPressed: () {
setState(() {
eraseractive = !eraseractive;
});
},
)
]),
body: _buildCanvas(), body: _buildCanvas(),
); );
} }
@ -51,80 +74,91 @@ class _DrawingPageState extends State<DrawingPage> {
// return basetickness * (angle / .5 + .5); // return basetickness * (angle / .5 + .5);
} }
// calculate new page offset from mousepointer delta
void _calcNewPageOffset(Offset delta, double canvasWidth) {
if (zoom > 1.0) {
Offset newOffset = offset + delta;
// don't allow navigating out of page if zoomed in
if (newOffset.dx > .0) {
setState(() {
offset = Offset(.0, newOffset.dy);
});
} else if (newOffset.dx < (-canvasWidth * zoom) + canvasWidth) {
setState(() {
offset = Offset((-canvasWidth * zoom) + canvasWidth, newOffset.dy);
});
print(offset);
} else {
setState(() {
offset = offset + delta;
});
}
} else {
setState(() {
// keep page x centered if zoomed out
offset = Offset(
(canvasWidth - (canvasWidth * zoom)) / 2, offset.dy + delta.dy);
});
}
}
void _onPointerMove(PointerMoveEvent event, Size size) {
Offset pos = event.localPosition;
final scale = calcPageDependentScale(zoom, a4Page, size);
pos = translateScreenToDocumentPoint(pos, scale, offset);
if (!a4Page.contains(pos)) {
return;
}
if (allowDrawWithFinger || event.kind != PointerDeviceKind.touch) {
final pts = _strokes.last.points;
if (pts.last.point == pos) return;
double newWidth = _calcTiltedWidth(3.0, event.tilt);
if (_strokes.last.points.length > 1) {
// todo current point not in list
newWidth = _calcAngleDependentWidth(
pts
.getRange(
pts.length - 10 >= 0 ? pts.length - 10 : 0, pts.length)
.toList(growable: false),
event.tilt);
}
setState(() {
_strokes = List.from(_strokes, growable: false)
..last.addPoint(Point(pos, newWidth));
});
} else {
_calcNewPageOffset(event.delta, size.width);
}
}
Widget _buildCanvas() { Widget _buildCanvas() {
final width = MediaQuery.of(context).size.width; final size = MediaQuery.of(context).size;
final height = MediaQuery.of(context).size.height;
return Scaffold( return Scaffold(
body: Listener( body: Listener(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onPointerMove: (event) { onPointerMove: (e) => _onPointerMove(e, size),
Offset pos = event.localPosition; onPointerSignal: (event) {
final scale = print('Button: ${event.buttons}');
calcPageDependentScale(zoom, a4Page, Size(width, height));
pos = translateScreenToDocumentPoint(pos, scale, offset);
if (!a4Page.contains(pos)) {
return;
}
if (allowDrawWithFinger || event.kind != PointerDeviceKind.touch) {
final pts = _strokes.last.points;
if (pts.last.point == pos) return;
double newWidth = _calcTiltedWidth(3.0, event.tilt);
if (_strokes.last.points.length > 1) {
// todo current point not in list
newWidth = _calcAngleDependentWidth(
pts
.getRange(pts.length - 10 >= 0 ? pts.length - 10 : 0,
pts.length)
.toList(growable: false),
event.tilt);
}
setState(() {
_strokes = List.from(_strokes, growable: false)
..last.points.add(Point(pos, newWidth));
});
} else {
if (zoom > 1.0) {
Offset newOffset = offset + event.delta;
// don't allow navigating out of page if zoomed in
if (newOffset.dx > .0) {
setState(() {
offset = Offset(.0, newOffset.dy);
});
} else if (newOffset.dx < (-width * zoom) + width) {
setState(() {
offset = Offset((-width * zoom) + width, newOffset.dy);
});
print(offset);
} else {
setState(() {
offset = offset + event.delta;
});
}
} else {
setState(() {
// keep page x centered if zoomed out
offset = Offset(
(width - (width * zoom)) / 2, offset.dy + event.delta.dy);
});
}
}
}, },
onPointerDown: (event) { onPointerDown: (event) {
print('Button: ${event.buttons}');
if (allowDrawWithFinger || event.kind != PointerDeviceKind.touch) { if (allowDrawWithFinger || event.kind != PointerDeviceKind.touch) {
Offset pos = event.localPosition; Offset pos = event.localPosition;
final scale = final scale = calcPageDependentScale(zoom, a4Page, size);
calcPageDependentScale(zoom, a4Page, Size(width, height));
pos = translateScreenToDocumentPoint(pos, scale, offset); pos = translateScreenToDocumentPoint(pos, scale, offset);
// todo line drawn on edge where line left page // todo line drawn on edge where line left page
if (!a4Page.contains(pos)) return; if (!a4Page.contains(pos)) return;
if (eraseractive) return;
setState(() { setState(() {
_strokes = List.from(_strokes) _strokes = List.from(_strokes)
..add(Stroke.fromPoints( ..add(Stroke.fromPoints(
@ -153,7 +187,6 @@ class _DrawingPageState extends State<DrawingPage> {
onScaleUpdate: (details) { onScaleUpdate: (details) {
if (details.scale == 1.0) return; if (details.scale == 1.0) return;
print('scale; ${details.scale}');
setState(() { setState(() {
zoom = (basezoom * details.scale).clamp(0.25, 5.0); zoom = (basezoom * details.scale).clamp(0.25, 5.0);
}); });
@ -161,10 +194,15 @@ class _DrawingPageState extends State<DrawingPage> {
onScaleEnd: (details) { onScaleEnd: (details) {
basezoom = zoom; basezoom = zoom;
}, },
onSecondaryTap: () {
print('secctab');
},
onTertiaryTapDown: (details) {
print('tertiary button');
},
child: CustomPaint( child: CustomPaint(
painter: MyPainter(strokes: _strokes, offset: offset, zoom: zoom), painter: MyPainter(strokes: _strokes, offset: offset, zoom: zoom),
// todo not working size: Size.infinite,
size: Size.infinite, // todo add different paper dimensions
), ),
), ),
), ),

View File

@ -37,6 +37,7 @@ class _CollapseDrawerState extends State<CollapseDrawer>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.only(top: MediaQuery.of(context).viewPadding.top),
color: const Color(0xff0d0d0d), color: const Color(0xff0d0d0d),
child: ClipRRect( child: ClipRRect(
borderRadius: const BorderRadius.only( borderRadius: const BorderRadius.only(