forked from nodegui/nodegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqcheckbox_wrap.cpp
More file actions
56 lines (45 loc) · 1.81 KB
/
qcheckbox_wrap.cpp
File metadata and controls
56 lines (45 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "qcheckbox_wrap.h"
#include "src/cpp/QtWidgets/QWidget/qwidget_wrap.h"
#include "src/cpp/Extras/Utils/nutils.h"
#include <QWidget>
Napi::FunctionReference QCheckBoxWrap::constructor;
Napi::Object QCheckBoxWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QCheckBox";
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("setText", &QCheckBoxWrap::setText),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QCheckBoxWrap)
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
NCheckBox* QCheckBoxWrap::getInternalInstance() {
return this->instance;
}
QCheckBoxWrap::QCheckBoxWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QCheckBoxWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if(info.Length() == 1) {
Napi::Object parentObject = info[0].As<Napi::Object>();
QWidgetWrap* parentWidgetWrap = Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
this->instance = new NCheckBox(parentWidgetWrap->getInternalInstance()); //this sets the parent to current widget
}else if (info.Length() == 0){
this->instance = new NCheckBox();
}else {
Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
}
// Adds measure function on yoga node so that widget size is calculated based on its text also.
YGNodeSetMeasureFunc(this->instance->getFlexNode(), &extrautils::measureQtWidget);
}
QCheckBoxWrap::~QCheckBoxWrap() {
delete this->instance;
}
Napi::Value QCheckBoxWrap::setText(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::String text = info[0].As<Napi::String>();
std::string label = text.Utf8Value();
this->instance->setText(label.c_str());
return env.Null();
}