From 39b3717b2c4d0a1aaf5c2fa294a4a15fffff7f8a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 13 Aug 2019 13:32:41 -0700 Subject: [PATCH] Include next connection in block's bounding box --- .../block_render_draw.js | 14 ++++++++------ .../block_render_draw_highlight.js | 2 +- .../block_render_info.js | 2 +- .../block_rendering_rewrite/measurables.js | 18 +++++++++++++++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/core/renderers/block_rendering_rewrite/block_render_draw.js b/core/renderers/block_rendering_rewrite/block_render_draw.js index 417848c56..ed5a2e3b4 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw.js @@ -147,7 +147,7 @@ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { } else if (elem.isSpacer()) { this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('h', elem.width); } - // No branch for a square corner, because it's a no-op. + // No branch for a 'square corner', because it's a no-op. } this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('v', topRow.height); }; @@ -183,7 +183,7 @@ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('H', row.xPos + row.width) + - Blockly.blockRendering.constants.PUZZLE_TAB.pathDown + + input.connectionShape.pathDown + Blockly.utils.svgPaths.lineOnAxis('v', row.height - input.connectionHeight); }; @@ -248,7 +248,8 @@ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { } this.positionNextConnection_(); - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('v', bottomRow.height); + this.outlinePath_ += + Blockly.utils.svgPaths.lineOnAxis('v', bottomRow.height - bottomRow.overhangY); for (var i = elems.length - 1; i >= 0; i--) { var elem = elems[i]; @@ -280,8 +281,9 @@ Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { if (outputConnection) { var tabBottom = outputConnection.connectionOffsetY + outputConnection.height; // Draw a line up to the bottom of the tab. - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('V', tabBottom); - this.outlinePath_ += Blockly.blockRendering.constants.PUZZLE_TAB.pathUp; + this.outlinePath_ += + Blockly.utils.svgPaths.lineOnAxis('V', tabBottom) + + outputConnection.connectionShape.pathUp; } // Close off the path. This draws a vertical line up to the start of the // block's path, which may be either a rounded or a sharp corner. @@ -466,7 +468,7 @@ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { var x = connInfo.xPos; // Already contains info about startX var connX = (this.info_.RTL ? -x : x) + 0.5; bottomRow.connection.setOffsetInBlock( - connX, this.info_.height + + connX, (connInfo.centerline - connInfo.height / 2) + Blockly.blockRendering.constants.DARK_PATH_OFFSET); } }; diff --git a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js index be3d8af38..0a9834234 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js @@ -156,7 +156,7 @@ Blockly.blockRendering.Highlighter.prototype.drawRightSideRow = function(row) { }; Blockly.blockRendering.Highlighter.prototype.drawBottomRow = function(row) { - var height = row.yPos + row.height; + var height = row.yPos + row.height - row.overhangY; // Highlight the vertical edge of the bottom row on the input side. // Highlighting is always from the top left, both in LTR and RTL. diff --git a/core/renderers/block_rendering_rewrite/block_render_info.js b/core/renderers/block_rendering_rewrite/block_render_info.js index 1262e6639..9336396a1 100644 --- a/core/renderers/block_rendering_rewrite/block_render_info.js +++ b/core/renderers/block_rendering_rewrite/block_render_info.js @@ -688,7 +688,7 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, e } else if (elem.isInlineInput()) { result += elem.height / 2; } else if (elem.isNextConnection()) { - result += row.height + elem.height / 2; + result += (row.height - row.overhangY + elem.height / 2); } else { result += (row.height / 2); } diff --git a/core/renderers/block_rendering_rewrite/measurables.js b/core/renderers/block_rendering_rewrite/measurables.js index de88510b5..cce0b39b6 100644 --- a/core/renderers/block_rendering_rewrite/measurables.js +++ b/core/renderers/block_rendering_rewrite/measurables.js @@ -311,7 +311,7 @@ Blockly.blockRendering.ExternalValueInput = function(input) { this.type = 'external value input'; if (!this.connectedBlock) { - this.height = Blockly.blockRendering.constants.TAB_HEIGHT; + this.height = this.connectionShape.height; } else { this.height = this.connectedBlockHeight - 2 * Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP; @@ -564,6 +564,7 @@ Blockly.blockRendering.BottomRow = function(block) { this.type = 'bottom row'; this.hasNextConnection = !!block.nextConnection; this.connection = block.nextConnection; + this.overhangY = 0; var followsStatement = block.inputList.length && @@ -587,3 +588,18 @@ Blockly.blockRendering.BottomRow.prototype.getNextConnection = function() { } return null; }; + +Blockly.blockRendering.BottomRow.prototype.measure = function() { + for (var e = 0; e < this.elements.length; e++) { + var elem = this.elements[e]; + this.width += elem.width; + if (!(elem.isSpacer())) { + if (elem.type == 'next connection') { + this.height = this.height + elem.height; + this.overhangY = elem.height; + } + this.height = Math.max(this.height, elem.height); + } + } + this.widthWithConnectedBlocks = this.width; +};