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) {
return Column(
children: [
const SizedBox(
height: 10,
SizedBox(
height: 10 + MediaQuery.of(context).viewPadding.top,
),
Row(
children: [

View File

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

View File

@ -20,10 +20,33 @@ class _DrawingPageState extends State<DrawingPage> {
double basezoom = 1.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
Widget build(BuildContext context) {
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(),
);
}
@ -51,17 +74,37 @@ class _DrawingPageState extends State<DrawingPage> {
// return basetickness * (angle / .5 + .5);
}
Widget _buildCanvas() {
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;
// 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);
});
}
}
return Scaffold(
body: Listener(
behavior: HitTestBehavior.opaque,
onPointerMove: (event) {
void _onPointerMove(PointerMoveEvent event, Size size) {
Offset pos = event.localPosition;
final scale =
calcPageDependentScale(zoom, a4Page, Size(width, height));
final scale = calcPageDependentScale(zoom, a4Page, size);
pos = translateScreenToDocumentPoint(pos, scale, offset);
if (!a4Page.contains(pos)) {
@ -79,52 +122,43 @@ class _DrawingPageState extends State<DrawingPage> {
// todo current point not in list
newWidth = _calcAngleDependentWidth(
pts
.getRange(pts.length - 10 >= 0 ? pts.length - 10 : 0,
pts.length)
.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));
..last.addPoint(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);
});
_calcNewPageOffset(event.delta, size.width);
}
}
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) {
print('Button: ${event.buttons}');
if (allowDrawWithFinger || event.kind != PointerDeviceKind.touch) {
Offset pos = event.localPosition;
final scale =
calcPageDependentScale(zoom, a4Page, Size(width, height));
final scale = calcPageDependentScale(zoom, a4Page, size);
pos = translateScreenToDocumentPoint(pos, scale, offset);
// todo line drawn on edge where line left page
if (!a4Page.contains(pos)) return;
if (eraseractive) return;
setState(() {
_strokes = List.from(_strokes)
..add(Stroke.fromPoints(
@ -153,7 +187,6 @@ class _DrawingPageState extends State<DrawingPage> {
onScaleUpdate: (details) {
if (details.scale == 1.0) return;
print('scale; ${details.scale}');
setState(() {
zoom = (basezoom * details.scale).clamp(0.25, 5.0);
});
@ -161,10 +194,15 @@ class _DrawingPageState extends State<DrawingPage> {
onScaleEnd: (details) {
basezoom = zoom;
},
onSecondaryTap: () {
print('secctab');
},
onTertiaryTapDown: (details) {
print('tertiary button');
},
child: CustomPaint(
painter: MyPainter(strokes: _strokes, offset: offset, zoom: zoom),
// todo not working
size: Size.infinite, // todo add different paper dimensions
size: Size.infinite,
),
),
),

View File

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