#include "flexlayout_wrap.h" #include "src/cpp/QtGui/QWidget/qwidget_wrap.h" #include "src/cpp/Extras/Utils/nutils.h" #include "src/cpp/core/Component/component_macro.h" Napi::FunctionReference FlexLayoutWrap::constructor; Napi::Object FlexLayoutWrap::init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); char CLASSNAME[] = "FlexLayout"; Napi::Function func = DefineClass(env, CLASSNAME, { InstanceMethod("addWidget", &FlexLayoutWrap::addWidget), InstanceMethod("insertChildBefore", &FlexLayoutWrap::insertChildBefore), InstanceMethod("removeWidget", &FlexLayoutWrap::removeWidget), InstanceMethod("setFlexNode", &FlexLayoutWrap::setFlexNode), COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; } FlexLayout* FlexLayoutWrap::getInternalInstance() { return this->instance; } FlexLayoutWrap::FlexLayoutWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); if(info.Length() == 1) { Napi::Object parentObject = info[0].As(); QWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new FlexLayout(parentWidgetWrap->getInternalInstance()); //this sets the parent to current widget }else if (info.Length() == 0){ this->instance = new FlexLayout(); }else { extrautils::throwTypeError(env, "Wrong number of arguments"); } } FlexLayoutWrap::~FlexLayoutWrap() { delete this->instance; } Napi::Value FlexLayoutWrap::addWidget(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); Napi::Object qwidgetObject = info[0].As(); Napi::External childFlexNodeObject = info[1].As>(); QWidgetWrap* widget = Napi::ObjectWrap::Unwrap(qwidgetObject); YGNodeRef childNodeRef = childFlexNodeObject.Data(); this->instance->addWidget(widget->getInternalInstance(),childNodeRef); return env.Null(); } Napi::Value FlexLayoutWrap::insertChildBefore(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); Napi::Object qwidgetObject = info[0].As(); Napi::External beforeChildFlexNodeObject = info[1].As>(); Napi::External childFlexNodeObject = info[2].As>(); QWidgetWrap* widget = Napi::ObjectWrap::Unwrap(qwidgetObject); YGNodeRef childNodeRef = childFlexNodeObject.Data(); YGNodeRef beforeChildNodeRef = beforeChildFlexNodeObject.Data(); this->instance->insertChildBefore(widget->getInternalInstance(), beforeChildNodeRef, childNodeRef); return env.Null(); } Napi::Value FlexLayoutWrap::removeWidget(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); Napi::Object qwidgetObject = info[0].As(); Napi::External childFlexNodeObject = info[1].As>(); QWidgetWrap* widget = Napi::ObjectWrap::Unwrap(qwidgetObject); YGNodeRef childNodeRef = childFlexNodeObject.Data(); this->instance->removeWidget(widget->getInternalInstance(),childNodeRef); return env.Null(); } Napi::Value FlexLayoutWrap::setFlexNode(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); Napi::External flexNodeObject = info[0].As>(); YGNodeRef flexNodeRef = flexNodeObject.Data(); this->instance->setFlexNode(flexNodeRef); return env.Null(); }