add set text on radio button

This commit is contained in:
Atul R 2019-07-12 20:25:15 +02:00
parent 275c4b2d64
commit b8b3dd53e7
3 changed files with 17 additions and 0 deletions

View File

@ -11,6 +11,7 @@ Napi::Object QRadioButtonWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QRadioButton";
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("setText", &QRadioButtonWrap::setText),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QRadioButtonWrap)
});
constructor = Napi::Persistent(func);
@ -43,3 +44,14 @@ QRadioButtonWrap::~QRadioButtonWrap() {
delete this->instance;
}
Napi::Value QRadioButtonWrap::setText(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::String napiText = info[0].As<Napi::String>();
std::string text = napiText.Utf8Value();
this->instance->setText(text.c_str());
return env.Null();
}

View File

@ -16,6 +16,7 @@ class QRadioButtonWrap : public Napi::ObjectWrap<QRadioButtonWrap>{
//class constructor
static Napi::FunctionReference constructor;
//wrapped methods
Napi::Value setText(const Napi::CallbackInfo& info);
QWIDGET_WRAPPED_METHODS_DECLARATION
};

View File

@ -19,5 +19,9 @@ export class QRadioButton extends NodeWidget {
this.native = native;
this.parent = parent;
// bind member functions
this.setText.bind(this);
}
setText(text: string | number) {
this.native.setText(`${text}`);
}
}