From f469a388edb8c9180674329e9427e1932d1576b2 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 17 Jul 2019 11:00:20 -0700 Subject: [PATCH 1/2] Add getCorrectedSize functions to fields --- core/field.js | 9 +++++++++ core/field_checkbox.js | 12 ++++++++++++ core/field_colour.js | 16 ++++++++++++++++ core/field_dropdown.js | 13 +++++++++++++ core/field_image.js | 16 ++++++++++++++++ core/field_label.js | 12 ++++++++++++ core/field_textinput.js | 12 ++++++++++++ core/icon.js | 12 ++++++++++++ 8 files changed, 102 insertions(+) diff --git a/core/field.js b/core/field.js index e0d20035e..e6b24207d 100644 --- a/core/field.js +++ b/core/field.js @@ -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. diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 82f281cad..f82a718c2 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -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); diff --git a/core/field_colour.js b/core/field_colour.js index 5f26899ad..7835822be 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -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); diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 7d070cfe0..46144acc4 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -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); diff --git a/core/field_image.js b/core/field_image.js index bd5a56ae1..615de00f3 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -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); diff --git a/core/field_label.js b/core/field_label.js index efeeb1e6c..6cab5af77 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -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); diff --git a/core/field_textinput.js b/core/field_textinput.js index c525b5c9c..f00ec6d01 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -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); diff --git a/core/icon.js b/core/icon.js index 73f3df609..39e6accc1 100644 --- a/core/icon.js +++ b/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); +}; From fc4372dbc2aabe8513cb7b263ade4440054861fb Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 22 Jul 2019 16:29:44 -0700 Subject: [PATCH 2/2] Add TODOs with github issue number --- core/field.js | 1 + core/field_checkbox.js | 2 ++ core/field_colour.js | 1 + core/field_dropdown.js | 3 +++ core/field_image.js | 2 +- core/field_label.js | 3 +++ core/field_textinput.js | 1 + 7 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/field.js b/core/field.js index e6b24207d..09ac46fa2 100644 --- a/core/field.js +++ b/core/field.js @@ -650,6 +650,7 @@ Blockly.Field.prototype.getSize = function() { * @package */ Blockly.Field.prototype.getCorrectedSize = function() { + // TODO (#2562): Remove getCorrectedSize. return this.getSize(); }; diff --git a/core/field_checkbox.js b/core/field_checkbox.js index f82a718c2..070454bb7 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -218,6 +218,8 @@ Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) { */ Blockly.FieldCheckbox.prototype.getCorrectedSize = function() { this.getSize(); + + // TODO (#2562): Remove getCorrectedSize. return new goog.math.Size(this.size_.width + Blockly.BlockSvg.SEP_SPACE_X, Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT); }; diff --git a/core/field_colour.js b/core/field_colour.js index 7835822be..e9f7ca639 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -351,6 +351,7 @@ 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(); + // TODO (#2562): Remove getCorrectedSize. return new goog.math.Size( this.size_.width + Blockly.BlockSvg.SEP_SPACE_X, Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT - 1); diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 46144acc4..651c18952 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -556,6 +556,9 @@ 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(); + // This extra 9 was probably to add padding between rows. + // It's also found in render_, renderSelectedImage_, and renderSelectedText_. + // TODO (#2562): Remove getCorrectedSize. return new goog.math.Size(this.size_.width + Blockly.BlockSvg.SEP_SPACE_X, this.size_.height - 9); }; diff --git a/core/field_image.js b/core/field_image.js index 615de00f3..6f329dafb 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -201,7 +201,7 @@ Blockly.FieldImage.prototype.getCorrectedSize = function() { // 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. + // TODO (#2562): Remove getCorrectedSize. return new goog.math.Size(this.size_.width, this.height_ + 1); }; diff --git a/core/field_label.js b/core/field_label.js index 6cab5af77..c1392d3cf 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -109,6 +109,9 @@ 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(); + // This extra 5 was probably to add padding between rows. + // It's also found in the constructor and in initView. + // TODO (#2562): Remove getCorrectedSize. return new goog.math.Size(this.size_.width, this.size_.height - 5); }; diff --git a/core/field_textinput.js b/core/field_textinput.js index f00ec6d01..39c3061e2 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -441,6 +441,7 @@ 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(); + // TODO (#2562): Remove getCorrectedSize. return new goog.math.Size(this.size_.width + Blockly.BlockSvg.SEP_SPACE_X, 16); };