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

Refactor top row #2472

Merged
merged 7 commits into from
May 22, 2019
Merged

Conversation

alschmiedt
Copy link
Contributor

The basics

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

The details

Resolves

Proposed Changes

Refactors the top row to inherit from Row instead of Measurable. Top row is now treated like a row and has an elements list with measurables such as corners, previous connection, and hats.

Reason for Changes

It makes more sense for the top row to be treated like a row.

Test Coverage

Tested on:

Additional Information

@@ -127,6 +127,8 @@ Blockly.BlockRendering.RenderInfo.prototype.measure_ = function() {
*/
Blockly.BlockRendering.RenderInfo.prototype.createRows_ = function() {
var activeRow = new Blockly.BlockRendering.Row();
this.topRow = this.createTopRow_();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move these above the activeRow line, so that it's clear that the activeRow will come after these.

Do we still need this.topRow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use it in the draw function and draw highlight function so I think it is probably worth it to keep it around? It seems cleaner than getting the first element in the list of rows every time.

/**
* Create the top row and fill the elements list with the correct measurables
* based on values from the block.
* @return {Blockly.BlockRendering.TopRow} The top row with all the elements
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why return? I expected you to just set this.topRow inside this function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

With all non-spacer elements created.

@@ -292,6 +337,23 @@ Blockly.BlockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne
}
}

// Spacing between a hat and a corner
if (prev.isRoundedCorner() || prev.isSquareCorner()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't even have a rounded corner preceding a hat.

@@ -356,7 +418,11 @@ Blockly.BlockRendering.RenderInfo.prototype.alignRowElements_ = function() {
var desiredWidth = this.width;
var missingSpace = desiredWidth - currentWidth;
if (missingSpace) {
this.addAlignmentPadding_(row, missingSpace);
if (row.type === 'top row') {
row.getLastSpacer().width += missingSpace;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like it belongs in addAlignmentPadding.

@@ -26,6 +26,15 @@ Blockly.BlockRendering.Measurable.prototype.isField = function() {
return this.type == 'field';
};

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note for later: we may remove these helper functions if all of them end up being direct checks against types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made a gnosis ticket in cleanup section and added todo

*/
Blockly.BlockRendering.PreviousConnection = function() {
Blockly.BlockRendering.PreviousConnection.superClass_.constructor.call(this);
this.renderRect = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you're not using renderRect, remove it. On render/collab it's only ever set to null, and never used.

Blockly.BlockRendering.PreviousConnection.superClass_.constructor.call(this);
this.renderRect = null;
this.type = 'previous connection';
this.height = BRC.MEDIUM_PADDING;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a new constant for this height. BRC.STACK_CONNECTION_HEIGHT, maybe? Use it here and for NextConnection, and set it equal to BRC.MEDIUM_PADDING. Changing connection height/shapes is a common tweak for rendering.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or `NOTCH_HEIGHT, since we seem to be calling those 'notches'

Blockly.BlockRendering.Hat.superClass_.constructor.call(this);
this.renderRect = null;
this.type = 'hat';
this.height = BRC.MEDIUM_PADDING;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a separate constant for this height as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

...though actually, this isn't the height up, right? It's the height down into the row? If so, does this need to have any height at all, or can we say its height is 0?

Blockly.BlockRendering.RoundCorner.superClass_.constructor.call(this);
this.renderRect = null;
this.type = 'round corner';
this.width = 8;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use constants.

Blockly.BlockRendering.TopRow = function(block) {
Blockly.BlockRendering.TopRow.superClass_.constructor.call(this);

this.elements = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

this.elements has already been created in the Row constructor.


if (squareCorner) {
this.topRow.elements.push(
new Blockly.BlockRendering.SquareCorner(this.width));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Get rid of unused width, here and on other measurables

Copy link
Collaborator

@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

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

One change then lgtm.

@alschmiedt alschmiedt merged commit fc5b501 into google:render/collab May 22, 2019
@alschmiedt alschmiedt deleted the refactor_topRow branch May 29, 2020 15:36
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