diff --git a/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h b/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h index b84a85bde..09a6646f7 100644 --- a/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h @@ -30,6 +30,10 @@ class DLL_EXPORT QBoxLayoutWrap : public Napi::ObjectWrap { Napi::Value insertWidget(const Napi::CallbackInfo& info); Napi::Value direction(const Napi::CallbackInfo& info); Napi::Value insertLayout(const Napi::CallbackInfo& info); + Napi::Value insertSpacing(const Napi::CallbackInfo& info); + Napi::Value insertStretch(const Napi::CallbackInfo& info); Napi::Value removeWidget(const Napi::CallbackInfo& info); Napi::Value setDirection(const Napi::CallbackInfo& info); + Napi::Value setStretch(const Napi::CallbackInfo& info); + Napi::Value count(const Napi::CallbackInfo& info); }; diff --git a/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_macro.h b/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_macro.h index abcfc3b7b..26067cd80 100644 --- a/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_macro.h @@ -12,26 +12,49 @@ */ #ifndef QLAYOUT_WRAPPED_METHODS_DECLARATION -#define QLAYOUT_WRAPPED_METHODS_DECLARATION \ - QOBJECT_WRAPPED_METHODS_DECLARATION \ - \ - Napi::Value activate(const Napi::CallbackInfo& info) { \ - Napi::Env env = info.Env(); \ - Napi::HandleScope scope(env); \ - bool wasRedone = this->instance->activate(); \ - return Napi::Boolean::New(env, wasRedone); \ - } \ - Napi::Value invalidate(const Napi::CallbackInfo& info) { \ - Napi::Env env = info.Env(); \ - Napi::HandleScope scope(env); \ - this->instance->invalidate(); \ - return env.Null(); \ - } \ - Napi::Value update(const Napi::CallbackInfo& info) { \ - Napi::Env env = info.Env(); \ - Napi::HandleScope scope(env); \ - this->instance->update(); \ - return env.Null(); \ +#define QLAYOUT_WRAPPED_METHODS_DECLARATION \ + QOBJECT_WRAPPED_METHODS_DECLARATION \ + \ + Napi::Value activate(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + bool wasRedone = this->instance->activate(); \ + return Napi::Boolean::New(env, wasRedone); \ + } \ + Napi::Value setEnabled(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + bool enable = info[0].As().Value(); \ + this->instance->setEnabled(enable); \ + return env.Null(); \ + } \ + Napi::Value isEnabled(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + bool enabled = this->instance->isEnabled(); \ + return Napi::Boolean::New(env, enabled); \ + } \ + Napi::Value setContentsMargins(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + int left = info[0].As().Int32Value(); \ + int top = info[1].As().Int32Value(); \ + int right = info[2].As().Int32Value(); \ + int bottom = info[3].As().Int32Value(); \ + this->instance->setContentsMargins(left, top, right, bottom); \ + return env.Null(); \ + } \ + Napi::Value invalidate(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + this->instance->invalidate(); \ + return env.Null(); \ + } \ + Napi::Value update(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + this->instance->update(); \ + return env.Null(); \ } #endif // QLAYOUT_WRAPPED_METHODS_DECLARATION @@ -41,6 +64,10 @@ \ QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(LayoutWrapName) \ InstanceMethod("activate", &LayoutWrapName::activate), \ + InstanceMethod("setEnabled", &LayoutWrapName::setEnabled), \ + InstanceMethod("isEnabled", &LayoutWrapName::isEnabled), \ + InstanceMethod("setContentsMargins", \ + &LayoutWrapName::setContentsMargins), \ InstanceMethod("invalidate", &LayoutWrapName::invalidate), \ InstanceMethod("update", &LayoutWrapName::update), diff --git a/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp b/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp index f04977bde..8d8fb069e 100644 --- a/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp @@ -18,8 +18,12 @@ Napi::Object QBoxLayoutWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("insertWidget", &QBoxLayoutWrap::insertWidget), InstanceMethod("direction", &QBoxLayoutWrap::direction), InstanceMethod("insertLayout", &QBoxLayoutWrap::insertLayout), + InstanceMethod("insertSpacing", &QBoxLayoutWrap::insertSpacing), + InstanceMethod("insertStretch", &QBoxLayoutWrap::insertStretch), InstanceMethod("removeWidget", &QBoxLayoutWrap::removeWidget), InstanceMethod("setDirection", &QBoxLayoutWrap::setDirection), + InstanceMethod("setStretch", &QBoxLayoutWrap::setStretch), + InstanceMethod("count", &QBoxLayoutWrap::count), QLAYOUT_WRAPPED_METHODS_EXPORT_DEFINE(QBoxLayoutWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); @@ -131,6 +135,26 @@ Napi::Value QBoxLayoutWrap::insertLayout(const Napi::CallbackInfo& info) { return env.Null(); } +Napi::Value QBoxLayoutWrap::insertSpacing(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + int index = info[0].As().Int32Value(); + int size = info[1].As().Int32Value(); + this->instance->insertSpacing(index, size); + return env.Null(); +} + +Napi::Value QBoxLayoutWrap::insertStretch(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + int index = info[0].As().Int32Value(); + int stretch = info[1].As().Int32Value(); + this->instance->insertStretch(index, stretch); + return env.Null(); +} + Napi::Value QBoxLayoutWrap::removeWidget(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); @@ -149,4 +173,22 @@ Napi::Value QBoxLayoutWrap::setDirection(const Napi::CallbackInfo& info) { info[0].As().Int32Value()); this->instance->setDirection(dir); return env.Null(); -} \ No newline at end of file +} + +Napi::Value QBoxLayoutWrap::setStretch(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + int index = info[0].As().Int32Value(); + int stretch = info[1].As().Int32Value(); + this->instance->setStretch(index, stretch); + return env.Null(); +} + +Napi::Value QBoxLayoutWrap::count(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + int count = this->instance->count(); + return Napi::Number::New(env, count); +} diff --git a/src/index.ts b/src/index.ts index 2e43d2853..cb7fe868a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,7 +22,7 @@ export { QMouseEvent } from './lib/QtGui/QEvent/QMouseEvent'; export { WidgetEventTypes } from './lib/core/EventWidget'; // Abstract: export { NodeWidget, QWidget, QWidgetSignals } from './lib/QtWidgets/QWidget'; -export { NodeLayout, QLayoutSignals } from './lib/QtWidgets/QLayout'; +export { NodeLayout, QLayoutSignals, SizeConstraint } from './lib/QtWidgets/QLayout'; export { QAbstractScrollArea } from './lib/QtWidgets/QAbstractScrollArea'; export { QAbstractSlider, QAbstractSliderSignals } from './lib/QtWidgets/QAbstractSlider'; export { QAbstractButton, QAbstractButtonSignals } from './lib/QtWidgets/QAbstractButton'; diff --git a/src/lib/QtWidgets/QBoxLayout.ts b/src/lib/QtWidgets/QBoxLayout.ts index 04d07b7ea..cb550d516 100644 --- a/src/lib/QtWidgets/QBoxLayout.ts +++ b/src/lib/QtWidgets/QBoxLayout.ts @@ -70,6 +70,12 @@ export class QBoxLayout extends NodeLayout { this.native.insertLayout(index, layout.native, stretch); this.childLayouts.add(layout); } + insertSpacing(index: number, size: number): void { + this.native.insertSpacing(index, size); + } + insertStretch(index: number, stretch = 0): void { + this.native.insertStretch(index, stretch); + } removeWidget(widget: NodeWidget): void { this.native.removeWidget(widget.native); this.nodeChildren.delete(widget); @@ -77,6 +83,12 @@ export class QBoxLayout extends NodeLayout { setDirection(dir: Direction): void { this.native.setDirection(dir); } + setStretch(index: number, stretch: number): void { + this.native.setStretch(index, stretch); + } + count(): number { + return this.native.count(); + } } export type QBoxLayoutSignals = QLayoutSignals; diff --git a/src/lib/QtWidgets/QLayout.ts b/src/lib/QtWidgets/QLayout.ts index d855a9e91..018accb2e 100644 --- a/src/lib/QtWidgets/QLayout.ts +++ b/src/lib/QtWidgets/QLayout.ts @@ -36,9 +36,30 @@ export abstract class NodeLayout extends NodeObj type = 'layout'; abstract addWidget(childWidget: NodeWidget, ...args: any[]): void; abstract removeWidget(childWidget: NodeWidget): void; + setSizeConstraint(constraint: SizeConstraint): void { + this.setProperty('sizeConstraint', constraint); + } + sizeConstraint(): SizeConstraint { + return this.property('sizeConstraint').toInt(); + } + setSpacing(spacing: number): void { + this.setProperty('spacing', spacing); + } + spacing(): number { + return this.property('spacing').toInt(); + } activate(): boolean { return this.native.activate(); } + setEnabled(enable: boolean): void { + this.native.setEnabled(enable); + } + isEnabled(): boolean { + return this.native.isEnabled(); + } + setContentsMargins(left: number, top: number, right: number, bottom: number): void { + this.native.setContentsMargins(left, top, right, bottom); + } invalidate(): void { this.native.invalidate(); } @@ -51,4 +72,13 @@ export abstract class NodeLayout extends NodeObj // native: any; // } +export enum SizeConstraint { + SetDefaultConstraint = 0, + SetNoConstraint = 1, + SetMinimumSize = 2, + SetFixedSize = 3, + SetMaximumSize = 4, + SetMinAndMaxSize = 5, +} + export type QLayoutSignals = QObjectSignals; diff --git a/src/lib/QtWidgets/QTreeWidget.ts b/src/lib/QtWidgets/QTreeWidget.ts index da862c460..4b63203d7 100644 --- a/src/lib/QtWidgets/QTreeWidget.ts +++ b/src/lib/QtWidgets/QTreeWidget.ts @@ -83,7 +83,7 @@ export class QTreeWidget extends QAbstractScrollArea { } insertTopLevelItem(index: number, item: QTreeWidgetItem): void { - this.topLevelItems.add(item) + this.topLevelItems.add(item); this.native.insertTopLevelItem(index, item.native); }