mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
Merge pull request #2773 from moniika/moniika-rtl-render-debug
Updating debug rendering for RTL blocks.
This commit is contained in:
@@ -65,13 +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 {boolean} isRtl Whether the block is rendered RTL.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Debug.prototype.drawSpacerRow = function(row, cursorY) {
|
||||
Blockly.blockRendering.Debug.prototype.drawSpacerRow = function(row, cursorY, isRtl) {
|
||||
this.debugElements_.push(Blockly.utils.dom.createSvgElement('rect',
|
||||
{
|
||||
'class': 'rowSpacerRect blockRenderDebug',
|
||||
'x': 0,
|
||||
'x': isRtl ? -row.width : 0,
|
||||
'y': cursorY,
|
||||
'width': row.width,
|
||||
'height': row.height,
|
||||
@@ -82,17 +83,21 @@ Blockly.blockRendering.Debug.prototype.drawSpacerRow = function(row, cursorY) {
|
||||
/**
|
||||
* Draw a debug rectangle for a horizontal spacer.
|
||||
* @param {!Blockly.BlockSvg.InRowSpacer} elem The spacer to render
|
||||
* @param {number} cursorX The x position of the left of the row.
|
||||
* @param {number} rowHeight The height of the container row.
|
||||
* @param {boolean} isRtl Whether the block is rendered RTL.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Debug.prototype.drawSpacerElem = function(elem, cursorX, rowHeight) {
|
||||
Blockly.blockRendering.Debug.prototype.drawSpacerElem = function(elem, rowHeight, isRtl) {
|
||||
var xPos = elem.xPos;
|
||||
if (isRtl) {
|
||||
xPos = -(xPos + elem.width);
|
||||
}
|
||||
var debugRenderedHeight = Math.min(elem.height, rowHeight);
|
||||
var yPos = elem.centerline - debugRenderedHeight / 2;
|
||||
this.debugElements_.push(Blockly.utils.dom.createSvgElement('rect',
|
||||
{
|
||||
'class': 'elemSpacerRect blockRenderDebug',
|
||||
'x': cursorX,
|
||||
'x': xPos,
|
||||
'y': yPos,
|
||||
'width': elem.width,
|
||||
'height': debugRenderedHeight,
|
||||
@@ -103,19 +108,22 @@ Blockly.blockRendering.Debug.prototype.drawSpacerElem = function(elem, cursorX,
|
||||
/**
|
||||
* Draw a debug rectangle for an in-row element.
|
||||
* @param {!Blockly.BlockSvg.Measurable} elem The element to render
|
||||
* @param {number} cursorX The x position of the left of the row.
|
||||
* @param {number} centerY The y position of the center of the row, vertically.
|
||||
* @param {boolean} isRtl Whether the block is rendered RTL.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Debug.prototype.drawRenderedElem = function(elem, cursorX) {
|
||||
Blockly.blockRendering.Debug.prototype.drawRenderedElem = function(elem, isRtl) {
|
||||
var xPos = elem.xPos;
|
||||
if (isRtl) {
|
||||
xPos = -(xPos + elem.width);
|
||||
}
|
||||
var yPos = elem.centerline - elem.height / 2;
|
||||
this.debugElements_.push(Blockly.utils.dom.createSvgElement('rect',
|
||||
{
|
||||
'class': 'rowRenderingRect blockRenderDebug',
|
||||
'x': cursorX,
|
||||
'x': xPos,
|
||||
'y': yPos,
|
||||
'width': elem.width,
|
||||
'height': elem.height ,
|
||||
'height': elem.height,
|
||||
},
|
||||
this.svgRoot_));
|
||||
|
||||
@@ -168,13 +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 {boolean} isRtl Whether the block is rendered RTL.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Debug.prototype.drawRenderedRow = function(row, cursorY) {
|
||||
Blockly.blockRendering.Debug.prototype.drawRenderedRow = function(row, cursorY, isRtl) {
|
||||
this.debugElements_.push(Blockly.utils.dom.createSvgElement('rect',
|
||||
{
|
||||
'class': 'elemRenderingRect blockRenderDebug',
|
||||
'x': 0,
|
||||
'x': isRtl ? -row.width : 0,
|
||||
'y': cursorY ,
|
||||
'width': row.width,
|
||||
'height': row.height,
|
||||
@@ -186,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 {boolean} isRtl Whether the block is rendered RTL.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Debug.prototype.drawRowWithElements = function(row, cursorY) {
|
||||
var cursorX = 0;
|
||||
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, cursorX, row.height);
|
||||
this.drawSpacerElem(elem, row.height, isRtl);
|
||||
} else {
|
||||
this.drawRenderedElem(elem, cursorX);
|
||||
this.drawRenderedElem(elem, isRtl);
|
||||
}
|
||||
cursorX += elem.width;
|
||||
}
|
||||
this.drawRenderedRow(row, cursorY);
|
||||
this.drawRenderedRow(row, cursorY, isRtl);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -216,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);
|
||||
this.drawSpacerRow(row, cursorY, info.RTL);
|
||||
} else {
|
||||
this.drawRowWithElements(row, cursorY);
|
||||
this.drawRowWithElements(row, cursorY, info.RTL);
|
||||
}
|
||||
cursorY += row.height;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user