mirror of
https://github.com/google/blockly.git
synced 2026-01-05 08:00:09 +01:00
Make alignment common renderer behaviour (#3498)
* Make alignment common
This commit is contained in:
@@ -560,14 +560,28 @@ Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() {
|
||||
*/
|
||||
Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function(row,
|
||||
missingSpace) {
|
||||
var firstSpacer = row.getFirstSpacer();
|
||||
var lastSpacer = row.getLastSpacer();
|
||||
if (lastSpacer) {
|
||||
lastSpacer.width += missingSpace;
|
||||
row.width += missingSpace;
|
||||
if (row.hasExternalInput || row.hasStatement) {
|
||||
row.widthWithConnectedBlocks += missingSpace;
|
||||
}
|
||||
if (row.hasExternalInput || row.hasStatement) {
|
||||
row.widthWithConnectedBlocks += missingSpace;
|
||||
}
|
||||
|
||||
// Decide where the extra padding goes.
|
||||
if (row.align == Blockly.ALIGN_LEFT) {
|
||||
// Add padding to the end of the row.
|
||||
lastSpacer.width += missingSpace;
|
||||
} else if (row.align == Blockly.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) {
|
||||
// Add padding at the beginning of the row.
|
||||
firstSpacer.width += missingSpace;
|
||||
} else {
|
||||
// Default to left-aligning.
|
||||
lastSpacer.width += missingSpace;
|
||||
}
|
||||
row.width += missingSpace;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -307,34 +307,6 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
|
||||
return this.constants_.MEDIUM_PADDING;
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.geras.RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) {
|
||||
var firstSpacer = row.getFirstSpacer();
|
||||
var lastSpacer = row.getLastSpacer();
|
||||
if (row.hasExternalInput || row.hasStatement) {
|
||||
row.widthWithConnectedBlocks += missingSpace;
|
||||
}
|
||||
|
||||
// Decide where the extra padding goes.
|
||||
if (row.align == Blockly.ALIGN_LEFT) {
|
||||
// Add padding to the end of the row.
|
||||
lastSpacer.width += missingSpace;
|
||||
} else if (row.align == Blockly.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) {
|
||||
// Add padding at the beginning of the row.
|
||||
firstSpacer.width += missingSpace;
|
||||
} else {
|
||||
// Default to left-aligning.
|
||||
lastSpacer.width += missingSpace;
|
||||
}
|
||||
row.width += missingSpace;
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
@@ -240,34 +240,6 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) {
|
||||
return this.constants_.MEDIUM_PADDING;
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.thrasos.RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) {
|
||||
var firstSpacer = row.getFirstSpacer();
|
||||
var lastSpacer = row.getLastSpacer();
|
||||
if (row.hasExternalInput || row.hasStatement) {
|
||||
row.widthWithConnectedBlocks += missingSpace;
|
||||
}
|
||||
|
||||
// Decide where the extra padding goes.
|
||||
if (row.align == Blockly.ALIGN_LEFT) {
|
||||
// Add padding to the end of the row.
|
||||
lastSpacer.width += missingSpace;
|
||||
} else if (row.align == Blockly.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) {
|
||||
// Add padding at the beginning of the row.
|
||||
firstSpacer.width += missingSpace;
|
||||
} else {
|
||||
// Default to left-aligning.
|
||||
lastSpacer.width += missingSpace;
|
||||
}
|
||||
row.width += missingSpace;
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
@@ -199,23 +199,6 @@ Blockly.zelos.RenderInfo.prototype.getSpacerRowHeight_ = function(
|
||||
return this.constants_.MEDIUM_PADDING;
|
||||
};
|
||||
|
||||
/**
|
||||
* Modify the given row to add the given amount of padding around its fields.
|
||||
* The exact location of the padding is based on the alignment property of the
|
||||
* last input in the field.
|
||||
* @param {Blockly.blockRendering.Row} row The row to add padding to.
|
||||
* @param {number} missingSpace How much padding to add.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.zelos.RenderInfo.prototype.addAlignmentPadding_ = function(row,
|
||||
missingSpace) {
|
||||
var lastSpacer = row.getLastSpacer();
|
||||
if (lastSpacer) {
|
||||
lastSpacer.width += missingSpace;
|
||||
row.width += missingSpace;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adjust the x position of fields to bump all non-label fields in the first row
|
||||
* past the notch position. This must be called before ``computeBounds`` is
|
||||
|
||||
@@ -149,7 +149,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
|
||||
},
|
||||
{
|
||||
"type": "test_align_dummy_right",
|
||||
"message0": "text %1 long text %2",
|
||||
"message0": "text right %1 long text right %2",
|
||||
"args0": [
|
||||
{
|
||||
"type": "input_dummy",
|
||||
@@ -164,7 +164,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
|
||||
},
|
||||
{
|
||||
"type": "test_align_all",
|
||||
"message0": "text %1 long text %2 text %3 much longer text",
|
||||
"message0": "text %1 long text left %2 text centre %3 much longer text right",
|
||||
"args0": [
|
||||
{
|
||||
"type": "input_dummy",
|
||||
@@ -183,7 +183,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
|
||||
},
|
||||
{
|
||||
"type": "test_align_with_external_input",
|
||||
"message0": "text %1 long text %2 text %3 much longer text %4",
|
||||
"message0": "text right %1 long text centre %2 text left %3 much longer text %4",
|
||||
"args0": [
|
||||
{
|
||||
"type": "input_dummy",
|
||||
|
||||
Reference in New Issue
Block a user