mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Move populate for topRow and bottomRow to info (#3057)
* Move populate for topRow and bottomRow from measurable definition to info. * Fix local variable and circular dependency.
This commit is contained in:
@@ -28,15 +28,18 @@ goog.provide('Blockly.blockRendering.RenderInfo');
|
||||
|
||||
goog.require('Blockly.blockRendering.BottomRow');
|
||||
goog.require('Blockly.blockRendering.ExternalValueInput');
|
||||
goog.require('Blockly.blockRendering.Hat');
|
||||
goog.require('Blockly.blockRendering.InlineInput');
|
||||
goog.require('Blockly.blockRendering.InputRow');
|
||||
goog.require('Blockly.blockRendering.Measurable');
|
||||
goog.require('Blockly.blockRendering.NextConnection');
|
||||
goog.require('Blockly.blockRendering.OutputConnection');
|
||||
goog.require('Blockly.blockRendering.PreviousConnection');
|
||||
goog.require('Blockly.blockRendering.RoundCorner');
|
||||
goog.require('Blockly.blockRendering.Row');
|
||||
goog.require('Blockly.blockRendering.SpacerRow');
|
||||
goog.require('Blockly.blockRendering.StatementInput');
|
||||
goog.require('Blockly.blockRendering.SquareCorner');
|
||||
goog.require('Blockly.blockRendering.TopRow');
|
||||
goog.require('Blockly.blockRendering.Types');
|
||||
goog.require('Blockly.RenderedConnection');
|
||||
@@ -196,7 +199,7 @@ Blockly.blockRendering.RenderInfo.prototype.measure = function() {
|
||||
* @protected
|
||||
*/
|
||||
Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() {
|
||||
this.topRow.populate(this.block_);
|
||||
this.populateTopRow_();
|
||||
this.rows.push(this.topRow);
|
||||
var activeRow = new Blockly.blockRendering.InputRow(this.constants_);
|
||||
|
||||
@@ -244,10 +247,91 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() {
|
||||
if (activeRow.elements.length) {
|
||||
this.rows.push(activeRow);
|
||||
}
|
||||
this.bottomRow.populate(this.block_);
|
||||
this.populateBottomRow_();
|
||||
this.rows.push(this.bottomRow);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create all non-spacer elements that belong on the top row.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() {
|
||||
var hasHat = this.block_.hat ?
|
||||
this.block_.hat === 'cap' : Blockly.BlockSvg.START_HAT;
|
||||
var hasPrevious = !!this.block_.previousConnection;
|
||||
var leftSquareCorner = this.topRow.hasLeftSquareCorner(this.block_);
|
||||
|
||||
if (leftSquareCorner) {
|
||||
this.topRow.elements.push(
|
||||
new Blockly.blockRendering.SquareCorner(this.constants_));
|
||||
} else {
|
||||
this.topRow.elements.push(
|
||||
new Blockly.blockRendering.RoundCorner(this.constants_));
|
||||
}
|
||||
|
||||
if (hasHat) {
|
||||
var hat = new Blockly.blockRendering.Hat(this.constants_);
|
||||
this.topRow.elements.push(hat);
|
||||
this.topRow.capline = hat.ascenderHeight;
|
||||
} else if (hasPrevious) {
|
||||
this.topRow.hasPreviousConnection = true;
|
||||
this.topRow.connection = new Blockly.blockRendering.PreviousConnection(
|
||||
this.constants_,
|
||||
/** @type {Blockly.RenderedConnection} */
|
||||
(this.block_.previousConnection));
|
||||
this.topRow.elements.push(this.topRow.connection);
|
||||
}
|
||||
|
||||
var precedesStatement = this.block_.inputList.length &&
|
||||
this.block_.inputList[0].type == Blockly.NEXT_STATEMENT;
|
||||
|
||||
// This is the minimum height for the row. If one of its elements has a
|
||||
// greater height it will be overwritten in the compute pass.
|
||||
if (precedesStatement && !this.block_.isCollapsed()) {
|
||||
this.topRow.minHeight = this.constants_.LARGE_PADDING;
|
||||
} else {
|
||||
this.topRow.minHeight = this.constants_.MEDIUM_PADDING;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create all non-spacer elements that belong on the bottom row.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() {
|
||||
this.bottomRow.hasNextConnection = !!this.block_.nextConnection;
|
||||
|
||||
var followsStatement =
|
||||
this.block_.inputList.length &&
|
||||
this.block_.inputList[this.block_.inputList.length - 1]
|
||||
.type == Blockly.NEXT_STATEMENT;
|
||||
|
||||
// This is the minimum height for the row. If one of its elements has a
|
||||
// greater height it will be overwritten in the compute pass.
|
||||
if (followsStatement) {
|
||||
this.bottomRow.minHeight = this.constants_.LARGE_PADDING;
|
||||
} else {
|
||||
this.bottomRow.minHeight = this.constants_.MEDIUM_PADDING - 1;
|
||||
}
|
||||
|
||||
var leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_);
|
||||
|
||||
if (leftSquareCorner) {
|
||||
this.bottomRow.elements.push(
|
||||
new Blockly.blockRendering.SquareCorner(this.constants_));
|
||||
} else {
|
||||
this.bottomRow.elements.push(
|
||||
new Blockly.blockRendering.RoundCorner(this.constants_));
|
||||
}
|
||||
|
||||
if (this.bottomRow.hasNextConnection) {
|
||||
this.bottomRow.connection = new Blockly.blockRendering.NextConnection(
|
||||
this.constants_,
|
||||
/** @type {Blockly.RenderedConnection} */ (this.block_.nextConnection));
|
||||
this.bottomRow.elements.push(this.bottomRow.connection);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an input element to the active row, if needed, and record the type of the
|
||||
* input on the row.
|
||||
|
||||
@@ -263,48 +263,6 @@ Blockly.blockRendering.TopRow = function(constants) {
|
||||
Blockly.utils.object.inherits(Blockly.blockRendering.TopRow,
|
||||
Blockly.blockRendering.Row);
|
||||
|
||||
/**
|
||||
* Create all non-spacer elements that belong on the top row.
|
||||
* @param {!Blockly.BlockSvg} block The block whose top row this represents.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.TopRow.prototype.populate = function(block) {
|
||||
var hasHat = block.hat ? block.hat === 'cap' : Blockly.BlockSvg.START_HAT;
|
||||
var hasPrevious = !!block.previousConnection;
|
||||
var leftSquareCorner = this.hasLeftSquareCorner(block);
|
||||
|
||||
if (leftSquareCorner) {
|
||||
this.elements.push(
|
||||
new Blockly.blockRendering.SquareCorner(this.constants_));
|
||||
} else {
|
||||
this.elements.push(
|
||||
new Blockly.blockRendering.RoundCorner(this.constants_));
|
||||
}
|
||||
|
||||
if (hasHat) {
|
||||
var hat = new Blockly.blockRendering.Hat(this.constants_);
|
||||
this.elements.push(hat);
|
||||
this.capline = hat.ascenderHeight;
|
||||
} else if (hasPrevious) {
|
||||
this.hasPreviousConnection = true;
|
||||
this.connection = new Blockly.blockRendering.PreviousConnection(
|
||||
this.constants_,
|
||||
/** @type {Blockly.RenderedConnection} */ (block.previousConnection));
|
||||
this.elements.push(this.connection);
|
||||
}
|
||||
|
||||
var precedesStatement = block.inputList.length &&
|
||||
block.inputList[0].type == Blockly.NEXT_STATEMENT;
|
||||
|
||||
// This is the minimum height for the row. If one of its elements has a
|
||||
// greater height it will be overwritten in the compute pass.
|
||||
if (precedesStatement && !block.isCollapsed()) {
|
||||
this.minHeight = this.constants_.LARGE_PADDING;
|
||||
} else {
|
||||
this.minHeight = this.constants_.MEDIUM_PADDING;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns whether or not the top row has a left square corner.
|
||||
* @param {!Blockly.BlockSvg} block The block whose top row this represents.
|
||||
@@ -390,44 +348,6 @@ Blockly.blockRendering.BottomRow = function(constants) {
|
||||
Blockly.utils.object.inherits(Blockly.blockRendering.BottomRow,
|
||||
Blockly.blockRendering.Row);
|
||||
|
||||
/**
|
||||
* Create all non-spacer elements that belong on the bottom row.
|
||||
* @param {!Blockly.BlockSvg} block The block whose bottom row this represents.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.BottomRow.prototype.populate = function(block) {
|
||||
this.hasNextConnection = !!block.nextConnection;
|
||||
|
||||
var followsStatement =
|
||||
block.inputList.length &&
|
||||
block.inputList[block.inputList.length - 1].type == Blockly.NEXT_STATEMENT;
|
||||
|
||||
// This is the minimum height for the row. If one of its elements has a
|
||||
// greater height it will be overwritten in the compute pass.
|
||||
if (followsStatement) {
|
||||
this.minHeight = this.constants_.LARGE_PADDING;
|
||||
} else {
|
||||
this.minHeight = this.constants_.MEDIUM_PADDING - 1;
|
||||
}
|
||||
|
||||
var leftSquareCorner = this.hasLeftSquareCorner(block);
|
||||
|
||||
if (leftSquareCorner) {
|
||||
this.elements.push(
|
||||
new Blockly.blockRendering.SquareCorner(this.constants_));
|
||||
} else {
|
||||
this.elements.push(
|
||||
new Blockly.blockRendering.RoundCorner(this.constants_));
|
||||
}
|
||||
|
||||
if (this.hasNextConnection) {
|
||||
this.connection = new Blockly.blockRendering.NextConnection(
|
||||
this.constants_,
|
||||
/** @type {Blockly.RenderedConnection} */ (block.nextConnection));
|
||||
this.elements.push(this.connection);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns whether or not the bottom row has a left square corner.
|
||||
* @param {!Blockly.BlockSvg} block The block whose bottom row this represents.
|
||||
|
||||
@@ -37,7 +37,9 @@ goog.require('Blockly.blockRendering.NextConnection');
|
||||
goog.require('Blockly.blockRendering.OutputConnection');
|
||||
goog.require('Blockly.blockRendering.PreviousConnection');
|
||||
goog.require('Blockly.blockRendering.RenderInfo');
|
||||
goog.require('Blockly.blockRendering.RoundCorner');
|
||||
goog.require('Blockly.blockRendering.Row');
|
||||
goog.require('Blockly.blockRendering.SquareCorner');
|
||||
goog.require('Blockly.blockRendering.SpacerRow');
|
||||
goog.require('Blockly.blockRendering.StatementInput');
|
||||
goog.require('Blockly.blockRendering.TopRow');
|
||||
@@ -92,6 +94,44 @@ Blockly.zelos.RenderInfo.prototype.getRenderer = function() {
|
||||
return /** @type {!Blockly.zelos.Renderer} */ (this.renderer_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create all non-spacer elements that belong on the top row.
|
||||
* @package
|
||||
* @override
|
||||
*/
|
||||
Blockly.zelos.RenderInfo.prototype.populateTopRow_ = function() {
|
||||
Blockly.zelos.RenderInfo.superClass_.populateTopRow_.call(this);
|
||||
|
||||
var rightSquareCorner = this.topRow.hasRightSquareCorner(this.block_);
|
||||
|
||||
if (rightSquareCorner) {
|
||||
this.topRow.elements.push(
|
||||
new Blockly.blockRendering.SquareCorner(this.constants_, 'right'));
|
||||
} else {
|
||||
this.topRow.elements.push(
|
||||
new Blockly.blockRendering.RoundCorner(this.constants_, 'right'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create all non-spacer elements that belong on the bottom row.
|
||||
* @package
|
||||
* @override
|
||||
*/
|
||||
Blockly.zelos.RenderInfo.prototype.populateBottomRow_ = function() {
|
||||
Blockly.zelos.RenderInfo.superClass_.populateBottomRow_.call(this);
|
||||
|
||||
var rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_);
|
||||
|
||||
if (rightSquareCorner) {
|
||||
this.bottomRow.elements.push(
|
||||
new Blockly.blockRendering.SquareCorner(this.constants_, 'right'));
|
||||
} else {
|
||||
this.bottomRow.elements.push(
|
||||
new Blockly.blockRendering.RoundCorner(this.constants_, 'right'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
@@ -55,24 +55,6 @@ Blockly.zelos.TopRow = function(constants) {
|
||||
Blockly.utils.object.inherits(Blockly.zelos.TopRow,
|
||||
Blockly.blockRendering.TopRow);
|
||||
|
||||
/**
|
||||
* Create all non-spacer elements that belong on the top row.
|
||||
* @param {!Blockly.BlockSvg} block The block whose top row this represents.
|
||||
* @package
|
||||
* @override
|
||||
*/
|
||||
Blockly.zelos.TopRow.prototype.populate = function(block) {
|
||||
Blockly.zelos.TopRow.superClass_.populate.call(this, block);
|
||||
|
||||
var rightSquareCorner = this.hasRightSquareCorner(block);
|
||||
|
||||
if (rightSquareCorner) {
|
||||
this.elements.push(new Blockly.blockRendering.SquareCorner(this.constants_, 'right'));
|
||||
} else {
|
||||
this.elements.push(new Blockly.blockRendering.RoundCorner(this.constants_, 'right'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Render a round corner unless the block has an output connection.
|
||||
* @override
|
||||
@@ -108,24 +90,6 @@ Blockly.zelos.BottomRow = function(constants) {
|
||||
Blockly.utils.object.inherits(Blockly.zelos.BottomRow,
|
||||
Blockly.blockRendering.BottomRow);
|
||||
|
||||
/**
|
||||
* Create all non-spacer elements that belong on the bottom row.
|
||||
* @param {!Blockly.BlockSvg} block The block whose bottom row this represents.
|
||||
* @package
|
||||
* @override
|
||||
*/
|
||||
Blockly.zelos.BottomRow.prototype.populate = function(block) {
|
||||
Blockly.zelos.BottomRow.superClass_.populate.call(this, block);
|
||||
|
||||
var rightSquareCorner = this.hasRightSquareCorner(block);
|
||||
|
||||
if (rightSquareCorner) {
|
||||
this.elements.push(new Blockly.blockRendering.SquareCorner(this.constants_, 'right'));
|
||||
} else {
|
||||
this.elements.push(new Blockly.blockRendering.RoundCorner(this.constants_, 'right'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Render a round corner unless the block has an output connection.
|
||||
* @override
|
||||
|
||||
Reference in New Issue
Block a user