centerRect function

Rectangle centerRect(
  1. Rectangle area,
  2. int width,
  3. int height
)

Returns a new Rectangle centered within area with width and height.

Upstream: CenterRect in third_party/ultraviolet/layout.go.

Implementation

Rectangle centerRect(Rectangle area, int width, int height) {
  final centerX = area.minX + area.width ~/ 2;
  final centerY = area.minY + area.height ~/ 2;
  final minX = centerX - width ~/ 2;
  final minY = centerY - height ~/ 2;
  return rect(minX, minY, width, height);
}