Remove BEFORE/AFTER statement input spacer measurable (#3506)

* Remove before / after statement input measurable and use spacer properties instead.
This commit is contained in:
Sam El-Husseini
2019-12-11 19:29:31 -08:00
committed by GitHub
parent adc06cc544
commit 595bc5270f
5 changed files with 43 additions and 84 deletions

View File

@@ -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;
};

View File

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

View File

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

View File

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

View File

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