Files
blockly/core/renderers/measurables/row_elements.js
Sam El-Husseini e339ae26bc Move the rendering object to live on the workspace_svg (#3016)
* Move the rendering object onto the workspace allowing the various workspaces to have different renderers.
2019-09-13 14:20:34 -07:00

200 lines
7.1 KiB
JavaScript

/**
* @license
* Visual Blocks Editor
*
* Copyright 2019 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Objects representing elements in a row of a rendered
* block.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.provide('Blockly.blockRendering.Field');
goog.provide('Blockly.blockRendering.Hat');
goog.provide('Blockly.blockRendering.Icon');
goog.provide('Blockly.blockRendering.InRowSpacer');
goog.provide('Blockly.blockRendering.JaggedEdge');
goog.provide('Blockly.blockRendering.RoundCorner');
goog.provide('Blockly.blockRendering.SquareCorner');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.Types');
goog.require('Blockly.utils.object');
/**
* An object containing information about the space an icon takes up during
* rendering
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {!Blockly.Icon} icon The icon to measure and store information for.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.Icon = function(constants, icon) {
Blockly.blockRendering.Icon.superClass_.constructor.call(this, constants);
this.icon = icon;
this.isVisible = icon.isVisible();
this.type |= Blockly.blockRendering.Types.ICON;
var size = icon.getCorrectedSize();
this.height = size.height;
this.width = size.width;
};
Blockly.utils.object.inherits(Blockly.blockRendering.Icon,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the jagged edge of a collapsed block
* takes up during rendering
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.JaggedEdge = function(constants) {
Blockly.blockRendering.JaggedEdge.superClass_.constructor.call(
this, constants);
this.type |= Blockly.blockRendering.Types.JAGGED_EDGE;
this.height = this.constants_.JAGGED_TEETH.height;
this.width = this.constants_.JAGGED_TEETH.width;
};
Blockly.utils.object.inherits(Blockly.blockRendering.JaggedEdge,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space a field takes up during
* rendering
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {!Blockly.Field} field The field to measure and store information for.
* @param {!Blockly.Input} parentInput The parent input for the field.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.Field = function(constants, field, parentInput) {
Blockly.blockRendering.Field.superClass_.constructor.call(this, constants);
this.field = field;
this.isEditable = field.isCurrentlyEditable();
this.flipRtl = field instanceof Blockly.FieldImage && field.getFlipRtl();
this.type |= Blockly.blockRendering.Types.FIELD;
var size = this.field.getSize();
this.height = size.height;
this.width = size.width;
this.parentInput = parentInput;
};
Blockly.utils.object.inherits(Blockly.blockRendering.Field,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space a hat takes up during
* rendering.
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.Hat = function(constants) {
Blockly.blockRendering.Hat.superClass_.constructor.call(this, constants);
this.type |= Blockly.blockRendering.Types.HAT;
this.height = this.constants_.START_HAT.height;
this.width = this.constants_.START_HAT.width;
this.ascenderHeight = this.height;
};
Blockly.utils.object.inherits(Blockly.blockRendering.Hat,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space a square corner takes up
* during rendering.
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {string=} opt_position The position of this corner.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.SquareCorner = function(constants, opt_position) {
Blockly.blockRendering.SquareCorner.superClass_.constructor.call(this,
constants);
this.type = ((!opt_position || opt_position == 'left') ?
Blockly.blockRendering.Types.LEFT_SQUARE_CORNER :
Blockly.blockRendering.Types.RIGHT_SQUARE_CORNER) |
Blockly.blockRendering.Types.CORNER;
this.height = this.constants_.NO_PADDING;
this.width = this.constants_.NO_PADDING;
};
Blockly.utils.object.inherits(Blockly.blockRendering.SquareCorner,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space a rounded corner takes up
* during rendering.
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {string=} opt_position The position of this corner.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.RoundCorner = function(constants, opt_position) {
Blockly.blockRendering.RoundCorner.superClass_.constructor.call(this,
constants);
this.type = ((!opt_position || opt_position == 'left') ?
Blockly.blockRendering.Types.LEFT_ROUND_CORNER :
Blockly.blockRendering.Types.RIGHT_ROUND_CORNER) |
Blockly.blockRendering.Types.CORNER;
this.width = this.constants_.CORNER_RADIUS;
// The rounded corner extends into the next row by 4 so we only take the
// height that is aligned with this row.
this.height = this.constants_.CORNER_RADIUS / 2;
};
Blockly.utils.object.inherits(Blockly.blockRendering.RoundCorner,
Blockly.blockRendering.Measurable);
/**
* An object containing information about a spacer between two elements on a
* row.
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {number} width The width of the spacer.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.InRowSpacer = function(constants, width) {
Blockly.blockRendering.InRowSpacer.superClass_.constructor.call(this,
constants);
this.type |= Blockly.blockRendering.Types.SPACER |
Blockly.blockRendering.Types.IN_ROW_SPACER;
this.width = width;
this.height = this.constants_.SPACER_DEFAULT_HEIGHT;
};
Blockly.utils.object.inherits(Blockly.blockRendering.InRowSpacer,
Blockly.blockRendering.Measurable);