Refactoring to pass boolean isRtl rather than whole RenderInfo object for debug render helper methods.

This commit is contained in:
kozbial
2019-08-05 14:06:02 -07:00
parent 5208ddfc03
commit 2ece7a7c53

View File

@@ -65,15 +65,14 @@ Blockly.blockRendering.Debug.prototype.clearElems = function() {
* Draw a debug rectangle for a spacer (empty) row.
* @param {!Blockly.blockRendering.Row} row The row to render
* @param {number} cursorY The y position of the top of the row.
* @param {!Blockly.blockRendering.RenderInfo} info Rendering information about
* the block to debug.
* @param {boolean} isRtl Whether the block is rendered RTL.
* @package
*/
Blockly.blockRendering.Debug.prototype.drawSpacerRow = function(row, cursorY, info) {
Blockly.blockRendering.Debug.prototype.drawSpacerRow = function(row, cursorY, isRtl) {
this.debugElements_.push(Blockly.utils.dom.createSvgElement('rect',
{
'class': 'rowSpacerRect blockRenderDebug',
'x': info.RTL ? -row.width : 0,
'x': isRtl ? -row.width : 0,
'y': cursorY,
'width': row.width,
'height': row.height,
@@ -85,13 +84,12 @@ Blockly.blockRendering.Debug.prototype.drawSpacerRow = function(row, cursorY, in
* Draw a debug rectangle for a horizontal spacer.
* @param {!Blockly.BlockSvg.InRowSpacer} elem The spacer to render
* @param {number} rowHeight The height of the container row.
* @param {!Blockly.blockRendering.RenderInfo} info Rendering information about
* the block to debug.
* @param {boolean} isRtl Whether the block is rendered RTL.
* @package
*/
Blockly.blockRendering.Debug.prototype.drawSpacerElem = function(elem, rowHeight, info) {
Blockly.blockRendering.Debug.prototype.drawSpacerElem = function(elem, rowHeight, isRtl) {
var xPos = elem.xPos;
if (info.RTL) {
if (isRtl) {
xPos = -(xPos + elem.width);
}
var debugRenderedHeight = Math.min(elem.height, rowHeight);
@@ -110,13 +108,12 @@ Blockly.blockRendering.Debug.prototype.drawSpacerElem = function(elem, rowHeight
/**
* Draw a debug rectangle for an in-row element.
* @param {!Blockly.BlockSvg.Measurable} elem The element to render
* @param {!Blockly.blockRendering.RenderInfo} info Rendering information about
* the block to debug.
* @param {boolean} isRtl Whether the block is rendered RTL.
* @package
*/
Blockly.blockRendering.Debug.prototype.drawRenderedElem = function(elem, info) {
Blockly.blockRendering.Debug.prototype.drawRenderedElem = function(elem, isRtl) {
var xPos = elem.xPos;
if (info.RTL) {
if (isRtl) {
xPos = -(xPos + elem.width);
}
var yPos = elem.centerline - elem.height / 2;
@@ -179,15 +176,14 @@ Blockly.blockRendering.Debug.prototype.drawConnection = function(conn) {
* Draw a debug rectangle for a non-empty row.
* @param {!Blockly.BlockSvg.Row} row The non-empty row to render.
* @param {number} cursorY The y position of the top of the row.
* @param {!Blockly.blockRendering.RenderInfo} info Rendering information about
* the block to debug.
* @param {boolean} isRtl Whether the block is rendered RTL.
* @package
*/
Blockly.blockRendering.Debug.prototype.drawRenderedRow = function(row, cursorY, info) {
Blockly.blockRendering.Debug.prototype.drawRenderedRow = function(row, cursorY, isRtl) {
this.debugElements_.push(Blockly.utils.dom.createSvgElement('rect',
{
'class': 'elemRenderingRect blockRenderDebug',
'x': info.RTL ? -row.width : 0,
'x': isRtl ? -row.width : 0,
'y': cursorY ,
'width': row.width,
'height': row.height,
@@ -199,20 +195,19 @@ Blockly.blockRendering.Debug.prototype.drawRenderedRow = function(row, cursorY,
* Draw debug rectangles for a non-empty row and all of its subcomponents.
* @param {!Blockly.BlockSvg.Row} row The non-empty row to render.
* @param {number} cursorY The y position of the top of the row.
* @param {!Blockly.blockRendering.RenderInfo} info Rendering information about
* the block to debug.
* @param {boolean} isRtl Whether the block is rendered RTL.
* @package
*/
Blockly.blockRendering.Debug.prototype.drawRowWithElements = function(row, cursorY, info) {
Blockly.blockRendering.Debug.prototype.drawRowWithElements = function(row, cursorY, isRtl) {
for (var e = 0; e < row.elements.length; e++) {
var elem = row.elements[e];
if (elem.isSpacer()) {
this.drawSpacerElem(elem, row.height, info);
this.drawSpacerElem(elem, row.height, isRtl);
} else {
this.drawRenderedElem(elem, info);
this.drawRenderedElem(elem, isRtl);
}
}
this.drawRenderedRow(row, cursorY, info);
this.drawRenderedRow(row, cursorY, isRtl);
};
/**
@@ -229,9 +224,9 @@ Blockly.blockRendering.Debug.prototype.drawDebug = function(block, info) {
for (var r = 0; r < info.rows.length; r++) {
var row = info.rows[r];
if (row.isSpacer()) {
this.drawSpacerRow(row, cursorY, info);
this.drawSpacerRow(row, cursorY, info.RTL);
} else {
this.drawRowWithElements(row, cursorY, info);
this.drawRowWithElements(row, cursorY, info.RTL);
}
cursorY += row.height;
}