From d9237d65e5b6577dbe6ddfd651b86630d223c139 Mon Sep 17 00:00:00 2001 From: rgabs Date: Sun, 9 Jun 2019 00:04:37 +0530 Subject: [PATCH] Added getter method for label widget --- demo.ts | 2 +- src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp | 9 +++++++++ src/cpp/QtWidgets/QLabel/qlabel_wrap.h | 3 ++- src/lib/QtWidgets/QLabel/index.ts | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/demo.ts b/demo.ts index 545198feb..c9e5e3195 100644 --- a/demo.ts +++ b/demo.ts @@ -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"); diff --git a/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp b/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp index 1d4a69c3b..173e763c6 100644 --- a/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp +++ b/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp @@ -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); +} diff --git a/src/cpp/QtWidgets/QLabel/qlabel_wrap.h b/src/cpp/QtWidgets/QLabel/qlabel_wrap.h index f348f32b6..949f10bf1 100644 --- a/src/cpp/QtWidgets/QLabel/qlabel_wrap.h +++ b/src/cpp/QtWidgets/QLabel/qlabel_wrap.h @@ -18,7 +18,8 @@ class QLabelWrap : public Napi::ObjectWrap{ //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 }; diff --git a/src/lib/QtWidgets/QLabel/index.ts b/src/lib/QtWidgets/QLabel/index.ts index cb9683b04..5fa4e0f4e 100644 --- a/src/lib/QtWidgets/QLabel/index.ts +++ b/src/lib/QtWidgets/QLabel/index.ts @@ -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);