Storing notch_left_offset on rows and measurables.

This commit is contained in:
kozbial
2019-08-19 17:54:41 -07:00
parent 3e6c0a07e3
commit ffbd483442
6 changed files with 24 additions and 19 deletions

View File

@@ -214,8 +214,7 @@ Blockly.blockRendering.Drawer.prototype.drawStatementInput_ = function(row) {
var innerTopLeftCorner =
input.notchShape.pathRight +
Blockly.utils.svgPaths.lineOnAxis('h',
-(Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT -
Blockly.blockRendering.constants.INSIDE_CORNERS.width)) +
-(input.notchOffset - Blockly.blockRendering.constants.INSIDE_CORNERS.width)) +
Blockly.blockRendering.constants.INSIDE_CORNERS.pathTop;
var innerHeight =
@@ -420,8 +419,7 @@ Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = functio
Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = function(row) {
var input = row.getLastInput();
if (input.connection) {
var connX = row.xPos + row.statementEdge +
Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT;
var connX = row.xPos + row.statementEdge + input.notchOffset;
if (this.info_.RTL) {
connX *= -1;
}
@@ -457,7 +455,7 @@ Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = funct
Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = function() {
var topRow = this.info_.topRow;
if (topRow.connection) {
var x = topRow.xPos + Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT;
var x = topRow.xPos + topRow.notchOffset;
var connX = (this.info_.RTL ? -x : x);
topRow.connection.connectionModel.setOffsetInBlock(connX, 0);
}

View File

@@ -403,26 +403,26 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne
}
// Spacing between a square corner and a previous or next connection
if (next.isPreviousConnection()) {
return Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT;
return next.notchOffset;
} else if (next.isNextConnection()) {
// Next connections are shifted slightly to the left (in both LTR and RTL)
// to make the dark path under the previous connection show through.
var offset = (this.RTL ? 1 : -1) *
Blockly.blockRendering.constants.DARK_PATH_OFFSET / 2;
return Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT + offset;
return next.notchOffset + offset;
}
}
// Spacing between a rounded corner and a previous or next connection.
if (prev.isRoundedCorner()) {
if (next.isPreviousConnection()) {
return Blockly.blockRendering.constants.NOTCH_OFFSET_ROUNDED_CORNER_PREV;
return next.notchOffset - Blockly.blockRendering.constants.CORNER_RADIUS;
} else if (next.isNextConnection()) {
// Next connections are shifted slightly to the left (in both LTR and RTL)
// to make the dark path under the previous connection show through.
var offset = (this.RTL ? 1 : -1) *
Blockly.blockRendering.constants.DARK_PATH_OFFSET / 2;
return Blockly.blockRendering.constants.NOTCH_OFFSET_ROUNDED_CORNER_PREV + offset;
return next.notchOffset - Blockly.blockRendering.constants.CORNER_RADIUS + offset;
}
}

View File

@@ -74,14 +74,6 @@ Blockly.blockRendering.constants.CORNER_RADIUS = 8;
Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT =
Blockly.blockRendering.constants.NOTCH_WIDTH;
// This is the width from where a rounded corner ends to where a previous
// connection starts.
// The position of the notch should not change as the rounded corner decreases
// in radius.
Blockly.blockRendering.constants.NOTCH_OFFSET_ROUNDED_CORNER_PREV =
Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT -
Blockly.blockRendering.constants.CORNER_RADIUS;
Blockly.blockRendering.constants.STATEMENT_BOTTOM_SPACER = 5;
Blockly.blockRendering.constants.STATEMENT_INPUT_PADDING_LEFT = 20;
Blockly.blockRendering.constants.BETWEEN_STATEMENT_PADDING_Y = 4;

View File

@@ -154,8 +154,7 @@ Blockly.blockRendering.StatementInput = function(input) {
this.height -= this.notchShape.height;
}
}
this.width = Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT +
this.notchShape.width;
this.width = this.notchOffset + this.notchShape.width;
};
goog.inherits(Blockly.blockRendering.StatementInput,
Blockly.blockRendering.Input);

View File

@@ -63,6 +63,14 @@ Blockly.blockRendering.Measurable.prototype.connectionShape =
Blockly.blockRendering.Measurable.prototype.notchShape =
Blockly.blockRendering.constants.NOTCH;
/**
* The offset from the left side of a block or the inside of a statement input
* to the left side of the connection notch.
* @type {number}
*/
Blockly.blockRendering.Measurable.prototype.notchOffset =
Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT;
// TODO: We may remove these helper functions if all of them end up being direct
// checks against types.

View File

@@ -155,6 +155,14 @@ Blockly.blockRendering.Row = function() {
Blockly.blockRendering.Row.prototype.notchShape =
Blockly.blockRendering.constants.NOTCH;
/**
* The offset from the left side of a block or the inside of a statement input
* to the left side of the connection notch.
* @type {number}
*/
Blockly.blockRendering.Row.prototype.notchOffset =
Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT;
/**
* Inspect all subcomponents and populate all size properties on the row.
* @package