centered method
void
centered(
- void paint(
- PCanvas pCanvas,
- Point point,
- PDimension size
- num? x,
- num? y,
- Point? point,
- PDimension? area,
- num? width,
- num? height,
- PDimension? dimension,
- PDimension sizer()?,
- double? scale,
A helper funtion to center draw operations.
Implementation
void centered(
void Function(PCanvas pCanvas, Point point, PDimension size) paint,
{num? x,
num? y,
Point? point,
PDimension? area,
num? width,
num? height,
PDimension? dimension,
PDimension Function()? sizer,
double? scale}) {
if (x == null || y == null) {
if (point == null) {
if (area == null) {
throw ArgumentError("Parameters `point` and `area` not provided!");
}
point = area.center;
}
x ??= point.x;
y ??= point.y;
}
if (width == null || height == null) {
if (dimension == null) {
if (sizer == null) {
throw ArgumentError(
"Parameters `dimension` and `sizer` not provided!");
}
dimension = sizer();
}
if (dimension is PTextMetric) {
width ??= dimension.actualWidth.toInt();
height ??= dimension.actualHeight.toInt();
} else {
width ??= dimension.width.toInt();
height ??= dimension.height.toInt();
}
}
if (scale != null) {
width = (width * scale).toInt();
height = (height * scale).toInt();
}
var x2 = x - (width ~/ 2);
var y2 = y - (height ~/ 2);
paint(this, Point(x2, y2), PDimension(width, height));
}