Merge pull request #2882 from rachel-fenichel/measurables_connections_file

Move Connection measurables to their own file
This commit is contained in:
Rachel Fenichel
2019-08-20 15:48:33 -07:00
committed by GitHub
5 changed files with 119 additions and 89 deletions

View File

@@ -102,13 +102,14 @@ goog.addDependency("../../../" + dir + "/core/rendered_connection.js", ['Blockly
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_draw.js", ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Highlighter', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_draw_debug.js", ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Highlighter', 'Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js", ['Blockly.blockRendering.Highlighter'], ['Blockly.blockRendering.highlightConstants', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_info.js", ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_info.js", ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_rendering.js", ['Blockly.blockRendering'], ['Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.RenderInfo']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_rendering_constants.js", ['Blockly.blockRendering.constants'], ['Blockly.utils.svgPaths']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/highlight_constants.js", ['Blockly.blockRendering.highlightConstants'], ['Blockly.blockRendering.constants', 'Blockly.utils.svgPaths']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/measurables.js", ['Blockly.blockRendering.Input', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.OutputConnection'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/measurables.js", ['Blockly.blockRendering.Input', 'Blockly.blockRendering.InRowSpacer'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable']);
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/shape_map.js", ['Blockly.blockRendering.connectionShapes'], ['Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/base.js", ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.constants']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/connections.js", [], []);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/connections.js", ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.constants', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/renderers/measurables/rows.js", ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Input', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.RenderedConnection']);
goog.addDependency("../../../" + dir + "/core/scrollbar.js", ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Touch', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']);
goog.addDependency("../../../" + dir + "/core/theme.js", ['Blockly.Theme'], []);
@@ -1901,6 +1902,7 @@ goog.require('Blockly.ZoomControls');
goog.require('Blockly.blockAnimations');
goog.require('Blockly.blockRendering');
goog.require('Blockly.blockRendering.BottomRow');
goog.require('Blockly.blockRendering.Connection');
goog.require('Blockly.blockRendering.Debug');
goog.require('Blockly.blockRendering.Drawer');
goog.require('Blockly.blockRendering.Highlighter');
@@ -1915,6 +1917,7 @@ goog.require('Blockly.blockRendering.RenderInfo');
goog.require('Blockly.blockRendering.Row');
goog.require('Blockly.blockRendering.SpacerRow');
goog.require('Blockly.blockRendering.TopRow');
goog.require('Blockly.blockRendering.connectionShapes');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.highlightConstants');
goog.require('Blockly.constants');

View File

@@ -38,6 +38,7 @@ goog.require('Blockly.blockRendering.PreviousConnection');
goog.require('Blockly.blockRendering.NextConnection');
goog.require('Blockly.blockRendering.OutputConnection');
goog.require('Blockly.RenderedConnection');
/**
* An object containing all sizing information needed to draw this block.
@@ -59,7 +60,8 @@ Blockly.blockRendering.RenderInfo = function(block) {
* @type {Blockly.blockRendering.OutputConnection}
*/
this.outputConnection = !block.outputConnection ? null :
new Blockly.blockRendering.OutputConnection(block.outputConnection);
new Blockly.blockRendering.OutputConnection(
/** @type {Blockly.RenderedConnection} */(block.outputConnection));
/**
* Whether the block should be rendered as a single line, either because it's
@@ -152,7 +154,6 @@ Blockly.blockRendering.RenderInfo = function(block) {
* may choose to rerender when getSize() is called). However, calling it
* repeatedly may be expensive.
*
* @param {!Blockly.BlockSvg} block The block to measure.
* @private
*/
Blockly.blockRendering.RenderInfo.prototype.measure_ = function() {

View File

@@ -1,9 +1,6 @@
goog.provide('Blockly.blockRendering.Input');
goog.provide('Blockly.blockRendering.InRowSpacer');
goog.provide('Blockly.blockRendering.NextConnection');
goog.provide('Blockly.blockRendering.PreviousConnection');
goog.provide('Blockly.blockRendering.OutputConnection');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.blockRendering.Measurable');
@@ -188,82 +185,6 @@ Blockly.blockRendering.ExternalValueInput = function(input) {
goog.inherits(Blockly.blockRendering.ExternalValueInput,
Blockly.blockRendering.Input);
/**
* The base class to represent a connection and the space that it takes up on
* the block.
* @param {Blockly.RenderedConnection} connectionModel The connection object on
* the block that this represents.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.Connection = function(connectionModel) {
Blockly.blockRendering.Connection.superClass_.constructor.call(this);
this.connectionModel = connectionModel;
};
goog.inherits(Blockly.blockRendering.Connection,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space an output connection takes
* up during rendering.
* @param {Blockly.RenderedConnection} connectionModel The connection object on
* the block that this represents.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.OutputConnection = function(connectionModel) {
Blockly.blockRendering.OutputConnection.superClass_.constructor.call(this,
connectionModel);
this.type = 'output connection';
this.height = this.connectionShape.height;
this.width = this.connectionShape.width;
this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP;
this.startX = this.width;
};
goog.inherits(Blockly.blockRendering.OutputConnection,
Blockly.blockRendering.Connection);
/**
* An object containing information about the space a previous connection takes
* up during rendering.
* @param {Blockly.RenderedConnection} connectionModel The connection object on
* the block that this represents.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.PreviousConnection = function(connectionModel) {
Blockly.blockRendering.PreviousConnection.superClass_.constructor.call(this,
connectionModel);
this.type = 'previous connection';
this.height = this.notchShape.height;
this.width = this.notchShape.width;
};
goog.inherits(Blockly.blockRendering.PreviousConnection,
Blockly.blockRendering.Connection);
/**
* An object containing information about the space a next connection takes
* up during rendering.
* @param {Blockly.RenderedConnection} connectionModel The connection object on
* the block that this represents.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.NextConnection = function(connectionModel) {
Blockly.blockRendering.NextConnection.superClass_.constructor.call(this,
connectionModel);
this.type = 'next connection';
this.height = this.notchShape.height;
this.width = this.notchShape.width;
};
goog.inherits(Blockly.blockRendering.NextConnection,
Blockly.blockRendering.Connection);
/**
* An object containing information about the space a hat takes up during
* rendering.

View File

@@ -0,0 +1,109 @@
/**
* @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 connections on rendered blocks.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.provide('Blockly.blockRendering.Connection');
goog.provide('Blockly.blockRendering.NextConnection');
goog.provide('Blockly.blockRendering.OutputConnection');
goog.provide('Blockly.blockRendering.PreviousConnection');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.constants');
goog.require('Blockly.RenderedConnection');
/**
* The base class to represent a connection and the space that it takes up on
* the block.
* @param {Blockly.RenderedConnection} connectionModel The connection object on
* the block that this represents.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.Connection = function(connectionModel) {
Blockly.blockRendering.Connection.superClass_.constructor.call(this);
this.connectionModel = connectionModel;
};
goog.inherits(Blockly.blockRendering.Connection,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space an output connection takes
* up during rendering.
* @param {Blockly.RenderedConnection} connectionModel The connection object on
* the block that this represents.
* @package
* @constructor
* @extends {Blockly.blockRendering.Connection}
*/
Blockly.blockRendering.OutputConnection = function(connectionModel) {
Blockly.blockRendering.OutputConnection.superClass_.constructor.call(this,
connectionModel);
this.type = 'output connection';
this.height = this.connectionShape.height;
this.width = this.connectionShape.width;
this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP;
this.startX = this.width;
};
goog.inherits(Blockly.blockRendering.OutputConnection,
Blockly.blockRendering.Connection);
/**
* An object containing information about the space a previous connection takes
* up during rendering.
* @param {Blockly.RenderedConnection} connectionModel The connection object on
* the block that this represents.
* @package
* @constructor
* @extends {Blockly.blockRendering.Connection}
*/
Blockly.blockRendering.PreviousConnection = function(connectionModel) {
Blockly.blockRendering.PreviousConnection.superClass_.constructor.call(this,
connectionModel);
this.type = 'previous connection';
this.height = this.notchShape.height;
this.width = this.notchShape.width;
};
goog.inherits(Blockly.blockRendering.PreviousConnection,
Blockly.blockRendering.Connection);
/**
* An object containing information about the space a next connection takes
* up during rendering.
* @param {Blockly.RenderedConnection} connectionModel The connection object on
* the block that this represents.
* @package
* @constructor
* @extends {Blockly.blockRendering.Connection}
*/
Blockly.blockRendering.NextConnection = function(connectionModel) {
Blockly.blockRendering.NextConnection.superClass_.constructor.call(this,
connectionModel);
this.type = 'next connection';
this.height = this.notchShape.height;
this.width = this.notchShape.width;
};
goog.inherits(Blockly.blockRendering.NextConnection,
Blockly.blockRendering.Connection);

View File

@@ -228,8 +228,6 @@ Blockly.blockRendering.Row.prototype.getLastSpacer = function() {
* connections.
* After this constructor is called, the row will contain all non-spacer
* elements it needs.
* @param {!Blockly.BlockSvg} block The block for which this represents the top
* row.
* @package
* @constructor
* @extends {Blockly.blockRendering.Row}
@@ -257,7 +255,7 @@ Blockly.blockRendering.TopRow = function() {
/**
* The previous connection on the block, if any.
* @type {Blockly.BlockRendering.PreviousConnection}
* @type {Blockly.blockRendering.PreviousConnection}
*/
this.connection = null;
};
@@ -327,8 +325,6 @@ Blockly.blockRendering.TopRow.prototype.measure = function() {
* An object containing information about what elements are in the bottom row of
* a block as well as spacing information for the top row.
* Elements in a bottom row can consist of corners, spacers and next connections.
* @param {!Blockly.BlockSvg} block The block for which this represents the
* bottom row.
* @package
* @constructor
* @extends {Blockly.blockRendering.Row}