@dark-engine/platform-desktop
Version:
Dark renderer to desktop platforms like Windows, Linux, macOS via Nodegui and Qt
54 lines (53 loc) • 1.67 kB
JavaScript
import { QWidget, QBoxLayout, Direction } from '@nodegui/nodegui';
import { component, detectIsNumber, detectIsArray } from '@dark-engine/core';
import { qBoxLayout } from '../factory';
import { detectIsDialog } from './dialog';
import { runAtTheEndOfCommit } from '../dom';
const BoxLayout = component(props => qBoxLayout(props), {
displayName: 'BoxLayout',
});
class QDarkBoxLayout extends QWidget {
boxLayout = new QBoxLayout(Direction.LeftToRight);
constructor() {
super();
this.setLayout(this.boxLayout);
}
detectIsContainer() {
return true;
}
getBoxLayout() {
return this.boxLayout;
}
setDirection(value) {
this.boxLayout.setDirection(value);
}
setSpacing(value) {
runAtTheEndOfCommit(() => this.boxLayout.setSpacing(value));
}
setMargin(value) {
if (detectIsNumber(value)) {
runAtTheEndOfCommit(() => this.boxLayout.setContentsMargins(value, value, value, value));
} else if (detectIsArray(value)) {
const [left, top, right, bottom] = value;
runAtTheEndOfCommit(() => this.boxLayout.setContentsMargins(left, top, right, bottom));
}
}
setStretch(value) {
runAtTheEndOfCommit(() => value.forEach((x, idx) => this.boxLayout.setStretch(idx, x)));
}
appendChild(child) {
if (detectIsDialog(child)) return;
this.boxLayout.addWidget(child);
}
insertBefore(child, _, idx) {
if (detectIsDialog(child)) return;
this.boxLayout.insertWidget(idx, child);
}
removeChild(child) {
if (detectIsDialog(child)) return;
this.boxLayout.removeWidget(child);
child.close();
}
}
export { BoxLayout, QDarkBoxLayout };
//# sourceMappingURL=box-layout.js.map