centered method

FrameArea centered({
  1. required int width,
  2. required int height,
})

Returns an area of at most width by height, centered within this area.

Implementation

FrameArea centered({required int width, required int height}) {
  if (width < 0 || height < 0) {
    throw ArgumentError('Centered dimensions must not be negative');
  }
  final centeredWidth = width.clamp(0, this.width);
  final centeredHeight = height.clamp(0, this.height);
  return FrameArea(
    x + (this.width - centeredWidth) ~/ 2,
    y + (this.height - centeredHeight) ~/ 2,
    centeredWidth,
    centeredHeight,
  );
}