field_angle renders degree symbol consistently.

Fixes #973
This commit is contained in:
marisaleung
2017-04-13 17:46:53 -07:00
parent f19b2c87aa
commit bc1ca547a4

View File

@@ -93,13 +93,35 @@ Blockly.FieldAngle.OFFSET = 0;
*/
Blockly.FieldAngle.WRAP = 360;
/**
* Radius of protractor circle. Slightly smaller than protractor size since
* otherwise SVG crops off half the border at the edges.
*/
Blockly.FieldAngle.RADIUS = Blockly.FieldAngle.HALF - 1;
/**
* Adds degree symbol and recalculates width.
* Saves the computed width in a property.
* @private
*/
Blockly.FieldAngle.prototype.render_ = function() {
if (!this.visible_) {
this.size_.width = 0;
return;
}
// Update textElement.
this.textElement_.textContent = this.getDisplayText_();
// Insert degree symbol.
if (this.sourceBlock_.RTL) {
this.textElement_.insertBefore(this.symbol_, this.textElement_.firstChild);
} else {
this.textElement_.appendChild(this.symbol_);
}
this.updateWidth();
};
/**
* Clean up this FieldAngle, as well as the inherited FieldTextInput.
* @return {!Function} Closure to call on destruction of the WidgetDiv.
@@ -233,12 +255,6 @@ Blockly.FieldAngle.prototype.setText = function(text) {
return;
}
this.updateGraph_();
// Insert degree symbol.
if (this.sourceBlock_.RTL) {
this.textElement_.insertBefore(this.symbol_, this.textElement_.firstChild);
} else {
this.textElement_.appendChild(this.symbol_);
}
// Cached width is obsolete. Clear it.
this.size_.width = 0;
};
@@ -301,4 +317,4 @@ Blockly.FieldAngle.prototype.classValidator = function(text) {
n -= 360;
}
return String(n);
};
};