Reduce the vertical spacing for spacers before and after an input row if it contains non-shadow connected blocks. (#3496)

This commit is contained in:
Sam El-Husseini
2019-12-09 13:17:00 -08:00
committed by GitHub
parent ec035f19d3
commit a779d44104
2 changed files with 49 additions and 7 deletions

View File

@@ -94,14 +94,20 @@ Blockly.blockRendering.Debug.prototype.drawSpacerRow = function(row, cursorY, is
return;
}
var height = Math.abs(row.height);
var isNegativeSpacing = row.height < 0;
if (isNegativeSpacing) {
cursorY -= height;
}
this.debugElements_.push(Blockly.utils.dom.createSvgElement('rect',
{
'class': 'rowSpacerRect blockRenderDebug',
'x': isRtl ? -(row.xPos + row.width) : row.xPos,
'y': cursorY,
'width': row.width,
'height': row.height,
'stroke': 'blue',
'height': height,
'stroke': isNegativeSpacing ? 'black' : 'blue',
'fill': 'blue',
'fill-opacity': '0.5',
'stroke-width': '1px'

View File

@@ -291,12 +291,13 @@ Blockly.zelos.RenderInfo.prototype.finalizeOutputConnection_ = function() {
};
/**
* Finalize alignment of elements on the block. In particular, reduce the
* implicit spacing created by the left and right output connection shapes by
* adding setting negative spacing onto the leftmost and rightmost spacers.
* Finalize horizontal alignment of elements on the block. In particular,
* reduce the implicit spacing created by the left and right output connection
* shapes by adding setting negative spacing onto the leftmost and rightmost
* spacers.
* @protected
*/
Blockly.zelos.RenderInfo.prototype.finalizeAlignment_ = function() {
Blockly.zelos.RenderInfo.prototype.finalizeHorizontalAlignment_ = function() {
if (!this.outputConnection) {
return;
}
@@ -379,11 +380,46 @@ Blockly.zelos.RenderInfo.prototype.getNegativeSpacing_ = function(elem) {
return 0;
};
/**
* Finalize vertical alignment of rows on a block. In particular, reduce the
* implicit spacing when a non-shadow block is connected to any of an input
* row's inline inputs.
* @protected
*/
Blockly.zelos.RenderInfo.prototype.finalizeVerticalAlignment_ = function() {
if (this.outputConnection) {
return;
}
for (var i = 2; i < this.rows.length - 1; i += 2) {
var prevSpacer = this.rows[i - 1];
var row = this.rows[i];
var nextSpacer = this.rows[i + 1];
if (Blockly.blockRendering.Types.isInputRow(row)) {
// Determine if the input row has non-shadow connected blocks.
var hasNonShadowConnectedBlocks = false;
for (var j = 0, elem; (elem = row.elements[j]); j++) {
if (Blockly.blockRendering.Types.isInlineInput(elem) &&
elem.connectedBlock && !elem.connectedBlock.isShadow()) {
hasNonShadowConnectedBlocks = true;
break;
}
}
if (hasNonShadowConnectedBlocks) {
// Reduce the previous and next spacer's height.
prevSpacer.height -= this.constants_.GRID_UNIT;
nextSpacer.height -= this.constants_.GRID_UNIT;
}
}
}
};
/**
* @override
*/
Blockly.zelos.RenderInfo.prototype.finalize_ = function() {
this.finalizeOutputConnection_();
this.finalizeAlignment_();
this.finalizeHorizontalAlignment_();
this.finalizeVerticalAlignment_();
Blockly.zelos.RenderInfo.superClass_.finalize_.call(this);
};