-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Implement AI indented value inputs for Blockly #3219
Changes from all commits
808ecec
7dbda65
a560859
22cb5fc
b7dabb4
ce7656e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,8 @@ Blockly.blockRendering.Drawer.prototype.drawOutline_ = function() { | |
this.drawJaggedEdge_(row); | ||
} else if (row.hasStatement) { | ||
this.drawStatementInput_(row); | ||
} else if (row.hasIndentedInput) { | ||
this.drawIndentedInput_(row); | ||
} else if (row.hasExternalInput) { | ||
this.drawValueInput_(row); | ||
} else { | ||
|
@@ -190,6 +192,30 @@ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { | |
}; | ||
|
||
|
||
/** | ||
* Add steps for an indented value input, rendered as a notch in the side | ||
* of the block but at the same X value as any statement inputs. | ||
* @param {!Blockly.blockRendering.Row} row The row that this input | ||
* belongs to. | ||
* @protected | ||
*/ | ||
Blockly.blockRendering.Drawer.prototype.drawIndentedInput_ = function(row) { | ||
var input = row.getLastInput(); | ||
this.positionIndentedValueConnection_(row); | ||
|
||
var pathDown = (typeof input.shape.pathDown == "function") ? | ||
input.shape.pathDown(input.height) : | ||
input.shape.pathDown; | ||
|
||
this.outlinePath_ += | ||
Blockly.utils.svgPaths.lineOnAxis('H', input.xPos + input.connectionWidth) + | ||
Blockly.utils.svgPaths.lineOnAxis('v', input.connectionOffsetY) + | ||
pathDown + | ||
Blockly.utils.svgPaths.lineOnAxis('v', row.height - input.connectionHeight - input.connectionOffsetY) + | ||
Blockly.utils.svgPaths.lineOnAxis('H', input.xPos + input.width); | ||
}; | ||
|
||
|
||
/** | ||
* Add steps for a statement input. | ||
* @param {!Blockly.blockRendering.Row} row The row that this input | ||
|
@@ -427,6 +453,24 @@ Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = funct | |
} | ||
}; | ||
|
||
/** | ||
* Position the connection on an indented value input, taking into account | ||
* RTL and the small gap between the parent block and child block which lets the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the comment on the small gap, since that doesn't apply for the base drawer. |
||
* parent block's dark path show through. | ||
* @param {!Blockly.blockRendering.Row} row The row that the connection is on. | ||
* @protected | ||
*/ | ||
Blockly.blockRendering.Drawer.prototype.positionIndentedValueConnection_ = function(row) { | ||
var input = row.getLastInput(); | ||
if (input.connection) { | ||
var connX = row.xPos + row.statementEdge + input.connectionWidth; | ||
if (this.info_.RTL) { | ||
connX *= -1; | ||
} | ||
input.connection.setOffsetInBlock(connX, row.yPos + input.connectionOffsetY); | ||
} | ||
}; | ||
|
||
/** | ||
* Position the previous connection on a block. | ||
* @protected | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,25 @@ Blockly.geras.Highlighter.prototype.drawValueInput = function(row) { | |
} | ||
}; | ||
|
||
Blockly.geras.Highlighter.prototype.drawIndentedInput = function(row) { | ||
var input = row.getLastInput(); | ||
if (this.RTL_) { | ||
var belowTabHeight = row.height - input.connectionHeight - input.connectionOffsetY; | ||
|
||
this.steps_ += | ||
Blockly.utils.svgPaths.moveTo( | ||
input.xPos + this.highlightOffset_ + input.connectionWidth - 1, row.yPos) + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This -1 is probably |
||
Blockly.utils.svgPaths.lineOnAxis('v', input.connectionOffsetY) + | ||
this.puzzleTabPaths_.pathDown(this.RTL_) + | ||
Blockly.utils.svgPaths.lineOnAxis('v', belowTabHeight); | ||
} else { | ||
this.steps_ += | ||
Blockly.utils.svgPaths.moveTo(input.xPos + input.connectionWidth, | ||
row.yPos + input.connectionOffsetY) + | ||
this.puzzleTabPaths_.pathDown(this.RTL_); | ||
} | ||
}; | ||
|
||
Blockly.geras.Highlighter.prototype.drawStatementInput = function(row) { | ||
var input = row.getLastInput(); | ||
if (this.RTL_) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,3 +165,24 @@ Blockly.blockRendering.ExternalValueInput = function(constants, input) { | |
}; | ||
Blockly.utils.object.inherits(Blockly.blockRendering.ExternalValueInput, | ||
Blockly.blockRendering.InputConnection); | ||
|
||
/** | ||
* An object containing information about the space an indented value input | ||
* takes up during rendering | ||
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering | ||
* constants provider. | ||
* @param {!Blockly.Input} input The indented value input to measure and store | ||
* information for. | ||
* @constructor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
*/ | ||
Blockly.blockRendering.IndentedValueInput = function(constants, input) { | ||
Blockly.blockRendering.IndentedValueInput.superClass_.constructor.call(this, | ||
constants, input); | ||
if (!this.connectedBlock) { | ||
this.height = this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT; | ||
} else { | ||
this.height = this.connectedBlockHeight; | ||
} | ||
}; | ||
Blockly.utils.object.inherits(Blockly.blockRendering.IndentedValueInput, | ||
Blockly.blockRendering.ExternalValueInput); |
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.
Do we want to add this as a built-in block. We could add it under test blocks instead?
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.
Good point. Yes, test blocks is a better home.