From 595bc5270fc8efd8d4df97f6c4dcfacfa4015994 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Wed, 11 Dec 2019 19:29:31 -0800 Subject: [PATCH] Remove BEFORE/AFTER statement input spacer measurable (#3506) * Remove before / after statement input measurable and use spacer properties instead. --- core/renderers/common/info.js | 3 ++ core/renderers/zelos/constants.js | 7 ++- core/renderers/zelos/drawer.js | 20 ++++----- core/renderers/zelos/info.js | 55 +++++++++++------------- core/renderers/zelos/measurables/rows.js | 42 ------------------ 5 files changed, 43 insertions(+), 84 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index bc3a78022..7db867148 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -650,6 +650,9 @@ Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function(prev, next if (prev.hasStatement) { spacer.followsStatement = true; } + if (next.hasStatement) { + spacer.precedesStatement = true; + } return spacer; }; diff --git a/core/renderers/zelos/constants.js b/core/renderers/zelos/constants.js index 1e57ab92a..42f7d70e4 100644 --- a/core/renderers/zelos/constants.js +++ b/core/renderers/zelos/constants.js @@ -106,6 +106,11 @@ Blockly.zelos.ConstantProvider = function() { */ this.TOP_ROW_MIN_HEIGHT = this.GRID_UNIT; + /** + * @override + */ + this.TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT = this.LARGE_PADDING; + /** * @override */ @@ -114,7 +119,7 @@ Blockly.zelos.ConstantProvider = function() { /** * @override */ - this.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT = 7 * this.GRID_UNIT; + this.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT = 6 * this.GRID_UNIT; /** * @override diff --git a/core/renderers/zelos/drawer.js b/core/renderers/zelos/drawer.js index a47d40e64..2ee56e555 100644 --- a/core/renderers/zelos/drawer.js +++ b/core/renderers/zelos/drawer.js @@ -98,18 +98,18 @@ Blockly.zelos.Drawer.prototype.drawOutline_ = function() { * @protected */ Blockly.zelos.Drawer.prototype.drawRightSideRow_ = function(row) { - if (row.type & Blockly.blockRendering.Types.getType('BEFORE_STATEMENT_SPACER_ROW')) { - var remainingHeight = row.height - this.constants_.INSIDE_CORNERS.rightWidth; + if (row.precedesStatement || row.followsStatement) { + var cornerHeight = this.constants_.INSIDE_CORNERS.rightHeight; + var remainingHeight = row.height - + (row.precedesStatement ? cornerHeight : 0); this.outlinePath_ += + (row.followsStatement ? + this.constants_.INSIDE_CORNERS.pathBottomRight : '') + (remainingHeight > 0 ? - Blockly.utils.svgPaths.lineOnAxis('V', row.yPos + remainingHeight) : '') + - this.constants_.INSIDE_CORNERS.pathTopRight; - } else if (row.type & Blockly.blockRendering.Types.getType('AFTER_STATEMENT_SPACER_ROW')) { - var remainingHeight = row.height - this.constants_.INSIDE_CORNERS.rightWidth; - this.outlinePath_ += - this.constants_.INSIDE_CORNERS.pathBottomRight + - (remainingHeight > 0 ? - Blockly.utils.svgPaths.lineOnAxis('V', row.yPos + row.height) : ''); + Blockly.utils.svgPaths + .lineOnAxis('V', row.yPos + remainingHeight) : '') + + (row.precedesStatement ? + this.constants_.INSIDE_CORNERS.pathTopRight : ''); } else { this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('V', row.yPos + row.height); diff --git a/core/renderers/zelos/info.js b/core/renderers/zelos/info.js index 57a35b3d0..580fc3fe2 100644 --- a/core/renderers/zelos/info.js +++ b/core/renderers/zelos/info.js @@ -42,8 +42,6 @@ goog.require('Blockly.blockRendering.StatementInput'); goog.require('Blockly.blockRendering.TopRow'); goog.require('Blockly.blockRendering.Types'); goog.require('Blockly.utils.object'); -goog.require('Blockly.zelos.AfterStatementSpacerRow'); -goog.require('Blockly.zelos.BeforeStatementSpacerRow'); goog.require('Blockly.zelos.BottomRow'); goog.require('Blockly.zelos.RightConnectionShape'); goog.require('Blockly.zelos.TopRow'); @@ -173,35 +171,6 @@ Blockly.zelos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { return this.constants_.MEDIUM_PADDING; }; -/** - * @override - */ -Blockly.zelos.RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { - var height = this.getSpacerRowHeight_(prev, next); - var width = this.getSpacerRowWidth_(prev, next); - if (Blockly.blockRendering.Types.isInputRow(next) && next.hasStatement) { - var spacer = - new Blockly.zelos.BeforeStatementSpacerRow( - this.constants_, - Math.max(height, this.constants_.INSIDE_CORNERS.rightHeight || 0), - Math.max(width, this.constants_.STATEMENT_INPUT_SPACER_MIN_WIDTH)); - } else if (Blockly.blockRendering.Types.isInputRow(prev) && prev.hasStatement) { - var spacer = - new Blockly.zelos.AfterStatementSpacerRow( - this.constants_, - Math.max(height, this.constants_.INSIDE_CORNERS.rightHeight || 0), - Math.max(width, this.constants_.STATEMENT_INPUT_SPACER_MIN_WIDTH)); - } else { - var spacer = new Blockly.blockRendering.SpacerRow( - this.constants_, height, width); - } - if (prev.hasStatement) { - spacer.followsStatement = true; - } - return spacer; -}; - - /** * @override */ @@ -219,6 +188,18 @@ Blockly.zelos.RenderInfo.prototype.getSpacerRowHeight_ = function( } return this.constants_.NO_PADDING; } + var precedesStatement = + Blockly.blockRendering.Types.isInputRow(prev) && prev.hasStatement; + var followsStatement = + Blockly.blockRendering.Types.isInputRow(next) && next.hasStatement; + if (precedesStatement || followsStatement) { + var cornerHeight = this.constants_.INSIDE_CORNERS.rightHeight || 0; + var height = Math.max(this.constants_.MEDIUM_PADDING, + Math.max(this.constants_.NOTCH_HEIGHT, cornerHeight)); + return precedesStatement && followsStatement ? + Math.max(height, + cornerHeight * 2 + this.constants_.DUMMY_INPUT_MIN_HEIGHT) : height; + } if ((Blockly.blockRendering.Types.isBottomRow(next))) { if (!this.outputConnection) { return this.constants_.SMALL_PADDING; @@ -228,6 +209,18 @@ Blockly.zelos.RenderInfo.prototype.getSpacerRowHeight_ = function( return this.constants_.MEDIUM_PADDING; }; +/** + * @override + */ +Blockly.zelos.RenderInfo.prototype.getSpacerRowWidth_ = function(prev, next) { + var width = this.width - this.startX; + if ((Blockly.blockRendering.Types.isInputRow(prev) && prev.hasStatement) || + (Blockly.blockRendering.Types.isInputRow(next) && next.hasStatement)) { + return Math.max(width, this.constants_.STATEMENT_INPUT_SPACER_MIN_WIDTH); + } + return width; +}; + /** * Adjust the x position of fields to bump all non-label fields in the first row * past the notch position. This must be called before ``computeBounds`` is diff --git a/core/renderers/zelos/measurables/rows.js b/core/renderers/zelos/measurables/rows.js index f28729ad2..1d1a34dfe 100644 --- a/core/renderers/zelos/measurables/rows.js +++ b/core/renderers/zelos/measurables/rows.js @@ -24,8 +24,6 @@ goog.provide('Blockly.zelos.BottomRow'); goog.provide('Blockly.zelos.TopRow'); -goog.provide('Blockly.zelos.AfterStatementSpacerRow'); -goog.provide('Blockly.zelos.BeforeStatementSpacerRow'); goog.require('Blockly.blockRendering.BottomRow'); goog.require('Blockly.blockRendering.TopRow'); @@ -114,43 +112,3 @@ Blockly.zelos.BottomRow.prototype.hasLeftSquareCorner = function(block) { Blockly.zelos.BottomRow.prototype.hasRightSquareCorner = function(block) { return !!block.outputConnection; }; - -/** - * An object containing information about a row spacer that comes right - * before a statement input. - * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering - * constants provider. - * @param {number} height The height of the spacer. - * @param {number} width The width of the spacer. - * @package - * @constructor - * @extends {Blockly.blockRendering.SpacerRow} - */ -Blockly.zelos.BeforeStatementSpacerRow = function(constants, height, width) { - Blockly.zelos.BeforeStatementSpacerRow.superClass_.constructor.call( - this, constants, height, width); - this.type |= - Blockly.blockRendering.Types.getType('BEFORE_STATEMENT_SPACER_ROW'); -}; -Blockly.utils.object.inherits(Blockly.zelos.BeforeStatementSpacerRow, - Blockly.blockRendering.SpacerRow); - -/** - * An object containing information about a row spacer that comes right - * after a statement input. - * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering - * constants provider. - * @param {number} height The height of the spacer. - * @param {number} width The width of the spacer. - * @package - * @constructor - * @extends {Blockly.blockRendering.SpacerRow} - */ -Blockly.zelos.AfterStatementSpacerRow = function(constants, height, width) { - Blockly.zelos.AfterStatementSpacerRow.superClass_.constructor.call( - this, constants, height, width); - this.type |= - Blockly.blockRendering.Types.getType('AFTER_STATEMENT_SPACER_ROW'); -}; -Blockly.utils.object.inherits(Blockly.zelos.AfterStatementSpacerRow, - Blockly.blockRendering.SpacerRow);