Added getter method for label widget
This commit is contained in:
parent
215401d08b
commit
d9237d65e5
2
demo.ts
2
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");
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
};
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user