mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
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:
@@ -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) {
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user