mirror of
https://github.com/google/blockly.git
synced 2026-01-13 20:07:08 +01:00
[zelos] bump fields to min x position (#3464)
* Bump up all non-text fields in the first row to a min x position.
This commit is contained in:
@@ -95,6 +95,20 @@ Blockly.zelos.RenderInfo.prototype.getRenderer = function() {
|
||||
return /** @type {!Blockly.zelos.Renderer} */ (this.renderer_);
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.zelos.RenderInfo.prototype.measure = function() {
|
||||
// Modifing parent measure method to add `adjustXPosition_`.
|
||||
this.createRows_();
|
||||
this.addElemSpacing_();
|
||||
this.addRowSpacing_();
|
||||
this.adjustXPosition_();
|
||||
this.computeBounds_();
|
||||
this.alignRowElements_();
|
||||
this.finalize_();
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
@@ -202,6 +216,42 @@ Blockly.zelos.RenderInfo.prototype.addAlignmentPadding_ = function(row,
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adjust the x position of fields to bump all non-label fields in the first row
|
||||
* past the notch position. This must be called before ``computeBounds`` is
|
||||
* called.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.zelos.RenderInfo.prototype.adjustXPosition_ = function() {
|
||||
if (!this.topRow.hasPreviousConnection) {
|
||||
return;
|
||||
}
|
||||
var minXPos = this.constants_.NOTCH_OFFSET_LEFT +
|
||||
this.constants_.NOTCH_WIDTH;
|
||||
for (var i = 0, row; (row = this.rows[i]); i++) {
|
||||
if (Blockly.blockRendering.Types.isInputRow(row)) {
|
||||
var xCursor = row.xPos;
|
||||
var prevSpacer = null;
|
||||
for (var j = 0, elem; (elem = row.elements[j]); j++) {
|
||||
if (Blockly.blockRendering.Types.isSpacer(elem)) {
|
||||
prevSpacer = elem;
|
||||
}
|
||||
if (prevSpacer && (Blockly.blockRendering.Types.isField(elem) ||
|
||||
Blockly.blockRendering.Types.isInput(elem))) {
|
||||
if (xCursor < minXPos &&
|
||||
!(Blockly.blockRendering.Types.isField(elem) &&
|
||||
elem.field instanceof Blockly.FieldLabel)) {
|
||||
var difference = minXPos - xCursor;
|
||||
prevSpacer.width += difference;
|
||||
}
|
||||
}
|
||||
xCursor += elem.width;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user