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,17 +74,37 @@ class _DrawingPageState extends State<DrawingPage> {
// return basetickness * (angle / .5 + .5); // return basetickness * (angle / .5 + .5);
} }
Widget _buildCanvas() { // calculate new page offset from mousepointer delta
final width = MediaQuery.of(context).size.width; void _calcNewPageOffset(Offset delta, double canvasWidth) {
final height = MediaQuery.of(context).size.height; 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);
});
}
}
return Scaffold( void _onPointerMove(PointerMoveEvent event, Size size) {
body: Listener(
behavior: HitTestBehavior.opaque,
onPointerMove: (event) {
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);
if (!a4Page.contains(pos)) { if (!a4Page.contains(pos)) {
@ -79,52 +122,43 @@ class _DrawingPageState extends State<DrawingPage> {
// todo current point not in list // todo current point not in list
newWidth = _calcAngleDependentWidth( newWidth = _calcAngleDependentWidth(
pts pts
.getRange(pts.length - 10 >= 0 ? pts.length - 10 : 0, .getRange(
pts.length) pts.length - 10 >= 0 ? pts.length - 10 : 0, pts.length)
.toList(growable: false), .toList(growable: false),
event.tilt); event.tilt);
} }
setState(() { setState(() {
_strokes = List.from(_strokes, growable: false) _strokes = List.from(_strokes, growable: false)
..last.points.add(Point(pos, newWidth)); ..last.addPoint(Point(pos, newWidth));
}); });
} else { } else {
if (zoom > 1.0) { _calcNewPageOffset(event.delta, size.width);
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);
});
} }
} }
Widget _buildCanvas() {
final size = MediaQuery.of(context).size;
return Scaffold(
body: Listener(
behavior: HitTestBehavior.opaque,
onPointerMove: (e) => _onPointerMove(e, size),
onPointerSignal: (event) {
print('Button: ${event.buttons}');
}, },
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(