Added getter method for label widget

This commit is contained in:
rgabs 2019-06-09 00:04:37 +05:30
parent 215401d08b
commit d9237d65e5
4 changed files with 15 additions and 2 deletions

View File

@ -38,7 +38,7 @@ const testGridLayout = () => {
console.log("toggled", ...args);
});
button1.setText("Yolo");
button1.setText(`Button for Label with text: ${label.text()}`);
const checkbox = new QCheckBox();
checkbox.setText("Checkbox text");

View File

@ -12,6 +12,7 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) {
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("setWordWrap", &QLabelWrap::setWordWrap),
InstanceMethod("setText", &QLabelWrap::setText),
InstanceMethod("text", &QLabelWrap::text),
InstanceMethod("getFlexNode", &QLabelWrap::getFlexNode),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
@ -65,3 +66,11 @@ Napi::Value QLabelWrap::setText(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QLabelWrap::text(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string labelText = this->instance->text().toStdString();
return Napi::String::New(env, labelText);
}

View File

@ -18,7 +18,8 @@ class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
//wrapped methods
Napi::Value setWordWrap(const Napi::CallbackInfo& info);
Napi::Value setText(const Napi::CallbackInfo& info);
Napi::Value text(const Napi::CallbackInfo &info);
QWIDGET_WRAPPED_METHODS_DECLARATION
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
};

View File

@ -19,6 +19,9 @@ export class QLabel extends NodeWidget {
setText(text: string) {
this.native.setText(text);
}
text() {
return this.native.text();
}
getFlexNode(): FlexNode {
const nativeFlexNode = this.native.getFlexNode();
return new FlexNode(nativeFlexNode);