feat: allow fetching block bounds not including children. (#8284)

* feat: allow fetching block bounds not including children.

* chore: run formatter.

* chore: run the other formatter.

* fix: don't include subsequent blocks in the childless bounding rect.

* chore: remove logging.
This commit is contained in:
Aaron Dodson
2024-07-10 14:52:07 -07:00
committed by GitHub
parent 8323642d0e
commit fa15cda950
2 changed files with 30 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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. */