[zelos] Full field colour (#3461)

* Support showing the colour value on the entire block.
This commit is contained in:
Sam El-Husseini
2019-11-22 13:50:33 -08:00
committed by GitHub
parent 14b7ee108c
commit 2a8e7d9ac8
4 changed files with 45 additions and 5 deletions

View File

@@ -969,8 +969,8 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
* @package
*/
Blockly.BlockSvg.prototype.applyColour = function() {
if (!this.isEnabled()) {
// Disabled blocks don't have colour.
if (!this.isEnabled() || !this.rendered) {
// Disabled blocks and non-rendered blocks don't have colour.
return;
}

View File

@@ -186,9 +186,24 @@ Blockly.FieldColour.prototype.initView = function() {
this.size_ = new Blockly.utils.Size(
this.constants_.FIELD_COLOUR_DEFAULT_WIDTH,
this.constants_.FIELD_COLOUR_DEFAULT_HEIGHT);
this.createBorderRect_();
this.borderRect_.style['fillOpacity'] = '1';
this.borderRect_.style.fill = this.value_;
if (!this.constants_.FIELD_COLOUR_FULL_BLOCK) {
this.createBorderRect_();
this.borderRect_.style['fillOpacity'] = '1';
} else {
this.clickTarget_ = this.sourceBlock_.getSvgRoot();
}
};
/**
* @override
*/
Blockly.FieldColour.prototype.applyColour = function() {
if (!this.constants_.FIELD_COLOUR_FULL_BLOCK) {
this.borderRect_.style.fill = this.getValue();
} else {
this.sourceBlock_.pathObject.svgPath.setAttribute('fill', this.getValue());
this.sourceBlock_.pathObject.svgPath.setAttribute('stroke', '#fff');
}
};
/**
@@ -214,6 +229,9 @@ Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) {
this.value_ = newValue;
if (this.borderRect_) {
this.borderRect_.style.fill = newValue;
} else if (this.sourceBlock_) {
this.sourceBlock_.pathObject.svgPath.setAttribute('fill', newValue);
this.sourceBlock_.pathObject.svgPath.setAttribute('stroke', '#fff');
}
};

View File

@@ -232,6 +232,13 @@ Blockly.blockRendering.ConstantProvider = function() {
*/
this.FIELD_DROPDOWN_SVG_ARROW = false;
/**
* Whether or not the colour field should display its colour value on the
* entire block.
* @type {boolean}
*/
this.FIELD_COLOUR_FULL_BLOCK = false;
/**
* A colour field's default width.
* @type {number}

View File

@@ -214,6 +214,21 @@ Blockly.zelos.ConstantProvider = function() {
'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' +
'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4=';
/**
* @override
*/
this.FIELD_COLOUR_FULL_BLOCK = true;
/**
* @override
*/
this.FIELD_COLOUR_DEFAULT_WIDTH = 2 * this.GRID_UNIT;
/**
* @override
*/
this.FIELD_COLOUR_DEFAULT_HEIGHT = 4 * this.GRID_UNIT;
/**
* The ID of the highlight glow filter, or the empty string if no filter is
* set.