diff --git a/core/block_svg.ts b/core/block_svg.ts index 54a5bfaaab7..bc02ef63810 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -109,6 +109,14 @@ export class BlockSvg */ width = 0; + /** + * Width of this block, not including any connected value blocks. + * Width is in workspace units. + * + * @internal + */ + childlessWidth = 0; + /** * Map from IDs for warnings text to PIDs of functions to apply them. * Used to be able to maintain multiple warnings. @@ -436,8 +444,28 @@ export class BlockSvg * @returns Object with coordinates of the bounding box. */ getBoundingRectangle(): Rect { + return this.getBoundingRectangleWithDimensions(this.getHeightWidth()); + } + + /** + * Returns the coordinates of a bounding box describing the dimensions of this + * block alone. + * Coordinate system: workspace coordinates. + * + * @returns Object with coordinates of the bounding box. + */ + getBoundingRectangleWithoutChildren(): Rect { + return this.getBoundingRectangleWithDimensions({ + height: this.height, + width: this.width, + }); + } + + private getBoundingRectangleWithDimensions(blockBounds: { + height: number; + width: number; + }) { const blockXY = this.getRelativeToSurfaceXY(); - const blockBounds = this.getHeightWidth(); let left; let right; if (this.RTL) { diff --git a/core/renderers/common/drawer.ts b/core/renderers/common/drawer.ts index 5ded620b799..17d54eea541 100644 --- a/core/renderers/common/drawer.ts +++ b/core/renderers/common/drawer.ts @@ -80,6 +80,7 @@ export class Drawer { // The dark path adds to the size of the block in both X and Y. this.block_.height = this.info_.height; this.block_.width = this.info_.widthWithChildren; + this.block_.childlessWidth = this.info_.width; } /** Create the outline of the block. This is a single continuous path. */