m3_lightmeter/lib/screens/metering/components/topbar/topbar_shape.dart

62 lines
1.8 KiB
Dart
Raw Normal View History

2022-10-23 20:18:19 +00:00
import 'package:flutter/material.dart';
2022-10-24 20:24:52 +00:00
import 'package:lightmeter/res/dimens.dart';
2022-10-23 20:18:19 +00:00
class TopBarShape extends CustomPainter {
final Color color;
final Size appendixSize;
TopBarShape({
required this.color,
required this.appendixSize,
});
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = color;
final path = Path();
2022-10-24 20:24:52 +00:00
const circularRadius = Radius.circular(Dimens.borderRadiusL);
if (appendixSize.shortestSide == 0) {
path.addRRect(
RRect.fromLTRBAndCorners(
0,
0,
0,
0,
bottomLeft: circularRadius,
bottomRight: circularRadius,
),
);
} else {
path.moveTo(size.width, 0);
path.lineTo(size.width, size.height - Dimens.borderRadiusL);
path.arcToPoint(
Offset(size.width - Dimens.borderRadiusL, size.height),
radius: circularRadius,
);
path.lineTo(size.width - appendixSize.width + Dimens.borderRadiusL, size.height);
path.arcToPoint(
Offset(size.width - appendixSize.width, size.height - Dimens.borderRadiusL),
radius: circularRadius,
);
path.lineTo(size.width - appendixSize.width, size.height - appendixSize.height + Dimens.borderRadiusM);
path.arcToPoint(
Offset(size.width - appendixSize.width - Dimens.borderRadiusM, size.height - appendixSize.height),
radius: circularRadius,
clockwise: false,
);
path.lineTo(Dimens.borderRadiusL, size.height - appendixSize.height);
path.arcToPoint(
Offset(0, size.height - appendixSize.height - Dimens.borderRadiusL),
radius: circularRadius,
);
path.lineTo(0, 0);
path.close();
}
2022-10-23 20:18:19 +00:00
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}