mirror of
https://github.com/google/blockly.git
synced 2026-01-08 09:30:06 +01:00
* chore: add linting for tsdoc * chore: don't require types on return * chore: remove redundant fileoverview from ts * chore: change return to returns and add some newlines * chore: remove license tag * chore: don't require params/return docs * chore: remove spurious struct tags * Revert "chore: change return to returns and add some newlines" This reverts commitd6d8656a45. * chore: don't auto-add param names * chore: disable require-param bc it breaks on this * return to returns and add line breaks * chore: configure additional jsdoc rules * chore: run format * Revert "chore: remove license tag" This reverts commit173455588a. * chore: allow license tag format * chore: only require jsdoc on exported items * chore: add missing jsdoc or silence where needed * chore: run format * chore: lint fixes
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* Object representing a row that holds one or more inputs on a
|
|
* rendered block.
|
|
*
|
|
* @class
|
|
*/
|
|
import * as goog from '../../../closure/goog/goog.js';
|
|
goog.declareModuleId('Blockly.blockRendering.InputRow');
|
|
|
|
import type {ConstantProvider} from '../common/constants.js';
|
|
|
|
import {ExternalValueInput} from './external_value_input.js';
|
|
import {InputConnection} from './input_connection.js';
|
|
import {Row} from './row.js';
|
|
import {StatementInput} from './statement_input.js';
|
|
import {Types} from './types.js';
|
|
|
|
|
|
/**
|
|
* An object containing information about a row that holds one or more inputs.
|
|
*
|
|
* @alias Blockly.blockRendering.InputRow
|
|
*/
|
|
export class InputRow extends Row {
|
|
/**
|
|
* The total width of all blocks connected to this row.
|
|
*
|
|
* @internal
|
|
*/
|
|
connectedBlockWidths = 0;
|
|
|
|
/**
|
|
* @param constants The rendering constants provider.
|
|
* @internal
|
|
*/
|
|
constructor(constants: ConstantProvider) {
|
|
super(constants);
|
|
this.type |= Types.INPUT_ROW;
|
|
}
|
|
|
|
/**
|
|
* Inspect all subcomponents and populate all size properties on the row.
|
|
*
|
|
* @internal
|
|
*/
|
|
override measure() {
|
|
this.width = this.minWidth;
|
|
this.height = this.minHeight;
|
|
let connectedBlockWidths = 0;
|
|
for (let i = 0; i < this.elements.length; i++) {
|
|
const elem = this.elements[i];
|
|
this.width += elem.width;
|
|
if (Types.isInput(elem) && elem instanceof InputConnection) {
|
|
if (Types.isStatementInput(elem) && elem instanceof StatementInput) {
|
|
connectedBlockWidths += elem.connectedBlockWidth;
|
|
} else if (
|
|
Types.isExternalInput(elem) && elem instanceof ExternalValueInput &&
|
|
elem.connectedBlockWidth !== 0) {
|
|
connectedBlockWidths +=
|
|
elem.connectedBlockWidth - elem.connectionWidth;
|
|
}
|
|
}
|
|
if (!Types.isSpacer(elem)) {
|
|
this.height = Math.max(this.height, elem.height);
|
|
}
|
|
}
|
|
this.connectedBlockWidths = connectedBlockWidths;
|
|
this.widthWithConnectedBlocks = this.width + connectedBlockWidths;
|
|
}
|
|
|
|
override endsWithElemSpacer() {
|
|
return !this.hasExternalInput && !this.hasStatement;
|
|
}
|
|
}
|