mirror of
https://github.com/google/blockly.git
synced 2026-01-10 18:37:09 +01:00
Adding checks for whether to add elem spacer on row ends (#3060)
* Adding checks for whether elem spacer shouldbe added to start and end of row. * Fix eslint and add package visibility.
This commit is contained in:
@@ -30,6 +30,7 @@ goog.require('Blockly.blockRendering.BottomRow');
|
||||
goog.require('Blockly.blockRendering.ExternalValueInput');
|
||||
goog.require('Blockly.blockRendering.Hat');
|
||||
goog.require('Blockly.blockRendering.InlineInput');
|
||||
goog.require('Blockly.blockRendering.InRowSpacer');
|
||||
goog.require('Blockly.blockRendering.InputRow');
|
||||
goog.require('Blockly.blockRendering.Measurable');
|
||||
goog.require('Blockly.blockRendering.NextConnection');
|
||||
@@ -395,18 +396,24 @@ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() {
|
||||
var oldElems = row.elements;
|
||||
row.elements = [];
|
||||
// No spacing needed before the corner on the top row or the bottom row.
|
||||
if (!Blockly.blockRendering.Types.isTopRow(row) &&
|
||||
!Blockly.blockRendering.Types.isBottomRow(row)) {
|
||||
if (row.startsWithElemSpacer()) {
|
||||
// There's a spacer before the first element in the row.
|
||||
row.elements.push(new Blockly.blockRendering.InRowSpacer(
|
||||
this.constants_, this.getInRowSpacing_(null, oldElems[0])));
|
||||
}
|
||||
for (var e = 0; e < oldElems.length; e++) {
|
||||
for (var e = 0; e < oldElems.length - 1; e++) {
|
||||
row.elements.push(oldElems[e]);
|
||||
var spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]);
|
||||
row.elements.push(
|
||||
new Blockly.blockRendering.InRowSpacer(this.constants_, spacing));
|
||||
}
|
||||
row.elements.push(oldElems[oldElems.length - 1]);
|
||||
if (row.endsWithElemSpacer()) {
|
||||
// There's a spacer after the last element in the row.
|
||||
row.elements.push(new Blockly.blockRendering.InRowSpacer(
|
||||
this.constants_,
|
||||
this.getInRowSpacing_(oldElems[oldElems.length - 1], null)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -223,12 +223,9 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
|
||||
* @override
|
||||
*/
|
||||
Blockly.geras.RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) {
|
||||
var elems = row.elements;
|
||||
var firstSpacer = row.getFirstSpacer();
|
||||
var lastSpacer = row.getLastSpacer();
|
||||
if (row.hasExternalInput || row.hasStatement) {
|
||||
// Get the spacer right before the input socket.
|
||||
lastSpacer = elems[elems.length - 3];
|
||||
row.widthWithConnectedBlocks += missingSpace;
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,24 @@ Blockly.blockRendering.Row.prototype.getLastInput = function() {
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether this row should start with an element spacer.
|
||||
* @return {boolean} Whether the row should start with a spacer.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Row.prototype.startsWithElemSpacer = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether this row should end with an element spacer.
|
||||
* @return {boolean} Whether the row should end with a spacer.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Row.prototype.endsWithElemSpacer = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convenience method to get the first spacer element on this row.
|
||||
* @return {Blockly.blockRendering.InRowSpacer} The first spacer element on
|
||||
@@ -300,6 +318,13 @@ Blockly.blockRendering.TopRow.prototype.measure = function() {
|
||||
this.widthWithConnectedBlocks = this.width;
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.blockRendering.TopRow.prototype.startsWithElemSpacer = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* An object containing information about what elements are in the bottom row of
|
||||
* a block as well as spacing information for the top row.
|
||||
@@ -382,6 +407,14 @@ Blockly.blockRendering.BottomRow.prototype.measure = function() {
|
||||
this.descenderHeight = descenderHeight;
|
||||
this.widthWithConnectedBlocks = this.width;
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.blockRendering.BottomRow.prototype.startsWithElemSpacer = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* An object containing information about a spacer between two rows.
|
||||
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
|
||||
@@ -465,21 +498,6 @@ Blockly.blockRendering.InputRow.prototype.measure = function() {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.blockRendering.InputRow.prototype.getLastSpacer = function() {
|
||||
// Adding spacing after the input connection would look weird. Find the
|
||||
// before the last input connection and add it there instead.
|
||||
if (this.hasExternalInput || this.hasStatement) {
|
||||
var elems = this.elements;
|
||||
for (var i = elems.length - 1, elem; (elem = elems[i]); i--) {
|
||||
if (Blockly.blockRendering.Types.isSpacer(elem)) {
|
||||
continue;
|
||||
}
|
||||
if (Blockly.blockRendering.Types.isInput(elem)) {
|
||||
var spacer = elems[i - 1];
|
||||
return /** @type {Blockly.blockRendering.InRowSpacer} */ (spacer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return Blockly.blockRendering.InputRow.superClass_.getLastSpacer.call(this);
|
||||
Blockly.blockRendering.InputRow.prototype.endsWithElemSpacer = function() {
|
||||
return !this.hasExternalInput && !this.hasStatement;
|
||||
};
|
||||
|
||||
@@ -210,12 +210,9 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
|
||||
* @override
|
||||
*/
|
||||
Blockly.thrasos.RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) {
|
||||
var elems = row.elements;
|
||||
var firstSpacer = row.getFirstSpacer();
|
||||
var lastSpacer = row.getLastSpacer();
|
||||
if (row.hasExternalInput || row.hasStatement) {
|
||||
// Get the spacer right before the input socket.
|
||||
lastSpacer = elems[elems.length - 3];
|
||||
row.widthWithConnectedBlocks += missingSpace;
|
||||
}
|
||||
|
||||
|
||||
@@ -363,11 +363,6 @@ Blockly.zelos.RenderInfo.prototype.getElemCenterline_ = function(row,
|
||||
Blockly.zelos.RenderInfo.prototype.addAlignmentPadding_ = function(row,
|
||||
missingSpace) {
|
||||
var lastSpacer = row.getLastSpacer();
|
||||
// Skip the right corner element on the top and bottom row, so we don't have
|
||||
// any spacing after the right corner element.
|
||||
if (Blockly.blockRendering.Types.isTopOrBottomRow(row)) {
|
||||
lastSpacer = row.elements[row.elements.length - 3];
|
||||
}
|
||||
if (lastSpacer) {
|
||||
lastSpacer.width += missingSpace;
|
||||
row.width += missingSpace;
|
||||
|
||||
@@ -55,6 +55,13 @@ Blockly.zelos.TopRow = function(constants) {
|
||||
Blockly.utils.object.inherits(Blockly.zelos.TopRow,
|
||||
Blockly.blockRendering.TopRow);
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.zelos.TopRow.prototype.endsWithElemSpacer = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render a round corner unless the block has an output connection.
|
||||
* @override
|
||||
@@ -90,6 +97,13 @@ Blockly.zelos.BottomRow = function(constants) {
|
||||
Blockly.utils.object.inherits(Blockly.zelos.BottomRow,
|
||||
Blockly.blockRendering.BottomRow);
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.zelos.BottomRow.prototype.endsWithElemSpacer = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render a round corner unless the block has an output connection.
|
||||
* @override
|
||||
|
||||
Reference in New Issue
Block a user