computePaddedContentBounds function

Rect2D? computePaddedContentBounds({
  1. required CanvasSceneDocument scene,
  2. required ComputedScene computed,
  3. ContentBoundsPolicy policy = const ContentBoundsPolicy(),
  4. double paddingPx = 0,
})

Implementation

Rect2D? computePaddedContentBounds({
  required CanvasSceneDocument scene,
  required ComputedScene computed,
  ContentBoundsPolicy policy = const ContentBoundsPolicy(),
  double paddingPx = 0,
}) {
  Rect2D? bounds;

  final preferredId = policy.preferredIdFor(scene);

  if (preferredId != null) {
    bounds = computed.paintBoundsWorldById[preferredId];
  }

  bounds ??= _unionPaintBounds(policy.fallbackIdsFor(scene), computed);

  if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
    return null;
  }

  return Rect2D.fromLTWH(
    bounds.left - paddingPx,
    bounds.top - paddingPx,
    bounds.width + paddingPx * 2,
    bounds.height + paddingPx * 2,
  );
}