Skip to content

Commit

Permalink
Release v3.20191014.4 #3342 (#3358)
Browse files Browse the repository at this point in the history
* Dummy input right alignment (#3342)

* Fix dummy input alignment in geras.

* Rebuild
  • Loading branch information
samelhusseini authored Oct 28, 2019
1 parent 1a4c321 commit ba6dfd8
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 41 deletions.
19 changes: 11 additions & 8 deletions blockly_compressed.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions core/renderers/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ Blockly.blockRendering.ConstantProvider = function() {

this.EMPTY_BLOCK_SPACER_HEIGHT = 16;

/**
* The minimum height of a dummy input row.
* @type {number}
*/
this.DUMMY_INPUT_MIN_HEIGHT = this.TAB_HEIGHT;

/**
* Rounded corner radius.
* @type {number}
Expand Down
3 changes: 3 additions & 0 deletions core/renderers/common/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,11 @@ Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRo
} else if (input.type == Blockly.DUMMY_INPUT) {
// Dummy inputs have no visual representation, but the information is still
// important.
activeRow.minHeight = Math.max(activeRow.minHeight,
this.constants_.DUMMY_INPUT_MIN_HEIGHT);
activeRow.hasDummyInput = true;
}
activeRow.align = input.align;
};

/**
Expand Down
71 changes: 56 additions & 15 deletions core/renderers/geras/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,49 @@ Blockly.geras.RenderInfo.prototype.addInput_ = function(input, activeRow) {
} else if (input.type == Blockly.DUMMY_INPUT) {
// Dummy inputs have no visual representation, but the information is still
// important.
activeRow.minHeight = Math.max(activeRow.minHeight,
this.constants_.DUMMY_INPUT_MIN_HEIGHT);
activeRow.hasDummyInput = true;
}
activeRow.align = input.align;
};

/**
* @override
*/
Blockly.geras.RenderInfo.prototype.addElemSpacing_ = function() {
var hasExternalInputs = false;
for (var i = 0, row; (row = this.rows[i]); i++) {
if (row.hasExternalInput) {
hasExternalInputs = true;
}
}
for (var i = 0, row; (row = this.rows[i]); i++) {
var oldElems = row.elements;
row.elements = [];
// No spacing needed before the corner on the top row or the bottom row.
if (row.startsWithElemSpacer()) {
// There's a spacer before the first element in the row.
row.elements.push(new Blockly.blockRendering.InRowSpacer(
this.constants_, this.getInRowSpacing_(null, oldElems[0])));
}
for (var e = 0; e < oldElems.length - 1; e++) {
row.elements.push(oldElems[e]);
var spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]);
row.elements.push(
new Blockly.blockRendering.InRowSpacer(this.constants_, spacing));
}
row.elements.push(oldElems[oldElems.length - 1]);
if (row.endsWithElemSpacer()) {
var spacing = this.getInRowSpacing_(oldElems[oldElems.length - 1], null);
if (hasExternalInputs && row.hasDummyInput) {
spacing += this.constants_.TAB_WIDTH;
}
// There's a spacer after the last element in the row.
row.elements.push(new Blockly.blockRendering.InRowSpacer(
this.constants_, spacing));
}
}
};

/**
Expand Down Expand Up @@ -252,22 +293,19 @@ Blockly.geras.RenderInfo.prototype.addAlignmentPadding_ = function(row, missingS
row.widthWithConnectedBlocks += missingSpace;
}

var input = row.getLastInput();
if (input) {
// Decide where the extra padding goes.
if (input.align == Blockly.ALIGN_LEFT) {
// Add padding to the end of the row.
lastSpacer.width += missingSpace;
} else if (input.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 (input.align == Blockly.ALIGN_RIGHT) {
// Add padding at the beginning of the row.
firstSpacer.width += 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 if there's no input to say where to align.
// Default to left-aligning.
lastSpacer.width += missingSpace;
}
row.width += missingSpace;
Expand Down Expand Up @@ -299,6 +337,9 @@ Blockly.geras.RenderInfo.prototype.getSpacerRowHeight_ = function(prev, next) {
if (!prev.hasStatement && next.hasDummyInput) {
return this.constants_.LARGE_PADDING;
}
if (prev.hasDummyInput) {
return this.constants_.LARGE_PADDING;
}
return this.constants_.MEDIUM_PADDING;
};

Expand Down
69 changes: 52 additions & 17 deletions core/renderers/thrasos/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,44 @@ Blockly.thrasos.RenderInfo.prototype.getRenderer = function() {
return /** @type {!Blockly.thrasos.Renderer} */ (this.renderer_);
};

/**
* @override
*/
Blockly.thrasos.RenderInfo.prototype.addElemSpacing_ = function() {
var hasExternalInputs = false;
for (var i = 0, row; (row = this.rows[i]); i++) {
if (row.hasExternalInput) {
hasExternalInputs = true;
}
}
for (var i = 0, row; (row = this.rows[i]); i++) {
var oldElems = row.elements;
row.elements = [];
// No spacing needed before the corner on the top row or the bottom row.
if (row.startsWithElemSpacer()) {
// There's a spacer before the first element in the row.
row.elements.push(new Blockly.blockRendering.InRowSpacer(
this.constants_, this.getInRowSpacing_(null, oldElems[0])));
}
for (var e = 0; e < oldElems.length - 1; e++) {
row.elements.push(oldElems[e]);
var spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]);
row.elements.push(
new Blockly.blockRendering.InRowSpacer(this.constants_, spacing));
}
row.elements.push(oldElems[oldElems.length - 1]);
if (row.endsWithElemSpacer()) {
var spacing = this.getInRowSpacing_(oldElems[oldElems.length - 1], null);
if (hasExternalInputs && row.hasDummyInput) {
spacing += this.constants_.TAB_WIDTH;
}
// There's a spacer after the last element in the row.
row.elements.push(new Blockly.blockRendering.InRowSpacer(
this.constants_, spacing));
}
}
};

/**
* @override
*/
Expand Down Expand Up @@ -211,23 +249,20 @@ Blockly.thrasos.RenderInfo.prototype.addAlignmentPadding_ = function(row, missin
if (row.hasExternalInput || row.hasStatement) {
row.widthWithConnectedBlocks += missingSpace;
}

var input = row.getLastInput();
if (input) {
// Decide where the extra padding goes.
if (input.align == Blockly.ALIGN_LEFT) {
// Add padding to the end of the row.
lastSpacer.width += missingSpace;
} else if (input.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 (input.align == Blockly.ALIGN_RIGHT) {
// Add padding at the beginning of the row.
firstSpacer.width += 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 if there's no input to say where to align.
// Default to left-aligning.
lastSpacer.width += missingSpace;
}
row.width += missingSpace;
Expand Down Expand Up @@ -257,7 +292,7 @@ Blockly.thrasos.RenderInfo.prototype.getSpacerRowHeight_ = function(
if (prev.hasStatement && next.hasStatement) {
return this.constants_.LARGE_PADDING;
}
if (next.hasDummyInput) {
if (prev.hasDummyInput || next.hasDummyInput) {
return this.constants_.LARGE_PADDING;
}
return this.constants_.MEDIUM_PADDING;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockly",
"version": "3.20191014.3",
"version": "3.20191014.4",
"description": "Blockly is a library for building visual programming editors.",
"keywords": [
"blockly"
Expand Down
81 changes: 81 additions & 0 deletions tests/blocks/test_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
"nextStatement": null,
"style": "math_blocks"
},
{
"type": "test_basic_dummy",
"message0": "dummy input %1",
"args0": [
{
"type": "input_dummy"
}
],
"style": "math_blocks"
},
{
"type": "test_basic_multiple_dummy",
"message0": "first dummy %1 second dummy %2",
"args0": [
{
"type": "input_dummy"
},
{
"type": "input_dummy"
}
],
"style": "math_blocks"
},
{
"type": "test_basic_row",
"message0": "row block %1",
Expand Down Expand Up @@ -124,6 +147,64 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
"colour": 200,
"tooltip": "Hello world."
},
{
"type": "test_align_dummy_right",
"message0": "text %1 long text %2",
"args0": [
{
"type": "input_dummy",
"align": "RIGHT",
},
{
"type": "input_dummy",
"align": "RIGHT",
},
],
"style": "math_blocks"
},
{
"type": "test_align_all",
"message0": "text %1 long text %2 text %3 much longer text",
"args0": [
{
"type": "input_dummy",
"align": "LEFT",
},
{
"type": "input_dummy",
"align": "CENTRE",
},
{
"type": "input_dummy",
"align": "RIGHT",
},
],
"style": "math_blocks"
},
{
"type": "test_align_with_external_input",
"message0": "text %1 long text %2 text %3 much longer text %4",
"args0": [
{
"type": "input_dummy",
"align": "RIGHT",
},
{
"type": "input_dummy",
"align": "CENTRE",
},
{
"type": "input_dummy",
"align": "LEFT",
},
{
"type": "input_value",
"name": "VALUE"
},
],
"inputsInline": false,
"style": "math_blocks"
},
{
"type": "test_dropdowns_long",
"message0": "long: %1",
Expand Down
7 changes: 7 additions & 0 deletions tests/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,8 @@ <h1>Blockly Playground</h1>
<category name="Basic">
<block type="test_basic_empty"></block>
<block type="test_basic_empty_with_mutator"></block>
<block type="test_basic_dummy"></block>
<block type="test_basic_multiple_dummy"></block>
<block type="test_basic_stack"></block>
<block type="test_basic_row"></block>
<block type="test_basic_value_to_stack"></block>
Expand All @@ -1361,6 +1363,11 @@ <h1>Blockly Playground</h1>
<block type="test_basic_tooltips"></block>
<block type="test_basic_javascript"></block>
</category>
<category name="Align">
<block type="test_align_dummy_right"></block>
<block type="test_align_all"></block>
<block type="test_align_with_external_input"></block>
</category>
<category name="Drag">
<label text="Drag each to the workspace"></label>
<block type="text_print">
Expand Down

0 comments on commit ba6dfd8

Please sign in to comment.