Files
blockly/core/renderers/measurables/input_row.ts
Maribeth Bottorff 037eb59b89 chore: Lint TsDoc. (#6353)
* 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 commit d6d8656a45.

* 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 commit 173455588a.

* 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
2022-08-23 14:27:22 -07:00

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;
}
}