mirror of
https://github.com/google/blockly.git
synced 2026-01-14 20:37:10 +01:00
Remove dealWithOffsetFields
This commit is contained in:
@@ -143,6 +143,12 @@ Blockly.Field.TEXT_DEFAULT_HEIGHT = 12.5;
|
||||
*/
|
||||
Blockly.Field.X_PADDING = 10;
|
||||
|
||||
/**
|
||||
* The default offset between the left of the text element and the left of the
|
||||
* border rect, if the border rect exists.
|
||||
* @type {[type]}
|
||||
*/
|
||||
Blockly.Field.DEFAULT_TEXT_OFFSET = Blockly.Field.X_PADDING / 2;
|
||||
/**
|
||||
* Name of field. Unique within each block.
|
||||
* Static labels are usually unnamed.
|
||||
@@ -306,7 +312,7 @@ Blockly.Field.prototype.createBorderRect_ = function() {
|
||||
{
|
||||
'rx': 4,
|
||||
'ry': 4,
|
||||
'x': -Blockly.Field.X_PADDING / 2,
|
||||
'x': 0,
|
||||
'y': 0,
|
||||
'height': this.size_.height,
|
||||
'width': this.size_.width
|
||||
@@ -320,12 +326,13 @@ Blockly.Field.prototype.createBorderRect_ = function() {
|
||||
* @protected
|
||||
*/
|
||||
Blockly.Field.prototype.createTextElement_ = function() {
|
||||
var xOffset = this.borderRect_ ? Blockly.Field.DEFAULT_TEXT_OFFSET : 0;
|
||||
this.textElement_ = Blockly.utils.dom.createSvgElement('text',
|
||||
{
|
||||
'class': 'blocklyText',
|
||||
// The y position is the baseline of the text.
|
||||
'y': Blockly.Field.TEXT_DEFAULT_HEIGHT,
|
||||
'x': 0
|
||||
'x': xOffset
|
||||
}, this.fieldGroup_);
|
||||
this.textContent_ = document.createTextNode('');
|
||||
this.textElement_.appendChild(this.textContent_);
|
||||
|
||||
@@ -84,7 +84,7 @@ Blockly.FieldCheckbox.CHECK_CHAR = '\u2713';
|
||||
* @type {number}
|
||||
* @const
|
||||
*/
|
||||
Blockly.FieldCheckbox.CHECK_X_OFFSET = -3;
|
||||
Blockly.FieldCheckbox.CHECK_X_OFFSET = Blockly.Field.DEFAULT_TEXT_OFFSET - 3;
|
||||
|
||||
/**
|
||||
* Used to correctly position the check mark.
|
||||
|
||||
@@ -502,11 +502,15 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function() {
|
||||
this.size_.width = imageWidth + arrowWidth + Blockly.Field.X_PADDING;
|
||||
|
||||
if (this.sourceBlock_.RTL) {
|
||||
this.imageElement_.setAttribute('x', arrowWidth);
|
||||
this.textElement_.setAttribute('x', -1);
|
||||
var imageX = Blockly.Field.DEFAULT_TEXT_OFFSET + arrowWidth;
|
||||
var arrowX = Blockly.Field.DEFAULT_TEXT_OFFSET - 1;
|
||||
this.imageElement_.setAttribute('x', imageX);
|
||||
this.textElement_.setAttribute('x', arrowX);
|
||||
} else {
|
||||
var arrowX = imageWidth + arrowWidth + Blockly.Field.DEFAULT_TEXT_OFFSET + 1;
|
||||
this.textElement_.setAttribute('text-anchor', 'end');
|
||||
this.textElement_.setAttribute('x', imageWidth + arrowWidth + 1);
|
||||
this.textElement_.setAttribute('x', arrowX);
|
||||
this.imageElement_.setAttribute('x', Blockly.Field.DEFAULT_TEXT_OFFSET);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -517,7 +521,7 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function() {
|
||||
Blockly.FieldDropdown.prototype.renderSelectedText_ = function() {
|
||||
this.textContent_.nodeValue = this.getDisplayText_();
|
||||
this.textElement_.setAttribute('text-anchor', 'start');
|
||||
this.textElement_.setAttribute('x', 0);
|
||||
this.textElement_.setAttribute('x', Blockly.Field.DEFAULT_TEXT_OFFSET);
|
||||
// Height and width include the border rect.
|
||||
this.size_.height = Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT;
|
||||
this.size_.width =
|
||||
|
||||
@@ -99,6 +99,14 @@ Blockly.FieldImage.fromJson = function(options) {
|
||||
return new Blockly.FieldImage(src, width, height, alt, null, flipRtl);
|
||||
};
|
||||
|
||||
/**
|
||||
* Vertical padding below the image, which is included in the reported height of
|
||||
* the field.
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldImage.Y_PADDING = 1;
|
||||
|
||||
/**
|
||||
* Editable fields usually show some sort of UI indicating they are
|
||||
* editable. This field should not.
|
||||
@@ -116,14 +124,6 @@ Blockly.FieldImage.prototype.EDITABLE = false;
|
||||
*/
|
||||
Blockly.FieldImage.prototype.isDirty_ = false;
|
||||
|
||||
/**
|
||||
* Vertical padding below the image, which is included in the reported height of
|
||||
* the field.
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldImage.Y_PADDING = 1;
|
||||
|
||||
/**
|
||||
* Create the block UI for this image.
|
||||
* @package
|
||||
|
||||
@@ -300,24 +300,6 @@ Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Some fields are terrible and render offset from where they claim to be
|
||||
* rendered. This function calculates an x offset for fields that need it.
|
||||
* No one is happy about this.
|
||||
* @param {!Blockly.Field} field The field to find an offset for.
|
||||
* @return {number} How far to offset the field in the x direction.
|
||||
* @private
|
||||
*/
|
||||
Blockly.blockRendering.Drawer.prototype.dealWithOffsetFields_ = function(field) {
|
||||
if (field instanceof Blockly.FieldDropdown ||
|
||||
field instanceof Blockly.FieldTextInput ||
|
||||
field instanceof Blockly.FieldColour ||
|
||||
field instanceof Blockly.FieldCheckbox) {
|
||||
return 5;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Push a field or icon's new position to its SVG root.
|
||||
* @param {!Blockly.blockRendering.Icon|!Blockly.blockRendering.Field} fieldInfo
|
||||
@@ -341,8 +323,6 @@ Blockly.blockRendering.Drawer.prototype.layoutField_ = function(fieldInfo) {
|
||||
svgGroup.setAttribute('transform', 'translate(' + xPos + ',' + yPos + ')');
|
||||
fieldInfo.icon.computeIconLocation();
|
||||
} else {
|
||||
xPos += this.dealWithOffsetFields_(fieldInfo.field);
|
||||
|
||||
svgGroup.setAttribute('transform', 'translate(' + xPos + ',' + yPos + ')');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user