Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed How Fields Handle Size #2500

Merged
merged 1 commit into from
May 31, 2019

Conversation

BeksOmega
Copy link
Collaborator

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide

The details

Resolves

#2428 and some collapse/expand problems

Proposed Changes

  1. Makes it so visibility (return a size of 0) is handled inside getSize instead of inside setVisible.
  2. Changes (public) updateWidth to (protected) updateSize_.

Reason for Changes

  1. There were problems with collapsing when it was done the previous way. Now all blocks are expanded and collapsed correctly.
  2. Makes it less confusing for outside developers who want to create a field with a dynamic height.

Note that the dropdown field's updateWidth function wasn't getting called from anywhere, so it could be safely removed.

Test Coverage

FieldsHandleSize

I also tested collapsing and collapsing all of the default categories, and it all looks good.

Tested on:

  • Desktop Chrome
  • Desktop Firefox

Was not able to test on internet explorer or edge because of #2499

Additional Information

N/A

core/field.js Outdated
* the approximated width on IE/Edge when `getComputedTextLength` fails. Once
* it eventually does succeed, the result will be cached.
* Updates the width of the field. Redirects to updateSize_().
* @deprecated May 2019 Use Blockly.Field.getCachedWidth() directly instead.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this say to use getCachedWidth instead of updateSize_?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render_ only supports text fields. updateSize_ is only called by the default render_ function. updateSize_ also only supports text fields.

If you have a text field, there is no need to override render_, and no need to call updateSize_.

If you have an image, or mixed field you need to override render_. In this case updateSize_ will not be helpful, because it only supports text fields. But if it is a mixed field, you may still want to know the size of your text, so you should call getCachedWidth().

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, but the redirect still feels wrong to me:

  • updateWidth and updateSize have no return value, but have side effects
  • getCachedWidths has a return value and no side effects

I suggest:
@deprecated May 2019 Use Blockly.Field.updateSize_() to force an update to the size of the field, or Blockly.Field.getCachedWidth() to check the size of the field..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, Fixed.

@@ -91,6 +91,14 @@ Blockly.FieldCheckbox.prototype.SERIALIZABLE = true;
*/
Blockly.FieldCheckbox.prototype.CURSOR = 'default';

/**
* Used to tell if the field needs to render. Checkbox fields are statically
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Used to tell if the field needs to be rendered the next time the block is rendered. Checkbox fields are statically sized, and only need to be rendered at initialization."

^ If this is inaccurate, let's find a more accurate way to say it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar/the same wording for other places where you're setting isDirty to false.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* image, or if the browser is not IE / Edge, this simply calls the parent
* implementation.
*/
Blockly.FieldDropdown.prototype.updateWidth = function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't actually get called anywhere, all of the sizing logic is handled in the image and text render functions.

@rachel-fenichel rachel-fenichel merged commit d3062ba into google:develop May 31, 2019
@BeksOmega BeksOmega deleted the fixes/FieldSizeHandling branch June 2, 2019 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants