Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make alignment common renderer behaviour #3498

Merged
merged 2 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions core/renderers/common/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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;
if (row.hasExternalInput || row.hasStatement) {
row.widthWithConnectedBlocks += missingSpace;
}
}
row.width += missingSpace;
};

/**
Expand Down
28 changes: 0 additions & 28 deletions core/renderers/geras/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
28 changes: 0 additions & 28 deletions core/renderers/thrasos/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
17 changes: 0 additions & 17 deletions core/renderers/zelos/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/blocks/test_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down