* computes the minimum size of a node according to its inputs and output slots * @returns the total size
(out?: Size)
| 1577 | * @returns the total size |
| 1578 | */ |
| 1579 | computeSize(out?: Size): Size { |
| 1580 | const ctorSize = this.constructor.size |
| 1581 | if (ctorSize) return [ctorSize[0], ctorSize[1]] |
| 1582 | |
| 1583 | const { inputs, outputs, widgets } = this |
| 1584 | let rows = Math.max( |
| 1585 | inputs ? inputs.filter(input => !isWidgetInputSlot(input)).length : 1, |
| 1586 | outputs ? outputs.length : 1, |
| 1587 | ) |
| 1588 | const size = out || new Float32Array([0, 0]) |
| 1589 | rows = Math.max(rows, 1) |
| 1590 | // although it should be graphcanvas.inner_text_font size |
| 1591 | const font_size = LiteGraph.NODE_TEXT_SIZE |
| 1592 | |
| 1593 | const padLeft = LiteGraph.NODE_TITLE_HEIGHT |
| 1594 | const padRight = padLeft * 0.33 |
| 1595 | const title_width = padLeft + compute_text_size(this.title, this.titleFontStyle) + padRight |
| 1596 | let input_width = 0 |
| 1597 | let widgetWidth = 0 |
| 1598 | let output_width = 0 |
| 1599 | |
| 1600 | if (inputs) { |
| 1601 | for (const input of inputs) { |
| 1602 | const text = input.label || input.localized_name || input.name || "" |
| 1603 | const text_width = compute_text_size(text, this.innerFontStyle) |
| 1604 | if (isWidgetInputSlot(input)) { |
| 1605 | const widget = this.getWidgetFromSlot(input) |
| 1606 | if (widget && !this.isWidgetVisible(widget)) continue |
| 1607 | |
| 1608 | if (text_width > widgetWidth) widgetWidth = text_width |
| 1609 | } else { |
| 1610 | if (text_width > input_width) input_width = text_width |
| 1611 | } |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | if (outputs) { |
| 1616 | for (const output of outputs) { |
| 1617 | const text = output.label || output.localized_name || output.name || "" |
| 1618 | const text_width = compute_text_size(text, this.innerFontStyle) |
| 1619 | if (output_width < text_width) |
| 1620 | output_width = text_width |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | const minWidth = LiteGraph.NODE_WIDTH * (widgets?.length ? 1.5 : 1) |
| 1625 | // Text + slot width + centre padding |
| 1626 | const centrePadding = input_width && output_width ? 5 : 0 |
| 1627 | const slotsWidth = input_width + output_width + (2 * LiteGraph.NODE_SLOT_HEIGHT) + centrePadding |
| 1628 | |
| 1629 | // Total distance from edge of node to the inner edge of the widget 'previous' arrow button |
| 1630 | const widgetMargin = BaseWidget.margin + BaseWidget.arrowMargin + BaseWidget.arrowWidth |
| 1631 | const widgetPadding = BaseWidget.minValueWidth + (2 * widgetMargin) |
| 1632 | if (widgetWidth) widgetWidth += widgetPadding |
| 1633 | |
| 1634 | size[0] = Math.max(slotsWidth, widgetWidth, title_width, minWidth) |
| 1635 | size[1] = (this.constructor.slot_start_y || 0) + rows * LiteGraph.NODE_SLOT_HEIGHT |
| 1636 |
no test coverage detected