Align constants -> Blockly.constants.ALIGN enum

This commit is contained in:
Rachel Fenichel
2021-02-26 11:12:53 -08:00
parent eab0897b5d
commit 4e31deca2b
7 changed files with 38 additions and 39 deletions

View File

@@ -1765,10 +1765,10 @@ Blockly.Block.prototype.fieldFromJson_ = function(element) {
*/
Blockly.Block.prototype.inputFromJson_ = function(element, warningPrefix) {
var alignmentLookup = {
'LEFT': Blockly.ALIGN_LEFT,
'RIGHT': Blockly.ALIGN_RIGHT,
'CENTRE': Blockly.ALIGN_CENTRE,
'CENTER': Blockly.ALIGN_CENTRE
'LEFT': Blockly.constants.ALIGN.LEFT,
'RIGHT': Blockly.constants.ALIGN.RIGHT,
'CENTRE': Blockly.constants.ALIGN.CENTRE,
'CENTER': Blockly.constants.ALIGN.CENTRE
};
var input = null;

View File

@@ -503,3 +503,18 @@ Blockly.unbindEvent_ = Blockly.browserEvents.unbind;
* @see Blockly.browserEvents.conditionalBind
*/
Blockly.bindEventWithChecks_ = Blockly.browserEvents.conditionalBind;
/**
* @see Blockly.constants.ALIGN.LEFT
*/
Blockly.ALIGN_LEFT = Blockly.constants.ALIGN.LEFT;
/**
* @see Blockly.constants.ALIGN.CENTRE
*/
Blockly.ALIGN_CENTRE = Blockly.constants.ALIGN.CENTRE;
/**
* @see Blockly.constants.ALIGN.RIGHT
*/
Blockly.ALIGN_RIGHT = Blockly.constants.ALIGN.RIGHT;

View File

@@ -140,22 +140,14 @@ Blockly.PREVIOUS_STATEMENT = 4;
Blockly.DUMMY_INPUT = 5;
/**
* ENUM for left alignment.
* @const
* Enum for alignment of inputs.
* @enum {number}
*/
Blockly.ALIGN_LEFT = -1;
/**
* ENUM for centre alignment.
* @const
*/
Blockly.ALIGN_CENTRE = 0;
/**
* ENUM for right alignment.
* @const
*/
Blockly.ALIGN_RIGHT = 1;
Blockly.constants.ALIGN = {
LEFT: -1,
CENTRE: 0,
RIGHT: 1
};
/**
* ENUM for no drag operation.

View File

@@ -55,7 +55,7 @@ Blockly.Input = function(type, name, block, connection) {
* Alignment of input's fields (left, right or centre).
* @type {number}
*/
Blockly.Input.prototype.align = Blockly.ALIGN_LEFT;
Blockly.Input.prototype.align = Blockly.constants.ALIGN.LEFT;
/**
* Is the input visible?
@@ -242,8 +242,8 @@ Blockly.Input.prototype.setCheck = function(check) {
/**
* Change the alignment of the connection's field(s).
* @param {number} align One of Blockly.ALIGN_LEFT, ALIGN_CENTRE, ALIGN_RIGHT.
* In RTL mode directions are reversed, and ALIGN_RIGHT aligns to the left.
* @param {number} align One of the values of Blockly.constants.ALIGN.
* In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left.
* @return {!Blockly.Input} The input being modified (to allow chaining).
*/
Blockly.Input.prototype.setAlign = function(align) {

View File

@@ -591,14 +591,14 @@ Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function(row,
}
// Decide where the extra padding goes.
if (row.align == Blockly.ALIGN_LEFT) {
if (row.align == Blockly.constants.ALIGN.LEFT) {
// Add padding to the end of the row.
lastSpacer.width += missingSpace;
} else if (row.align == Blockly.ALIGN_CENTRE) {
} else if (row.align == Blockly.constants.ALIGN.CENTRE) {
// Split the padding between the beginning and end of the row.
firstSpacer.width += missingSpace / 2;
lastSpacer.width += missingSpace / 2;
} else if (row.align == Blockly.ALIGN_RIGHT) {
} else if (row.align == Blockly.constants.ALIGN.RIGHT) {
// Add padding at the beginning of the row.
firstSpacer.width += missingSpace;
} else {

View File

@@ -277,8 +277,8 @@ Blockly.zelos.RenderInfo.prototype.addInput_ = function(input, activeRow) {
// right, keep track of the right aligned dummy input so we can add padding
// later.
if (input.type == Blockly.DUMMY_INPUT && activeRow.hasDummyInput &&
activeRow.align == Blockly.ALIGN_LEFT &&
input.align == Blockly.ALIGN_RIGHT) {
activeRow.align == Blockly.constants.ALIGN.LEFT &&
input.align == Blockly.constants.ALIGN.RIGHT) {
activeRow.rightAlignedDummyInput = input;
}
Blockly.zelos.RenderInfo.superClass_.addInput_.call(this, input, activeRow);

View File

@@ -561,9 +561,7 @@ suite('Block JSON initialization', function() {
'type': 'input_dummy',
'align': 'LEFT',
},
'input_dummy',
undefined,
Blockly.ALIGN_LEFT);
'input_dummy', undefined, Blockly.constants.ALIGN.LEFT);
});
test('"Right" align', function() {
@@ -572,9 +570,7 @@ suite('Block JSON initialization', function() {
'type': 'input_dummy',
'align': 'RIGHT',
},
'input_dummy',
undefined,
Blockly.ALIGN_RIGHT);
'input_dummy', undefined, Blockly.constants.ALIGN);
});
test('"Center" align', function() {
@@ -583,9 +579,7 @@ suite('Block JSON initialization', function() {
'type': 'input_dummy',
'align': 'CENTER',
},
'input_dummy',
undefined,
Blockly.ALIGN_CENTRE);
'input_dummy', undefined, Blockly.constants..);
});
test('"Centre" align', function() {
@@ -594,9 +588,7 @@ suite('Block JSON initialization', function() {
'type': 'input_dummy',
'align': 'CENTRE',
},
'input_dummy',
undefined,
Blockly.ALIGN_CENTRE);
'input_dummy', undefined, Blockly.constants.ALIGN.CENTRE);
});
});
});