Adds take widget for scrollarea and adds geometry getter for widgets

This commit is contained in:
Atul R 2019-09-10 00:06:08 +02:00
parent cc69485c8a
commit 4499bf05a7
5 changed files with 43 additions and 2 deletions

View File

@ -46,4 +46,12 @@ Napi::Value QScrollAreaWrap::setWidget(const Napi::CallbackInfo& info) {
QWidgetWrap* contentWidgetWrap = Napi::ObjectWrap<QWidgetWrap>::Unwrap(contentWidget);
this->instance->setWidget(contentWidgetWrap->getInternalInstance());
return env.Null();
}
Napi::Value QScrollAreaWrap::takeWidget(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->takeWidget();
// We will not return the value here since we are doing it in js side anyway
return env.Null();
}

View File

@ -17,6 +17,7 @@ class QScrollAreaWrap : public Napi::ObjectWrap<QScrollAreaWrap>{
static Napi::FunctionReference constructor;
//wrapped methods
Napi::Value setWidget(const Napi::CallbackInfo &info);
Napi::Value takeWidget(const Napi::CallbackInfo &info);
QABSTRACTSCROLLAREA_WRAPPED_METHODS_DECLARATION
};

View File

@ -154,6 +154,17 @@ Napi::Value setGeometry(const Napi::CallbackInfo& info){ \
this->instance->setGeometry(x, y, width, height); \
return env.Null(); \
} \
Napi::Value geometry(const Napi::CallbackInfo& info){ \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
QRect geometry = this->instance->geometry(); \
Napi::Object geometryObj = Napi::Object::New(env); \
geometryObj.Set("width", geometry.width()); \
geometryObj.Set("height", geometry.height()); \
geometryObj.Set("x", geometry.x()); \
geometryObj.Set("y", geometry.y()); \
return geometryObj; \
} \
Napi::Value setMaximumSize(const Napi::CallbackInfo& info){ \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
@ -263,6 +274,7 @@ Napi::Value setWindowFlag(const Napi::CallbackInfo& info){ \
InstanceMethod("setEnabled",&WidgetWrapName::setEnabled), \
InstanceMethod("setFixedSize",&WidgetWrapName::setFixedSize), \
InstanceMethod("setGeometry",&WidgetWrapName::setGeometry), \
InstanceMethod("geometry",&WidgetWrapName::geometry), \
InstanceMethod("setMaximumSize",&WidgetWrapName::setMaximumSize), \
InstanceMethod("setMinimumSize",&WidgetWrapName::setMinimumSize), \
InstanceMethod("repaint",&WidgetWrapName::repaint), \

View File

@ -9,7 +9,7 @@ export const QScrollAreaEvents = Object.freeze({
});
export class QScrollArea extends QAbstractScrollArea {
native: NativeElement;
contentWidget?: NodeWidget;
contentWidget?: NodeWidget | null;
constructor(parent?: NodeWidget) {
let native;
if (parent) {
@ -21,9 +21,20 @@ export class QScrollArea extends QAbstractScrollArea {
this.native = native;
this.parent = parent;
// bind member functions
this.setWidget.bind(this);
this.takeWidget.bind(this);
}
setWidget(widget: NodeWidget) {
this.contentWidget = widget;
this.native.setWidget(widget.native);
}
takeWidget(): NodeWidget | null {
const contentWidget = this.contentWidget;
this.contentWidget = null;
if (contentWidget) {
this.native.takeWidget();
return contentWidget;
}
return null;
}
}

View File

@ -45,9 +45,12 @@ export abstract class NodeWidget extends EventWidget {
await applyStyleSheet(this, preparedSheet);
};
setGeometry = (x: number, y: number, w: number, h: number) => {
// react:✓, //TODO:getter
// react:✓
this.native.setGeometry(x, y, w, h);
};
geometry = (): Rect => {
return this.native.geometry();
};
setObjectName = (objectName: string) => {
// react:✓
this.native.setObjectName(objectName);
@ -148,6 +151,12 @@ export abstract class NodeWidget extends EventWidget {
};
}
type Rect = {
x: number;
y: number;
width: number;
height: number;
};
type arg = NodeWidget | NativeElement;
export class QWidget extends NodeWidget {