mirror of
https://github.com/google/blockly.git
synced 2026-01-08 17:40:09 +01:00
Add getCorrectedSize functions to fields
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
12
core/icon.js
12
core/icon.js
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user