mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Merge pull request #2501 from BeksOmega/fixes/AngleFields
Angle Field Fixes
This commit is contained in:
@@ -264,16 +264,28 @@ Blockly.FieldAngle.prototype.onMouseMove = function(e) {
|
||||
} else if (dy > 0) {
|
||||
angle += 360;
|
||||
}
|
||||
|
||||
// Do offsetting.
|
||||
if (Blockly.FieldAngle.CLOCKWISE) {
|
||||
angle = Blockly.FieldAngle.OFFSET + 360 - angle;
|
||||
} else {
|
||||
angle -= Blockly.FieldAngle.OFFSET;
|
||||
angle = 360 - (Blockly.FieldAngle.OFFSET - angle);
|
||||
}
|
||||
if (angle > 360) {
|
||||
angle -= 360;
|
||||
}
|
||||
|
||||
// Do rounding.
|
||||
if (Blockly.FieldAngle.ROUND) {
|
||||
angle = Math.round(angle / Blockly.FieldAngle.ROUND) *
|
||||
Blockly.FieldAngle.ROUND;
|
||||
}
|
||||
|
||||
// Do wrapping.
|
||||
if (angle > Blockly.FieldAngle.WRAP) {
|
||||
angle -= 360;
|
||||
}
|
||||
|
||||
// Update value.
|
||||
var angleString = String(angle);
|
||||
if (angleString != this.text_) {
|
||||
@@ -295,6 +307,7 @@ Blockly.FieldAngle.prototype.updateGraph_ = function() {
|
||||
}
|
||||
// Always display the input (i.e. getText) even if it is invalid.
|
||||
var angleDegrees = Number(this.getText()) + Blockly.FieldAngle.OFFSET;
|
||||
angleDegrees %= 360;
|
||||
var angleRadians = Blockly.utils.toRadians(angleDegrees);
|
||||
var path = ['M ', Blockly.FieldAngle.HALF, ',', Blockly.FieldAngle.HALF];
|
||||
var x2 = Blockly.FieldAngle.HALF;
|
||||
@@ -334,7 +347,7 @@ Blockly.FieldAngle.prototype.doClassValidation_ = function(newValue) {
|
||||
return null;
|
||||
}
|
||||
var n = parseFloat(newValue || 0);
|
||||
n = n % 360;
|
||||
n %= 360;
|
||||
if (n < 0) {
|
||||
n += 360;
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() {
|
||||
thisField.isBeingEdited_ = false;
|
||||
// No need to call setValue because if the widget is being closed the
|
||||
// latest input text has already been validated.
|
||||
if (thisField.value_ != thisField.text_) {
|
||||
if (thisField.value_ !== thisField.text_) {
|
||||
// At the end of an edit the text should be the same as the value. It
|
||||
// may not be if the input text is different than the validated text.
|
||||
// We should fix that.
|
||||
|
||||
Reference in New Issue
Block a user