Add getCorrectedSize functions to fields

This commit is contained in:
Rachel Fenichel
2019-07-17 11:00:20 -07:00
parent ac3c066fa9
commit f469a388ed
8 changed files with 102 additions and 0 deletions

View File

@@ -644,6 +644,15 @@ Blockly.Field.prototype.getSize = function() {
return this.size_;
};
/**
* Get the size of the visible field, as used in new rendering.
* @return {!goog.math.Size} The size of the visible field.
* @package
*/
Blockly.Field.prototype.getCorrectedSize = function() {
return this.getSize();
};
/**
* Returns the bounding box of the rendered field, accounting for workspace
* scaling.

View File

@@ -209,4 +209,16 @@ Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) {
}
};
/**
* Get the size of the visible field, as used in new rendering.
* The checkbox field fills the entire border rect, rather than just using the
* text element.
* @return {!goog.math.Size} The size of the visible field.
* @package
*/
Blockly.FieldCheckbox.prototype.getCorrectedSize = function() {
this.getSize();
return new goog.math.Size(this.size_.width + Blockly.BlockSvg.SEP_SPACE_X,
Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT);
};
Blockly.Field.register('field_checkbox', Blockly.FieldCheckbox);

View File

@@ -340,4 +340,20 @@ Blockly.FieldColour.prototype.dropdownDispose_ = function() {
Blockly.unbindEvent_(this.onUpWrapper_);
};
/**
* Get the size of the visible field, as used in new rendering.
* The colour field fills the bounding box with colour and takes up the full
* space of the bounding box.
* @return {!goog.math.Size} The size of the visible field.
* @package
*/
Blockly.FieldColour.prototype.getCorrectedSize = function() {
// getSize also renders and updates the size if needed. Rather than duplicate
// the logic to figure out whether to rerender, just call getSize.
this.getSize();
return new goog.math.Size(
this.size_.width + Blockly.BlockSvg.SEP_SPACE_X,
Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT - 1);
};
Blockly.Field.register('field_colour', Blockly.FieldColour);

View File

@@ -547,4 +547,17 @@ Blockly.FieldDropdown.validateOptions_ = function(options) {
}
};
/**
* Get the size of the visible field, as used in new rendering.
* @return {!goog.math.Size} The size of the visible field.
* @package
*/
Blockly.FieldDropdown.prototype.getCorrectedSize = function() {
// getSize also renders and updates the size if needed. Rather than duplicate
// the logic to figure out whether to rerender, just call getSize.
this.getSize();
return new goog.math.Size(this.size_.width + Blockly.BlockSvg.SEP_SPACE_X,
this.size_.height - 9);
};
Blockly.Field.register('field_dropdown', Blockly.FieldDropdown);

View File

@@ -189,4 +189,20 @@ Blockly.FieldImage.prototype.showEditor_ = function() {
}
};
/**
* Get the size of the visible field, as used in new rendering.
* @return {!goog.math.Size} The size of the visible field.
* @package
*/
Blockly.FieldImage.prototype.getCorrectedSize = function() {
// getSize also renders and updates the size if needed. Rather than duplicate
// the logic to figure out whether to rerender, just call getSize.
this.getSize();
// Old rendering adds an extra pixel under the image. We include this in the
// height of the image in new rendering, rather than having the spacer below
// know that there was an image in the previous row.
// TODO: Remove.
return new goog.math.Size(this.size_.width, this.height_ + 1);
};
Blockly.Field.register('field_image', Blockly.FieldImage);

View File

@@ -100,4 +100,16 @@ Blockly.FieldLabel.prototype.doClassValidation_ = function(newValue) {
return String(newValue);
};
/**
* Get the size of the visible field, as used in new rendering.
* @return {!goog.math.Size} The size of the visible field.
* @package
*/
Blockly.FieldLabel.prototype.getCorrectedSize = function() {
// getSize also renders and updates the size if needed. Rather than duplicate
// the logic to figure out whether to rerender, just call getSize.
this.getSize();
return new goog.math.Size(this.size_.width, this.size_.height - 5);
};
Blockly.Field.register('field_label', Blockly.FieldLabel);

View File

@@ -432,4 +432,16 @@ Blockly.FieldTextInput.nonnegativeIntegerValidator = function(text) {
return n;
};
/**
* Get the size of the visible field, as used in new rendering.
* @return {!goog.math.Size} The size of the visible field.
* @package
*/
Blockly.FieldTextInput.prototype.getCorrectedSize = function() {
// getSize also renders and updates the size if needed. Rather than duplicate
// the logic to figure out whether to rerender, just call getSize.
this.getSize();
return new goog.math.Size(this.size_.width + Blockly.BlockSvg.SEP_SPACE_X, 16);
};
Blockly.Field.register('field_input', Blockly.FieldTextInput);

View File

@@ -205,3 +205,15 @@ Blockly.Icon.prototype.computeIconLocation = function() {
Blockly.Icon.prototype.getIconLocation = function() {
return this.iconXY_;
};
/**
* Get the size of the icon as used for rendering.
* This differs from the actual size of the icon, because it bulges slightly
* out of its row rather than increasing the height of its row.
* TODO (#2562): Remove getCorrectedSize.
* @return {!goog.math.Size} Height and width.
*/
Blockly.Icon.prototype.getCorrectedSize = function() {
return new goog.math.Size(
Blockly.Icon.prototype.SIZE, Blockly.Icon.prototype.SIZE - 2);
};