mirror of
https://github.com/google/blockly.git
synced 2026-01-11 10:57:07 +01:00
Move all rows into rows.js
This commit is contained in:
@@ -99,15 +99,14 @@ goog.addDependency("../../../" + dir + "/core/names.js", ['Blockly.Names'], []);
|
||||
goog.addDependency("../../../" + dir + "/core/options.js", ['Blockly.Options'], ['Blockly.Themes.Classic', 'Blockly.utils.userAgent', 'Blockly.Xml']);
|
||||
goog.addDependency("../../../" + dir + "/core/procedures.js", ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.constants', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.utils.xml', 'Blockly.Workspace', 'Blockly.Xml']);
|
||||
goog.addDependency("../../../" + dir + "/core/rendered_connection.js", ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.Events', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']);
|
||||
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.Rows']);
|
||||
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.Rows']);
|
||||
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.Rows']);
|
||||
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_info.js", ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Rows']);
|
||||
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']);
|
||||
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']);
|
||||
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']);
|
||||
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_info.js", ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable']);
|
||||
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.Measurable', 'Blockly.blockRendering.Input', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection'], ['Blockly.blockRendering.constants']);
|
||||
goog.addDependency("../../../" + dir + "/core/renderers/measurables/rows.js", ['Blockly.blockRendering.Rows'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Input', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.RenderedConnection']);
|
||||
goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/measurables.js", ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.constants']);
|
||||
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'], []);
|
||||
goog.addDependency("../../../" + dir + "/core/theme/classic.js", ['Blockly.Themes.Classic'], ['Blockly.Theme']);
|
||||
@@ -1889,13 +1888,8 @@ goog.require('Blockly.blockRendering');
|
||||
goog.require('Blockly.blockRendering.Debug');
|
||||
goog.require('Blockly.blockRendering.Drawer');
|
||||
goog.require('Blockly.blockRendering.Highlighter');
|
||||
goog.require('Blockly.blockRendering.InRowSpacer');
|
||||
goog.require('Blockly.blockRendering.Input');
|
||||
goog.require('Blockly.blockRendering.Measurable');
|
||||
goog.require('Blockly.blockRendering.NextConnection');
|
||||
goog.require('Blockly.blockRendering.PreviousConnection');
|
||||
goog.require('Blockly.blockRendering.RenderInfo');
|
||||
goog.require('Blockly.blockRendering.Rows');
|
||||
goog.require('Blockly.blockRendering.constants');
|
||||
goog.require('Blockly.blockRendering.highlightConstants');
|
||||
goog.require('Blockly.constants');
|
||||
|
||||
@@ -31,7 +31,11 @@ goog.require('Blockly.blockRendering.Debug');
|
||||
goog.require('Blockly.blockRendering.RenderInfo');
|
||||
goog.require('Blockly.blockRendering.Highlighter');
|
||||
goog.require('Blockly.blockRendering.Measurable');
|
||||
goog.require('Blockly.blockRendering.Rows');
|
||||
goog.require('Blockly.blockRendering.BottomRow');
|
||||
goog.require('Blockly.blockRendering.InputRow');
|
||||
goog.require('Blockly.blockRendering.Row');
|
||||
goog.require('Blockly.blockRendering.SpacerRow');
|
||||
goog.require('Blockly.blockRendering.TopRow');
|
||||
|
||||
/**
|
||||
* An object that draws a block based on the given rendering information.
|
||||
@@ -299,14 +303,12 @@ Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() {
|
||||
Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() {
|
||||
for (var r = 0; r < this.info_.rows.length; r++) {
|
||||
var row = this.info_.rows[r];
|
||||
if (!(row.isSpacer())) {
|
||||
for (var e = 0; e < row.elements.length; e++) {
|
||||
var elem = row.elements[e];
|
||||
if (elem.isInlineInput()) {
|
||||
this.drawInlineInput_(elem);
|
||||
} else if (elem.isIcon() || elem.isField()) {
|
||||
this.layoutField_(elem);
|
||||
}
|
||||
for (var e = 0; e < row.elements.length; e++) {
|
||||
var elem = row.elements[e];
|
||||
if (elem.isInlineInput()) {
|
||||
this.drawInlineInput_(elem);
|
||||
} else if (elem.isIcon() || elem.isField()) {
|
||||
this.layoutField_(elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,11 @@ goog.require('Blockly.blockRendering.RenderInfo');
|
||||
goog.require('Blockly.blockRendering.Highlighter');
|
||||
goog.require('Blockly.blockRendering.constants');
|
||||
goog.require('Blockly.blockRendering.Measurable');
|
||||
goog.require('Blockly.blockRendering.Rows');
|
||||
goog.require('Blockly.blockRendering.BottomRow');
|
||||
goog.require('Blockly.blockRendering.InputRow');
|
||||
goog.require('Blockly.blockRendering.Row');
|
||||
goog.require('Blockly.blockRendering.SpacerRow');
|
||||
goog.require('Blockly.blockRendering.TopRow');
|
||||
|
||||
/**
|
||||
* An object that renders rectangles and dots for debugging rendering code.
|
||||
@@ -323,7 +327,7 @@ Blockly.blockRendering.Debug.prototype.drawDebug = function(block, info) {
|
||||
var cursorY = 0;
|
||||
for (var r = 0; r < info.rows.length; r++) {
|
||||
var row = info.rows[r];
|
||||
if (row.isSpacer()) {
|
||||
if (row.type == 'between-row spacer') {
|
||||
this.drawSpacerRow(row, cursorY, info.RTL);
|
||||
} else {
|
||||
this.drawRowWithElements(row, cursorY, info.RTL);
|
||||
|
||||
@@ -29,7 +29,11 @@ goog.provide('Blockly.blockRendering.Highlighter');
|
||||
goog.require('Blockly.blockRendering.highlightConstants');
|
||||
goog.require('Blockly.blockRendering.RenderInfo');
|
||||
goog.require('Blockly.blockRendering.Measurable');
|
||||
goog.require('Blockly.blockRendering.Rows');
|
||||
goog.require('Blockly.blockRendering.BottomRow');
|
||||
goog.require('Blockly.blockRendering.InputRow');
|
||||
goog.require('Blockly.blockRendering.Row');
|
||||
goog.require('Blockly.blockRendering.SpacerRow');
|
||||
goog.require('Blockly.blockRendering.TopRow');
|
||||
|
||||
/**
|
||||
* An object that adds highlights to a block based on the given rendering
|
||||
|
||||
@@ -29,7 +29,11 @@ goog.provide('Blockly.blockRendering.RenderInfo');
|
||||
|
||||
goog.require('Blockly.blockRendering.constants');
|
||||
goog.require('Blockly.blockRendering.Measurable');
|
||||
goog.require('Blockly.blockRendering.Rows');
|
||||
goog.require('Blockly.blockRendering.BottomRow');
|
||||
goog.require('Blockly.blockRendering.InputRow');
|
||||
goog.require('Blockly.blockRendering.Row');
|
||||
goog.require('Blockly.blockRendering.SpacerRow');
|
||||
goog.require('Blockly.blockRendering.TopRow');
|
||||
|
||||
/**
|
||||
* An object containing all sizing information needed to draw this block.
|
||||
@@ -166,7 +170,7 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() {
|
||||
this.populateTopRow_();
|
||||
this.rows.push(this.topRow);
|
||||
|
||||
var activeRow = new Blockly.blockRendering.Row();
|
||||
var activeRow = new Blockly.blockRendering.InputRow();
|
||||
|
||||
// Icons always go on the first row, before anything else.
|
||||
var icons = this.block_.getIcons();
|
||||
@@ -193,7 +197,7 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() {
|
||||
if (this.shouldStartNewRow_(input, lastInput)) {
|
||||
// Finish this row and create a new one.
|
||||
this.rows.push(activeRow);
|
||||
activeRow = new Blockly.blockRendering.Row();
|
||||
activeRow = new Blockly.blockRendering.InputRow();
|
||||
}
|
||||
|
||||
// All of the fields in an input go on the same row.
|
||||
@@ -615,13 +619,13 @@ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() {
|
||||
* Create a spacer row to go between prev and next, and set its size.
|
||||
* @param {?Blockly.blockRendering.Measurable} prev The previous row, or null.
|
||||
* @param {?Blockly.blockRendering.Measurable} next The next row, or null.
|
||||
* @return {!Blockly.BlockSvg.BetweenRowSpacer} The newly created spacer row.
|
||||
* @return {!Blockly.BlockSvg.SpacerRow} The newly created spacer row.
|
||||
* @private
|
||||
*/
|
||||
Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function(prev, next) {
|
||||
var height = this.getSpacerRowHeight_(prev, next);
|
||||
var width = this.getSpacerRowWidth_(prev, next);
|
||||
var spacer = new Blockly.blockRendering.BetweenRowSpacer(height, width);
|
||||
var spacer = new Blockly.blockRendering.SpacerRow(height, width);
|
||||
if (prev.hasStatement) {
|
||||
spacer.followsStatement = true;
|
||||
}
|
||||
@@ -726,14 +730,12 @@ Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() {
|
||||
this.bottomRow.height += diff;
|
||||
yCursor += diff;
|
||||
}
|
||||
if (!(row.isSpacer())) {
|
||||
var xCursor = row.xPos;
|
||||
for (var e = 0; e < row.elements.length; e++) {
|
||||
var elem = row.elements[e];
|
||||
elem.xPos = xCursor;
|
||||
elem.centerline = this.getElemCenterline_(row, elem);
|
||||
xCursor += elem.width;
|
||||
}
|
||||
var xCursor = row.xPos;
|
||||
for (var e = 0; e < row.elements.length; e++) {
|
||||
var elem = row.elements[e];
|
||||
elem.xPos = xCursor;
|
||||
elem.centerline = this.getElemCenterline_(row, elem);
|
||||
xCursor += elem.width;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -436,24 +436,6 @@ Blockly.blockRendering.RoundCorner = function() {
|
||||
};
|
||||
goog.inherits(Blockly.blockRendering.RoundCorner, Blockly.blockRendering.Measurable);
|
||||
|
||||
/**
|
||||
* An object containing information about a spacer between two rows.
|
||||
* @param {number} height The height of the spacer.
|
||||
* @param {number} width The width of the spacer.
|
||||
* @package
|
||||
* @constructor
|
||||
* @extends {Blockly.blockRendering.Measurable}
|
||||
*/
|
||||
Blockly.blockRendering.BetweenRowSpacer = function(height, width) {
|
||||
this.type = 'between-row spacer';
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.followsStatement = false;
|
||||
this.widthWithConnectedBlocks = 0;
|
||||
};
|
||||
goog.inherits(Blockly.blockRendering.BetweenRowSpacer,
|
||||
Blockly.blockRendering.Measurable);
|
||||
|
||||
/**
|
||||
* An object containing information about a spacer between two elements on a
|
||||
* row.
|
||||
|
||||
@@ -24,7 +24,11 @@
|
||||
* @author fenichel@google.com (Rachel Fenichel)
|
||||
*/
|
||||
|
||||
goog.provide('Blockly.blockRendering.Rows');
|
||||
goog.provide('Blockly.blockRendering.BottomRow');
|
||||
goog.provide('Blockly.blockRendering.InputRow');
|
||||
goog.provide('Blockly.blockRendering.Row');
|
||||
goog.provide('Blockly.blockRendering.SpacerRow');
|
||||
goog.provide('Blockly.blockRendering.TopRow');
|
||||
|
||||
goog.require('Blockly.blockRendering.constants');
|
||||
goog.require('Blockly.blockRendering.Input');
|
||||
@@ -137,41 +141,17 @@ Blockly.blockRendering.Row = function() {
|
||||
Blockly.blockRendering.Row.prototype.notchShape =
|
||||
Blockly.blockRendering.constants.NOTCH;
|
||||
|
||||
/**
|
||||
* Whether this is a spacer row.
|
||||
* @return {boolean} Always false.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Row.prototype.isSpacer = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Inspect all subcomponents and populate all size properties on the row.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Row.prototype.measure = function() {
|
||||
var connectedBlockWidths = 0;
|
||||
for (var e = 0; e < this.elements.length; e++) {
|
||||
var elem = this.elements[e];
|
||||
this.width += elem.width;
|
||||
if (elem.isInput) {
|
||||
if (elem.type == 'statement input') {
|
||||
connectedBlockWidths += elem.connectedBlockWidth;
|
||||
} else if (elem.type == 'external value input' &&
|
||||
elem.connectedBlockWidth != 0) {
|
||||
connectedBlockWidths += (elem.connectedBlockWidth - elem.connectionWidth);
|
||||
}
|
||||
}
|
||||
if (!(elem.isSpacer())) {
|
||||
this.height = Math.max(this.height, elem.height);
|
||||
}
|
||||
}
|
||||
this.widthWithConnectedBlocks = this.width + connectedBlockWidths;
|
||||
throw Error('Unexpected attempt to measure a base Row.');
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the last input on this row, if it has one.
|
||||
* TODO: Consider moving this to InputRow, if possible.
|
||||
* @return {Blockly.blockRendering.Input} The last input on the row, or null.
|
||||
* @package
|
||||
*/
|
||||
@@ -387,3 +367,65 @@ Blockly.blockRendering.BottomRow.prototype.measure = function() {
|
||||
}
|
||||
this.widthWithConnectedBlocks = this.width;
|
||||
};
|
||||
/**
|
||||
* An object containing information about a spacer between two rows.
|
||||
* @param {number} height The height of the spacer.
|
||||
* @param {number} width The width of the spacer.
|
||||
* @package
|
||||
* @constructor
|
||||
* @extends {Blockly.blockRendering.Row}
|
||||
*/
|
||||
Blockly.blockRendering.SpacerRow = function(height, width) {
|
||||
this.type = 'between-row spacer';
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.followsStatement = false;
|
||||
this.widthWithConnectedBlocks = 0;
|
||||
this.elements = [new Blockly.blockRendering.InRowSpacer(width)];
|
||||
};
|
||||
goog.inherits(Blockly.blockRendering.SpacerRow,
|
||||
Blockly.blockRendering.Row);
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.blockRendering.SpacerRow.prototype.measure = function() {
|
||||
// NOP. Width and height were set at creation.
|
||||
};
|
||||
|
||||
/**
|
||||
* An object containing information about a row that holds one or more inputs.
|
||||
* @package
|
||||
* @constructor
|
||||
* @extends {Blockly.blockRendering.Row}
|
||||
*/
|
||||
Blockly.blockRendering.InputRow = function() {
|
||||
Blockly.blockRendering.InputRow.superClass_.constructor.call(this);
|
||||
this.type = 'input row';
|
||||
};
|
||||
goog.inherits(Blockly.blockRendering.InputRow,
|
||||
Blockly.blockRendering.Row);
|
||||
|
||||
/**
|
||||
* Inspect all subcomponents and populate all size properties on the row.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.InputRow.prototype.measure = function() {
|
||||
var connectedBlockWidths = 0;
|
||||
for (var e = 0; e < this.elements.length; e++) {
|
||||
var elem = this.elements[e];
|
||||
this.width += elem.width;
|
||||
if (elem.isInput) {
|
||||
if (elem.type == 'statement input') {
|
||||
connectedBlockWidths += elem.connectedBlockWidth;
|
||||
} else if (elem.type == 'external value input' &&
|
||||
elem.connectedBlockWidth != 0) {
|
||||
connectedBlockWidths += (elem.connectedBlockWidth - elem.connectionWidth);
|
||||
}
|
||||
}
|
||||
if (!(elem.isSpacer())) {
|
||||
this.height = Math.max(this.height, elem.height);
|
||||
}
|
||||
}
|
||||
this.widthWithConnectedBlocks = this.width + connectedBlockWidths;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user