mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
Cleanup and comments
This commit is contained in:
@@ -136,9 +136,12 @@ Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT = 16;
|
||||
*/
|
||||
Blockly.Field.TEXT_DEFAULT_HEIGHT = 12.5;
|
||||
|
||||
Blockly.Field.WIDTH_PADDING = 10;
|
||||
|
||||
Blockly.Field.HEIGHT_PADDING = 10;
|
||||
/**
|
||||
* The padding added to the width by the border rect, if it exists.
|
||||
* @type {number}
|
||||
* @package
|
||||
*/
|
||||
Blockly.Field.X_PADDING = 10;
|
||||
|
||||
/**
|
||||
* Name of field. Unique within each block.
|
||||
@@ -297,11 +300,13 @@ Blockly.Field.prototype.initView = function() {
|
||||
Blockly.Field.prototype.createBorderRect_ = function() {
|
||||
this.size_.height =
|
||||
Math.max(this.size_.height, Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT);
|
||||
this.size_.width =
|
||||
Math.max(this.size_.width, Blockly.Field.X_PADDING);
|
||||
this.borderRect_ = Blockly.utils.dom.createSvgElement('rect',
|
||||
{
|
||||
'rx': 4,
|
||||
'ry': 4,
|
||||
'x': -Blockly.Field.WIDTH_PADDING / 2,
|
||||
'x': -Blockly.Field.X_PADDING / 2,
|
||||
'y': 0,
|
||||
'height': this.size_.height,
|
||||
'width': this.size_.width
|
||||
@@ -318,7 +323,7 @@ Blockly.Field.prototype.createTextElement_ = function() {
|
||||
this.textElement_ = Blockly.utils.dom.createSvgElement('text',
|
||||
{
|
||||
'class': 'blocklyText',
|
||||
// This may just be trying to vertically center the text?
|
||||
// The y position is the baseline of the text.
|
||||
'y': Blockly.Field.TEXT_DEFAULT_HEIGHT,
|
||||
'x': 0
|
||||
}, this.fieldGroup_);
|
||||
@@ -587,7 +592,7 @@ Blockly.Field.prototype.updateSize_ = function() {
|
||||
var textWidth = Blockly.Field.getCachedWidth(this.textElement_);
|
||||
var totalWidth = textWidth;
|
||||
if (this.borderRect_) {
|
||||
totalWidth += Blockly.Field.WIDTH_PADDING;
|
||||
totalWidth += Blockly.Field.X_PADDING;
|
||||
this.borderRect_.setAttribute('width', totalWidth);
|
||||
}
|
||||
this.size_.width = totalWidth;
|
||||
|
||||
@@ -78,7 +78,7 @@ Blockly.FieldColour.fromJson = function(options) {
|
||||
* @private
|
||||
* @const
|
||||
*/
|
||||
Blockly.FieldColour.DEFAULT_WIDTH = 16 + Blockly.Field.WIDTH_PADDING;
|
||||
Blockly.FieldColour.DEFAULT_WIDTH = 16 + Blockly.Field.X_PADDING;
|
||||
|
||||
/**
|
||||
* Default height of a colour field.
|
||||
|
||||
@@ -99,9 +99,11 @@ Blockly.FieldDropdown.CHECKMARK_OVERHANG = 25;
|
||||
Blockly.FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45;
|
||||
|
||||
/**
|
||||
* Used to position the imageElement_ correctly.
|
||||
* The y offset from the top of the field to the top of the image, if an image
|
||||
* is selected.
|
||||
* @type {number}
|
||||
* @const
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldDropdown.IMAGE_Y_OFFSET = 5;
|
||||
|
||||
@@ -109,6 +111,7 @@ Blockly.FieldDropdown.IMAGE_Y_OFFSET = 5;
|
||||
* The total vertical padding above and below an image.
|
||||
* @type {number}
|
||||
* @const
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldDropdown.IMAGE_Y_PADDING = Blockly.FieldDropdown.IMAGE_Y_OFFSET * 2;
|
||||
|
||||
@@ -160,8 +163,6 @@ Blockly.FieldDropdown.prototype.initView = function() {
|
||||
} else {
|
||||
this.textElement_.appendChild(this.arrow_);
|
||||
}
|
||||
|
||||
this.contentDimensions_ = new Blockly.utils.Size(0, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -493,11 +494,12 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function() {
|
||||
|
||||
var arrowWidth = Blockly.Field.getCachedWidth(this.arrow_);
|
||||
|
||||
// Height and width include the border rect.
|
||||
var imageHeight = Number(this.imageJson_.height);
|
||||
var imageWidth = Number(this.imageJson_.width);
|
||||
|
||||
// Height and width include the border rect.
|
||||
this.size_.height = imageHeight + Blockly.FieldDropdown.IMAGE_Y_PADDING;
|
||||
this.size_.width = imageWidth + arrowWidth + Blockly.Field.WIDTH_PADDING;
|
||||
this.size_.width = imageWidth + arrowWidth + Blockly.Field.X_PADDING;
|
||||
|
||||
if (this.sourceBlock_.RTL) {
|
||||
this.imageElement_.setAttribute('x', arrowWidth);
|
||||
@@ -519,7 +521,7 @@ Blockly.FieldDropdown.prototype.renderSelectedText_ = function() {
|
||||
// Height and width include the border rect.
|
||||
this.size_.height = Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT;
|
||||
this.size_.width =
|
||||
Blockly.Field.getCachedWidth(this.textElement_) + Blockly.Field.WIDTH_PADDING;
|
||||
Blockly.Field.getCachedWidth(this.textElement_) + Blockly.Field.X_PADDING;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,6 +65,7 @@ Blockly.FieldImage = function(src, width, height,
|
||||
throw Error('Height and width values of an image field must be greater' +
|
||||
' than 0.');
|
||||
}
|
||||
// Store the image height, since it is different from the field height.
|
||||
this.imageHeight_ = imageHeight;
|
||||
this.size_ = new Blockly.utils.Size(imageWidth,
|
||||
imageHeight + Blockly.FieldImage.Y_PADDING);
|
||||
@@ -115,6 +116,12 @@ 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;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user