Merge pull request #2898 from rachel-fenichel/constant_property

Centralize references to Blockly.blockRendering.constants
This commit is contained in:
Rachel Fenichel
2019-08-23 10:40:01 -07:00
committed by GitHub
14 changed files with 149 additions and 180 deletions

View File

@@ -102,9 +102,9 @@ goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/measurables.js", ['Blockly.blockRendering.InRowSpacer'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable']);
goog.addDependency("../../../" + dir + "/core/renderers/geras/info.js", ['Blockly.geras', 'Blockly.geras.RenderInfo'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/base.js", ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.constants']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/connections.js", ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.constants', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/inputs.js", ['Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.ExternalValueInput'], ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.constants']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/rows.js", ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/connections.js", ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection'], ['Blockly.blockRendering.Measurable', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/inputs.js", ['Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.ExternalValueInput'], ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.Measurable']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/rows.js", ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow'], ['Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/thrasos/info.js", ['Blockly.thrasos', 'Blockly.thrasos.RenderInfo'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/zelos/info.js", ['Blockly.zelos', 'Blockly.zelos.RenderInfo'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/scrollbar.js", ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Touch', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']);

View File

@@ -26,7 +26,6 @@
goog.provide('Blockly.blockRendering.Drawer');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.Debug');
goog.require('Blockly.blockRendering.RenderInfo');
goog.require('Blockly.blockRendering.Highlighter');
@@ -55,6 +54,8 @@ Blockly.blockRendering.Drawer = function(block, info) {
this.pathObject_ = new Blockly.BlockSvg.PathObject();
this.highlighter_ =
new Blockly.blockRendering.Highlighter(this.info_, this.pathObject_);
this.constants_ = Blockly.blockRendering.getConstants();
};
/**
@@ -91,9 +92,9 @@ Blockly.blockRendering.Drawer.prototype.recordSizeOnBlock_ = function() {
// This is used when the block is reporting its size to anyone else.
// The dark path adds to the size of the block in both X and Y.
this.block_.height = this.info_.height +
Blockly.blockRendering.constants.DARK_PATH_OFFSET;
this.constants_.DARK_PATH_OFFSET;
this.block_.width = this.info_.widthWithChildren +
Blockly.blockRendering.constants.DARK_PATH_OFFSET;
this.constants_.DARK_PATH_OFFSET;
};
/**
@@ -148,11 +149,11 @@ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() {
for (var i = 0, elem; (elem = elements[i]); i++) {
if (elem.type == 'round corner') {
this.outlinePath_ +=
Blockly.blockRendering.constants.OUTSIDE_CORNERS.topLeft;
this.constants_.OUTSIDE_CORNERS.topLeft;
} else if (elem.type == 'previous connection') {
this.outlinePath_ += topRow.notchShape.pathLeft;
} else if (elem.type == 'hat') {
this.outlinePath_ += Blockly.blockRendering.constants.START_HAT.path;
this.outlinePath_ += this.constants_.START_HAT.path;
} else if (elem.isSpacer()) {
this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('h', elem.width);
}
@@ -171,8 +172,8 @@ Blockly.blockRendering.Drawer.prototype.drawJaggedEdge_ = function(row) {
this.highlighter_.drawJaggedEdge_(row);
}
var remainder =
row.height - Blockly.blockRendering.constants.JAGGED_TEETH.height;
this.outlinePath_ += Blockly.blockRendering.constants.JAGGED_TEETH.path +
row.height - this.constants_.JAGGED_TEETH.height;
this.outlinePath_ += this.constants_.JAGGED_TEETH.path +
Blockly.utils.svgPaths.lineOnAxis('v', remainder);
};
@@ -214,16 +215,16 @@ Blockly.blockRendering.Drawer.prototype.drawStatementInput_ = function(row) {
var innerTopLeftCorner =
input.notchShape.pathRight +
Blockly.utils.svgPaths.lineOnAxis('h',
-(input.notchOffset - Blockly.blockRendering.constants.INSIDE_CORNERS.width)) +
Blockly.blockRendering.constants.INSIDE_CORNERS.pathTop;
-(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) +
this.constants_.INSIDE_CORNERS.pathTop;
var innerHeight =
row.height - (2 * Blockly.blockRendering.constants.INSIDE_CORNERS.height);
row.height - (2 * this.constants_.INSIDE_CORNERS.height);
this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('H', x) +
innerTopLeftCorner +
Blockly.utils.svgPaths.lineOnAxis('v', innerHeight) +
Blockly.blockRendering.constants.INSIDE_CORNERS.pathBottom;
this.constants_.INSIDE_CORNERS.pathBottom;
this.positionStatementInputConnection_(row);
};
@@ -267,7 +268,7 @@ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() {
} else if (elem.isSquareCorner()) {
this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('H', bottomRow.xPos);
} else if (elem.isRoundedCorner()) {
this.outlinePath_ += Blockly.blockRendering.constants.OUTSIDE_CORNERS.bottomLeft;
this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.bottomLeft;
} else if (elem.isSpacer()) {
this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('h', elem.width * -1);
}
@@ -399,13 +400,13 @@ Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = functio
if (input.connection) {
// xPos already contains info about startX
var connX = input.xPos + input.connectionWidth +
Blockly.blockRendering.constants.DARK_PATH_OFFSET;
this.constants_.DARK_PATH_OFFSET;
if (this.info_.RTL) {
connX *= -1;
}
input.connection.setOffsetInBlock(
connX, yPos + input.connectionOffsetY +
Blockly.blockRendering.constants.DARK_PATH_OFFSET);
this.constants_.DARK_PATH_OFFSET);
}
};
@@ -425,7 +426,7 @@ Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = func
}
connX += 0.5;
input.connection.setOffsetInBlock(connX,
row.yPos + Blockly.blockRendering.constants.DARK_PATH_OFFSET);
row.yPos + this.constants_.DARK_PATH_OFFSET);
}
};
@@ -440,7 +441,7 @@ Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = funct
var input = row.getLastInput();
if (input.connection) {
var connX = row.xPos + row.width +
Blockly.blockRendering.constants.DARK_PATH_OFFSET;
this.constants_.DARK_PATH_OFFSET;
if (this.info_.RTL) {
connX *= -1;
}
@@ -474,7 +475,7 @@ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() {
var connX = (this.info_.RTL ? -x : x) + 0.5;
connInfo.connectionModel.setOffsetInBlock(
connX, (connInfo.centerline - connInfo.height / 2) +
Blockly.blockRendering.constants.DARK_PATH_OFFSET);
this.constants_.DARK_PATH_OFFSET);
}
};

View File

@@ -28,7 +28,6 @@ goog.provide('Blockly.blockRendering.Debug');
goog.require('Blockly.blockRendering.RenderInfo');
goog.require('Blockly.blockRendering.Highlighter');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.BottomRow');
goog.require('Blockly.blockRendering.InputRow');

View File

@@ -62,6 +62,7 @@ Blockly.blockRendering.Highlighter = function(info, pathObject) {
this.RTL_ = this.info_.RTL;
this.constants_ = Blockly.blockRendering.getConstants();
/**
* The offset between the block's main path and highlight path.
* @type {number}

View File

@@ -26,7 +26,6 @@
goog.provide('Blockly.blockRendering.RenderInfo');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.BottomRow');
goog.require('Blockly.blockRendering.InputRow');
@@ -147,6 +146,7 @@ Blockly.blockRendering.RenderInfo = function(block) {
this.startX = 0;
this.startY = 0;
this.constants_ = Blockly.blockRendering.getConstants();
this.measure_();
};
@@ -311,15 +311,15 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne
// Between inputs and the end of the row.
if (prev && prev.isInput && !next) {
if (prev.isExternalInput()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
} else if (prev.isInlineInput()) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
} else if (prev.isStatementInput()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
}
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
};
/**
@@ -466,7 +466,7 @@ Blockly.blockRendering.RenderInfo.prototype.getSpacerRowWidth_ = function(prev,
*/
Blockly.blockRendering.RenderInfo.prototype.getSpacerRowHeight_ = function(
_prev, _next) {
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
};
/**

View File

@@ -51,3 +51,7 @@ Blockly.blockRendering.render = function(block) {
var info = new Blockly.geras.RenderInfo(block);
new Blockly.blockRendering.Drawer(block, info).draw_();
};
Blockly.blockRendering.getConstants = function() {
return Blockly.blockRendering.constants;
};

View File

@@ -1,7 +1,6 @@
goog.provide('Blockly.blockRendering.InRowSpacer');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.Measurable');
/**
@@ -34,8 +33,8 @@ goog.inherits(Blockly.blockRendering.Icon, Blockly.blockRendering.Measurable);
Blockly.blockRendering.JaggedEdge = function() {
Blockly.blockRendering.JaggedEdge.superClass_.constructor.call(this);
this.type = 'jagged edge';
this.height = Blockly.blockRendering.constants.JAGGED_TEETH.height;
this.width = Blockly.blockRendering.constants.JAGGED_TEETH.width;
this.height = this.constants_.JAGGED_TEETH.height;
this.width = this.constants_.JAGGED_TEETH.width;
};
goog.inherits(Blockly.blockRendering.JaggedEdge, Blockly.blockRendering.Measurable);
@@ -73,8 +72,8 @@ goog.inherits(Blockly.blockRendering.Field, Blockly.blockRendering.Measurable);
Blockly.blockRendering.Hat = function() {
Blockly.blockRendering.Hat.superClass_.constructor.call(this);
this.type = 'hat';
this.height = Blockly.blockRendering.constants.START_HAT.height;
this.width = Blockly.blockRendering.constants.START_HAT.width;
this.height = this.constants_.START_HAT.height;
this.width = this.constants_.START_HAT.width;
this.startY = this.height;
};
@@ -91,7 +90,7 @@ Blockly.blockRendering.SquareCorner = function() {
Blockly.blockRendering.SquareCorner.superClass_.constructor.call(this);
this.type = 'square corner';
this.height = this.notchShape.height;
this.width = Blockly.blockRendering.constants.NO_PADDING;
this.width = this.constants_.NO_PADDING;
};
goog.inherits(Blockly.blockRendering.SquareCorner, Blockly.blockRendering.Measurable);
@@ -106,7 +105,7 @@ goog.inherits(Blockly.blockRendering.SquareCorner, Blockly.blockRendering.Measur
Blockly.blockRendering.RoundCorner = function() {
Blockly.blockRendering.RoundCorner.superClass_.constructor.call(this);
this.type = 'round corner';
this.width = Blockly.blockRendering.constants.CORNER_RADIUS;
this.width = this.constants_.CORNER_RADIUS;
// The rounded corner extends into the next row by 4 so we only take the
// height that is aligned with this row.
this.height = this.notchShape.height;
@@ -123,9 +122,10 @@ goog.inherits(Blockly.blockRendering.RoundCorner, Blockly.blockRendering.Measura
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.InRowSpacer = function(width) {
Blockly.blockRendering.InRowSpacer.superClass_.constructor.call(this);
this.type = 'in-row spacer';
this.width = width;
this.height = Blockly.blockRendering.constants.SPACER_DEFAULT_HEIGHT;
this.height = this.constants_.SPACER_DEFAULT_HEIGHT;
};
goog.inherits(Blockly.blockRendering.InRowSpacer,
Blockly.blockRendering.Measurable);

View File

@@ -29,7 +29,6 @@ goog.provide('Blockly.geras');
goog.provide('Blockly.geras.RenderInfo');
goog.require('Blockly.blockRendering.RenderInfo');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.BottomRow');
goog.require('Blockly.blockRendering.InputRow');
@@ -91,56 +90,56 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
if (!prev) {
// Between an editable field and the beginning of the row.
if (next.isField() && next.isEditable) {
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
}
// Inline input at the beginning of the row.
if (next.isInput && next.isInlineInput()) {
return Blockly.blockRendering.constants.MEDIUM_LARGE_PADDING;
return this.constants_.MEDIUM_LARGE_PADDING;
}
if (next.isStatementInput()) {
return Blockly.blockRendering.constants.STATEMENT_INPUT_PADDING_LEFT;
return this.constants_.STATEMENT_INPUT_PADDING_LEFT;
}
// Anything else at the beginning of the row.
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Spacing between a non-input and the end of the row.
if (!prev.isInput && !next) {
// Between an editable field and the end of the row.
if (prev.isField() && prev.isEditable) {
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
}
// Padding at the end of an icon-only row to make the block shape clearer.
if (prev.isIcon()) {
return (Blockly.blockRendering.constants.LARGE_PADDING * 2) + 1;
return (this.constants_.LARGE_PADDING * 2) + 1;
}
if (prev.isHat()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
// Establish a minimum width for a block with a previous or next connection.
if (prev.isPreviousConnection() || prev.isNextConnection()) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Between rounded corner and the end of the row.
if (prev.isRoundedCorner()) {
return Blockly.blockRendering.constants.MIN_BLOCK_WIDTH;
return this.constants_.MIN_BLOCK_WIDTH;
}
// Between a jagged edge and the end of the row.
if (prev.isJaggedEdge()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
// Between noneditable fields and icons and the end of the row.
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Between inputs and the end of the row.
if (prev.isInput && !next) {
if (prev.isExternalInput()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
} else if (prev.isInlineInput()) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
} else if (prev.isStatementInput()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
}
@@ -149,42 +148,42 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
// Between an editable field and an input.
if (prev.isEditable) {
if (next.isInlineInput()) {
return Blockly.blockRendering.constants.SMALL_PADDING;
return this.constants_.SMALL_PADDING;
} else if (next.isExternalInput()) {
return Blockly.blockRendering.constants.SMALL_PADDING;
return this.constants_.SMALL_PADDING;
}
} else {
if (next.isInlineInput()) {
return Blockly.blockRendering.constants.MEDIUM_LARGE_PADDING;
return this.constants_.MEDIUM_LARGE_PADDING;
} else if (next.isExternalInput()) {
return Blockly.blockRendering.constants.MEDIUM_LARGE_PADDING;
return this.constants_.MEDIUM_LARGE_PADDING;
} else if (next.isStatementInput()) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
}
return Blockly.blockRendering.constants.LARGE_PADDING - 1;
return this.constants_.LARGE_PADDING - 1;
}
// Spacing between an icon and an icon or field.
if (prev.isIcon() && !next.isInput) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Spacing between an inline input and a field.
if (prev.isInlineInput() && !next.isInput) {
// Editable field after inline input.
if (next.isEditable) {
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
} else {
// Noneditable field after inline input.
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
}
if (prev.isSquareCorner()) {
// Spacing between a hat and a corner
if (next.isHat()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
// Spacing between a square corner and a previous or next connection
if (next.isPreviousConnection()) {
@@ -193,7 +192,7 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
// 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;
this.constants_.DARK_PATH_OFFSET / 2;
return next.notchOffset + offset;
}
}
@@ -201,27 +200,27 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
// Spacing between a rounded corner and a previous or next connection.
if (prev.isRoundedCorner()) {
if (next.isPreviousConnection()) {
return next.notchOffset - Blockly.blockRendering.constants.CORNER_RADIUS;
return next.notchOffset - this.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 next.notchOffset - Blockly.blockRendering.constants.CORNER_RADIUS + offset;
this.constants_.DARK_PATH_OFFSET / 2;
return next.notchOffset - this.constants_.CORNER_RADIUS + offset;
}
}
// Spacing between two fields of the same editability.
if (!prev.isInput && !next.isInput && (prev.isEditable == next.isEditable)) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Spacing between anything and a jagged edge.
if (next.isJaggedEdge()) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
};
/**
@@ -239,7 +238,7 @@ Blockly.geras.RenderInfo.prototype.alignRowElements_ = function() {
var desiredWidth = this.width - this.startX;
}
if (row.type == 'bottom row' && row.hasFixedWidth) {
desiredWidth = Blockly.blockRendering.constants.MAX_BOTTOM_WIDTH;
desiredWidth = this.constants_.MAX_BOTTOM_WIDTH;
}
var missingSpace = desiredWidth - currentWidth;
if (missingSpace) {
@@ -301,25 +300,25 @@ Blockly.geras.RenderInfo.prototype.getSpacerRowWidth_ = function(prev, next) {
Blockly.geras.RenderInfo.prototype.getSpacerRowHeight_ = function(prev, next) {
// If we have an empty block add a spacer to increase the height.
if (prev.type == 'top row' && next.type == 'bottom row') {
return Blockly.blockRendering.constants.EMPTY_BLOCK_SPACER_HEIGHT;
return this.constants_.EMPTY_BLOCK_SPACER_HEIGHT;
}
// Top and bottom rows act as a spacer so we don't need any extra padding.
if (prev.type == 'top row' || next.type == 'bottom row') {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
if (prev.hasExternalInput && next.hasExternalInput) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
if (!prev.hasStatement && next.hasStatement) {
return Blockly.blockRendering.constants.BETWEEN_STATEMENT_PADDING_Y;
return this.constants_.BETWEEN_STATEMENT_PADDING_Y;
}
if (prev.hasStatement && next.hasStatement) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
if (next.hasDummyInput) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
};
/**
@@ -330,7 +329,7 @@ Blockly.geras.RenderInfo.prototype.getElemCenterline_ = function(row, elem) {
if (elem.isField() || elem.isIcon()) {
result += (elem.height / 2);
if (row.hasInlineInput || row.hasStatement) {
result += Blockly.blockRendering.constants.TALL_INPUT_FIELD_OFFSET_Y;
result += this.constants_.TALL_INPUT_FIELD_OFFSET_Y;
}
} else if (elem.isInlineInput()) {
result += elem.height / 2;
@@ -361,9 +360,9 @@ Blockly.geras.RenderInfo.prototype.finalize_ = function() {
// Add padding to the bottom row if block height is less than minimum
var heightWithoutHat = yCursor - this.topRow.startY;
if (row == this.bottomRow &&
heightWithoutHat < Blockly.blockRendering.constants.MIN_BLOCK_HEIGHT) {
heightWithoutHat < this.constants_.MIN_BLOCK_HEIGHT) {
// But the hat height shouldn't be part of this.
var diff = Blockly.blockRendering.constants.MIN_BLOCK_HEIGHT - heightWithoutHat;
var diff = this.constants_.MIN_BLOCK_HEIGHT - heightWithoutHat;
this.bottomRow.height += diff;
yCursor += diff;
}

View File

@@ -45,32 +45,13 @@ Blockly.blockRendering.Measurable = function() {
this.xPos = 0;
this.centerline = 0;
this.constants_ = Blockly.blockRendering.getConstants();
this.connectionShape = this.constants_.PUZZLE_TAB;
this.notchShape = this.constants_.NOTCH;
this.notchOffset = this.constants_.NOTCH_OFFSET_LEFT;
};
/**
* The shape object to use when drawing input and output connections.
* TODO (#2803): Formalize type annotations for these objects.
* @type {Object}
*/
Blockly.blockRendering.Measurable.prototype.connectionShape =
Blockly.blockRendering.constants.PUZZLE_TAB;
/**
* The shape object to use when drawing previous and next connections.
* TODO (#2803): Formalize type annotations for these objects.
* @type {Object}
*/
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

@@ -29,7 +29,6 @@ goog.provide('Blockly.blockRendering.OutputConnection');
goog.provide('Blockly.blockRendering.PreviousConnection');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.RenderedConnection');
/**
@@ -63,7 +62,7 @@ Blockly.blockRendering.OutputConnection = function(connectionModel) {
this.type = 'output connection';
this.height = this.connectionShape.height;
this.width = this.connectionShape.width;
this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP;
this.connectionOffsetY = this.constants_.TAB_OFFSET_FROM_TOP;
this.startX = this.width;
};
goog.inherits(Blockly.blockRendering.OutputConnection,

View File

@@ -31,7 +31,6 @@ goog.provide('Blockly.blockRendering.ExternalValueInput');
goog.require('Blockly.blockRendering.Connection');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.constants');
/**
@@ -84,18 +83,18 @@ Blockly.blockRendering.InlineInput = function(input) {
this.type = 'inline input';
if (!this.connectedBlock) {
this.height = Blockly.blockRendering.constants.EMPTY_INLINE_INPUT_HEIGHT;
this.height = this.constants_.EMPTY_INLINE_INPUT_HEIGHT;
this.width = this.connectionShape.width +
Blockly.blockRendering.constants.EMPTY_INLINE_INPUT_PADDING;
this.constants_.EMPTY_INLINE_INPUT_PADDING;
} else {
// We allow the dark path to show on the parent block so that the child
// block looks embossed. This takes up an extra pixel in both x and y.
this.width = this.connectedBlockWidth +
Blockly.blockRendering.constants.DARK_PATH_OFFSET;
this.height = this.connectedBlockHeight + Blockly.blockRendering.constants.DARK_PATH_OFFSET;
this.constants_.DARK_PATH_OFFSET;
this.height = this.connectedBlockHeight + this.constants_.DARK_PATH_OFFSET;
}
this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP;
this.connectionOffsetY = this.constants_.TAB_OFFSET_FROM_TOP;
this.connectionHeight = this.connectionShape.height;
this.connectionWidth = this.connectionShape.width;
};
@@ -117,15 +116,15 @@ Blockly.blockRendering.StatementInput = function(input) {
this.type = 'statement input';
if (!this.connectedBlock) {
this.height = Blockly.blockRendering.constants.EMPTY_STATEMENT_INPUT_HEIGHT;
this.height = this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT;
} else {
this.height =
this.connectedBlockHeight + Blockly.blockRendering.constants.STATEMENT_BOTTOM_SPACER;
this.connectedBlockHeight + this.constants_.STATEMENT_BOTTOM_SPACER;
if (this.connectedBlock.nextConnection) {
this.height -= this.notchShape.height;
}
}
this.width = Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT +
this.width = this.constants_.NOTCH_OFFSET_LEFT +
this.notchShape.width;
};
goog.inherits(Blockly.blockRendering.StatementInput,
@@ -149,12 +148,12 @@ Blockly.blockRendering.ExternalValueInput = function(input) {
this.height = this.connectionShape.height;
} else {
this.height =
this.connectedBlockHeight - 2 * Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP;
this.connectedBlockHeight - 2 * this.constants_.TAB_OFFSET_FROM_TOP;
}
this.width = this.connectionShape.width +
Blockly.blockRendering.constants.EXTERNAL_VALUE_INPUT_PADDING;
this.constants_.EXTERNAL_VALUE_INPUT_PADDING;
this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP;
this.connectionOffsetY = this.constants_.TAB_OFFSET_FROM_TOP;
this.connectionHeight = this.connectionShape.height;
this.connectionWidth = this.connectionShape.width;
};

View File

@@ -30,7 +30,6 @@ goog.provide('Blockly.blockRendering.Row');
goog.provide('Blockly.blockRendering.SpacerRow');
goog.provide('Blockly.blockRendering.TopRow');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.InputConnection');
goog.require('Blockly.blockRendering.InRowSpacer');
goog.require('Blockly.blockRendering.Measurable');
@@ -145,24 +144,13 @@ Blockly.blockRendering.Row = function() {
* @type {boolean}
*/
this.hasJaggedEdge = false;
this.constants_ = Blockly.blockRendering.getConstants();
this.connectionShape = this.constants_.PUZZLE_TAB;
this.notchShape = this.constants_.NOTCH;
this.notchOffset = this.constants_.NOTCH_OFFSET_LEFT;
};
/**
* The shape object to use when drawing previous and next connections.
* TODO (#2803): Formalize type annotations for these objects.
* @type {Object}
*/
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
@@ -297,9 +285,9 @@ Blockly.blockRendering.TopRow.prototype.populate = function(block) {
// 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 = Blockly.blockRendering.constants.LARGE_PADDING;
this.minHeight = this.constants_.LARGE_PADDING;
} else {
this.minHeight = Blockly.blockRendering.constants.MEDIUM_PADDING;
this.minHeight = this.constants_.MEDIUM_PADDING;
}
};
@@ -380,7 +368,7 @@ Blockly.blockRendering.BottomRow.prototype.populate = function(block) {
// 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 = Blockly.blockRendering.constants.LARGE_PADDING;
this.minHeight = this.constants_.LARGE_PADDING;
} else {
this.minHeight = this.notchShape.height;
}

View File

@@ -29,7 +29,6 @@ goog.provide('Blockly.thrasos');
goog.provide('Blockly.thrasos.RenderInfo');
goog.require('Blockly.blockRendering.RenderInfo');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.BottomRow');
goog.require('Blockly.blockRendering.InputRow');
@@ -91,56 +90,56 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
if (!prev) {
// Between an editable field and the beginning of the row.
if (next.isField() && next.isEditable) {
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
}
// Inline input at the beginning of the row.
if (next.isInput && next.isInlineInput()) {
return Blockly.blockRendering.constants.MEDIUM_LARGE_PADDING;
return this.constants_.MEDIUM_LARGE_PADDING;
}
if (next.isStatementInput()) {
return Blockly.blockRendering.constants.STATEMENT_INPUT_PADDING_LEFT;
return this.constants_.STATEMENT_INPUT_PADDING_LEFT;
}
// Anything else at the beginning of the row.
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Spacing between a non-input and the end of the row.
if (!prev.isInput && !next) {
// Between an editable field and the end of the row.
if (prev.isField() && prev.isEditable) {
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
}
// Padding at the end of an icon-only row to make the block shape clearer.
if (prev.isIcon()) {
return (Blockly.blockRendering.constants.LARGE_PADDING * 2) + 1;
return (this.constants_.LARGE_PADDING * 2) + 1;
}
if (prev.isHat()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
// Establish a minimum width for a block with a previous or next connection.
if (prev.isPreviousConnection() || prev.isNextConnection()) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Between rounded corner and the end of the row.
if (prev.isRoundedCorner()) {
return Blockly.blockRendering.constants.MIN_BLOCK_WIDTH;
return this.constants_.MIN_BLOCK_WIDTH;
}
// Between a jagged edge and the end of the row.
if (prev.isJaggedEdge()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
// Between noneditable fields and icons and the end of the row.
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Between inputs and the end of the row.
if (prev.isInput && !next) {
if (prev.isExternalInput()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
} else if (prev.isInlineInput()) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
} else if (prev.isStatementInput()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
}
@@ -149,42 +148,42 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
// Between an editable field and an input.
if (prev.isEditable) {
if (next.isInlineInput()) {
return Blockly.blockRendering.constants.SMALL_PADDING;
return this.constants_.SMALL_PADDING;
} else if (next.isExternalInput()) {
return Blockly.blockRendering.constants.SMALL_PADDING;
return this.constants_.SMALL_PADDING;
}
} else {
if (next.isInlineInput()) {
return Blockly.blockRendering.constants.MEDIUM_LARGE_PADDING;
return this.constants_.MEDIUM_LARGE_PADDING;
} else if (next.isExternalInput()) {
return Blockly.blockRendering.constants.MEDIUM_LARGE_PADDING;
return this.constants_.MEDIUM_LARGE_PADDING;
} else if (next.isStatementInput()) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
}
return Blockly.blockRendering.constants.LARGE_PADDING - 1;
return this.constants_.LARGE_PADDING - 1;
}
// Spacing between an icon and an icon or field.
if (prev.isIcon() && !next.isInput) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Spacing between an inline input and a field.
if (prev.isInlineInput() && !next.isInput) {
// Editable field after inline input.
if (next.isEditable) {
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
} else {
// Noneditable field after inline input.
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
}
if (prev.isSquareCorner()) {
// Spacing between a hat and a corner
if (next.isHat()) {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
// Spacing between a square corner and a previous or next connection
if (next.isPreviousConnection()) {
@@ -193,7 +192,7 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
// 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;
this.constants_.DARK_PATH_OFFSET / 2;
return next.notchOffset + offset;
}
}
@@ -201,27 +200,27 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
// Spacing between a rounded corner and a previous or next connection.
if (prev.isRoundedCorner()) {
if (next.isPreviousConnection()) {
return next.notchOffset - Blockly.blockRendering.constants.CORNER_RADIUS;
return next.notchOffset - this.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 next.notchOffset - Blockly.blockRendering.constants.CORNER_RADIUS + offset;
this.constants_.DARK_PATH_OFFSET / 2;
return next.notchOffset - this.constants_.CORNER_RADIUS + offset;
}
}
// Spacing between two fields of the same editability.
if (!prev.isInput && !next.isInput && (prev.isEditable == next.isEditable)) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
// Spacing between anything and a jagged edge.
if (next.isJaggedEdge()) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
};
/**
@@ -239,7 +238,7 @@ Blockly.thrasos.RenderInfo.prototype.alignRowElements_ = function() {
var desiredWidth = this.width - this.startX;
}
if (row.type == 'bottom row' && row.hasFixedWidth) {
desiredWidth = Blockly.blockRendering.constants.MAX_BOTTOM_WIDTH;
desiredWidth = this.constants_.MAX_BOTTOM_WIDTH;
}
var missingSpace = desiredWidth - currentWidth;
if (missingSpace) {
@@ -299,25 +298,25 @@ Blockly.thrasos.RenderInfo.prototype.getSpacerRowWidth_ = function(prev, next) {
Blockly.thrasos.RenderInfo.prototype.getSpacerRowHeight_ = function(prev, next) {
// If we have an empty block add a spacer to increase the height.
if (prev.type == 'top row' && next.type == 'bottom row') {
return Blockly.blockRendering.constants.EMPTY_BLOCK_SPACER_HEIGHT;
return this.constants_.EMPTY_BLOCK_SPACER_HEIGHT;
}
// Top and bottom rows act as a spacer so we don't need any extra padding.
if (prev.type == 'top row' || next.type == 'bottom row') {
return Blockly.blockRendering.constants.NO_PADDING;
return this.constants_.NO_PADDING;
}
if (prev.hasExternalInput && next.hasExternalInput) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
if (!prev.hasStatement && next.hasStatement) {
return Blockly.blockRendering.constants.BETWEEN_STATEMENT_PADDING_Y;
return this.constants_.BETWEEN_STATEMENT_PADDING_Y;
}
if (prev.hasStatement && next.hasStatement) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
if (next.hasDummyInput) {
return Blockly.blockRendering.constants.LARGE_PADDING;
return this.constants_.LARGE_PADDING;
}
return Blockly.blockRendering.constants.MEDIUM_PADDING;
return this.constants_.MEDIUM_PADDING;
};
/**
@@ -326,7 +325,7 @@ Blockly.thrasos.RenderInfo.prototype.getSpacerRowHeight_ = function(prev, next)
Blockly.thrasos.RenderInfo.prototype.getElemCenterline_ = function(row, elem) {
var result = row.yPos;
if (elem.isField() && row.hasStatement) {
var offset = Blockly.blockRendering.constants.TALL_INPUT_FIELD_OFFSET_Y +
var offset = this.constants_.TALL_INPUT_FIELD_OFFSET_Y +
elem.height / 2;
result += offset;
} else if (elem.isNextConnection()) {
@@ -356,9 +355,9 @@ Blockly.thrasos.RenderInfo.prototype.finalize_ = function() {
// Add padding to the bottom row if block height is less than minimum
var heightWithoutHat = yCursor - this.topRow.startY;
if (row == this.bottomRow &&
heightWithoutHat < Blockly.blockRendering.constants.MIN_BLOCK_HEIGHT) {
heightWithoutHat < this.constants_.MIN_BLOCK_HEIGHT) {
// But the hat height shouldn't be part of this.
var diff = Blockly.blockRendering.constants.MIN_BLOCK_HEIGHT - heightWithoutHat;
var diff = this.constants_.MIN_BLOCK_HEIGHT - heightWithoutHat;
this.bottomRow.height += diff;
yCursor += diff;
}

View File

@@ -29,7 +29,6 @@ goog.provide('Blockly.zelos');
goog.provide('Blockly.zelos.RenderInfo');
goog.require('Blockly.blockRendering.RenderInfo');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.BottomRow');
goog.require('Blockly.blockRendering.InputRow');