UNPKG

@dark-engine/platform-desktop

Version:

Dark renderer to desktop platforms like Windows, Linux, macOS via Nodegui and Qt

76 lines (75 loc) 2.35 kB
import { QWidget, QGridLayout } from '@nodegui/nodegui'; import { component, detectIsArray, detectIsNumber } from '@dark-engine/core'; import { qGridLayout } from '../factory'; import { detectIsGridItem } from './grid-item'; import { throwUnsupported } from '../utils'; import { runAtTheEndOfCommit } from '../dom'; const GridLayout = component(props => qGridLayout(props), { displayName: 'GridLayout', }); class QDarkGridLayout extends QWidget { gridLayout = new QGridLayout(); constructor() { super(); this.setLayout(this.gridLayout); } detectIsContainer() { return true; } getGridLayout() { return this.gridLayout; } setHorizontalSpacing(value) { this.gridLayout.setHorizontalSpacing(value); } setVerticalSpacing(value) { this.gridLayout.setVerticalSpacing(value); } setMargin(value) { if (detectIsNumber(value)) { runAtTheEndOfCommit(() => this.gridLayout.setContentsMargins(value, value, value, value)); } else if (detectIsArray(value)) { const [left, top, right, bottom] = value; runAtTheEndOfCommit(() => this.gridLayout.setContentsMargins(left, top, right, bottom)); } } setColumnStretch(value) { setIndexedValue(value, (...args) => this.gridLayout.setColumnStretch(...args)); } setRowStretch(value) { setIndexedValue(value, (...args) => this.gridLayout.setRowStretch(...args)); } setRowMinimumHeight(value) { setIndexedValue(value, (...args) => this.gridLayout.setRowMinimumHeight(...args)); } setColumnMinimumWidth(value) { setIndexedValue(value, (...args) => this.gridLayout.setColumnMinimumWidth(...args)); } appendChild(child) { if (!detectIsGridItem(child)) return; runAtTheEndOfCommit(() => { this.gridLayout.addWidget( child.getChild(), child.getRow(), child.getCol(), child.getRowSpan(), child.getColSpan(), child.getAlignment(), ); }); } insertBefore() { throwUnsupported(this); } removeChild(child) { if (!detectIsGridItem(child)) return; this.gridLayout.removeWidget(child); child.close(); } } function setIndexedValue(value, fn) { if (!detectIsArray(value)) return; value.forEach((x, idx) => detectIsNumber(x) && fn(idx, x)); } export { GridLayout, QDarkGridLayout }; //# sourceMappingURL=grid-layout.js.map