@dark-engine/platform-desktop
Version:
Dark renderer to desktop platforms like Windows, Linux, macOS via Nodegui and Qt
80 lines (79 loc) • 2.62 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
exports.QDarkGridLayout = exports.GridLayout = void 0;
const nodegui_1 = require('@nodegui/nodegui');
const core_1 = require('@dark-engine/core');
const factory_1 = require('../factory');
const grid_item_1 = require('./grid-item');
const utils_1 = require('../utils');
const dom_1 = require('../dom');
const GridLayout = (0, core_1.component)(props => (0, factory_1.qGridLayout)(props), {
displayName: 'GridLayout',
});
exports.GridLayout = GridLayout;
class QDarkGridLayout extends nodegui_1.QWidget {
gridLayout = new nodegui_1.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 ((0, core_1.detectIsNumber)(value)) {
(0, dom_1.runAtTheEndOfCommit)(() => this.gridLayout.setContentsMargins(value, value, value, value));
} else if ((0, core_1.detectIsArray)(value)) {
const [left, top, right, bottom] = value;
(0, dom_1.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 (!(0, grid_item_1.detectIsGridItem)(child)) return;
(0, dom_1.runAtTheEndOfCommit)(() => {
this.gridLayout.addWidget(
child.getChild(),
child.getRow(),
child.getCol(),
child.getRowSpan(),
child.getColSpan(),
child.getAlignment(),
);
});
}
insertBefore() {
(0, utils_1.throwUnsupported)(this);
}
removeChild(child) {
if (!(0, grid_item_1.detectIsGridItem)(child)) return;
this.gridLayout.removeWidget(child);
child.close();
}
}
exports.QDarkGridLayout = QDarkGridLayout;
function setIndexedValue(value, fn) {
if (!(0, core_1.detectIsArray)(value)) return;
value.forEach((x, idx) => (0, core_1.detectIsNumber)(x) && fn(idx, x));
}
//# sourceMappingURL=grid-layout.js.map