Add json property for adding a checkbox in the flyout

This commit is contained in:
Rachel Fenichel 2016-06-29 13:38:07 -07:00
parent ef283c8537
commit c79f4929dd
3 changed files with 32 additions and 5 deletions

View file

@ -86,7 +86,8 @@ Blockly.Blocks['operator_subtract'] = {
"colour": Blockly.Colours.operators.primary,
"colourSecondary": Blockly.Colours.operators.secondary,
"colourTertiary": Blockly.Colours.operators.tertiary,
"outputShape": Blockly.OUTPUT_SHAPE_ROUND
"outputShape": Blockly.OUTPUT_SHAPE_ROUND,
"checkboxInFlyout": true
});
}
};
@ -201,7 +202,8 @@ Blockly.Blocks['operator_lt'] = {
"colour": Blockly.Colours.operators.primary,
"colourSecondary": Blockly.Colours.operators.secondary,
"colourTertiary": Blockly.Colours.operators.tertiary,
"outputShape": Blockly.OUTPUT_SHAPE_HEXAGONAL
"outputShape": Blockly.OUTPUT_SHAPE_HEXAGONAL,
"checkboxInFlyout": true
});
}
};

View file

@ -118,6 +118,12 @@ Blockly.Block = function(workspace, prototypeName, opt_id) {
*/
this.collapsed_ = false;
/**
* @type {boolean}
* @private
*/
this.checkboxInFlyout_ = false;
/** @type {string|Blockly.Comment} */
this.comment = null;
@ -1127,6 +1133,9 @@ Blockly.Block.prototype.jsonInit = function(json) {
if (json['outputShape'] !== undefined) {
this.setOutputShape(json['outputShape']);
}
if (json['checkboxInFlyout'] !== undefined) {
this.setCheckboxInFlyout(json['checkboxInFlyout']);
}
};
/**
@ -1423,7 +1432,8 @@ Blockly.Block.prototype.setCommentText = function(text) {
/**
* Set this block's output shape.
* e.g., null, OUTPUT_SHAPE_HEXAGONAL, OUTPUT_SHAPE_ROUND, OUTPUT_SHAPE_SQUARE.
* @param {?number} outputShape Value representing output shape (see constants.js).
* @param {?number} outputShape Value representing output shape
* (see constants.js).
*/
Blockly.Block.prototype.setOutputShape = function(outputShape) {
this.outputShape_ = outputShape;
@ -1437,6 +1447,22 @@ Blockly.Block.prototype.getOutputShape = function() {
return this.outputShape_;
};
/**
* Set whether this block has a checkbox next to it in the flyout.
* @param {boolean} hasCheckbox True if this block should have a checkbox.
*/
Blockly.Block.prototype.setCheckboxInFlyout = function(hasCheckbox) {
this.checkboxInFlyout_ = hasCheckbox;
};
/**
* Get whether this block has a checkbox next to it in the flyout.
* @return {boolean} True if this block should have a checkbox.
*/
Blockly.Block.prototype.hasCheckboxInFlyout = function() {
return this.checkboxInFlyout_;
};
/**
* Set this block's warning text.
* @param {?string} text The text, or null to delete.

View file

@ -701,8 +701,7 @@ Blockly.Flyout.prototype.layoutBlocks_ = function(blocks, gaps) {
}
var root = block.getSvgRoot();
var blockHW = block.getHeightWidth();
if (!this.horizontalLayout_ &&
block.previousConnection && block.nextConnection) {
if (!this.horizontalLayout_ && block.hasCheckboxInFlyout()) {
this.createCheckbox_(block, cursorX, cursorY, blockHW);
block.moveBy(cursorX + this.CHECKBOX_SIZE + this.CHECKBOX_MARGIN,
cursorY);