-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Refactor top row #2472
Conversation
@@ -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_(); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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'; | |||
}; | |||
|
|||
/** |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 = []; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
There was a problem hiding this 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.
The basics
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