Expose dirtied func in Javascript bindings

This commit is contained in:
Reinier Hartog
2018-12-31 13:16:37 +01:00
parent 138521ccc2
commit 046d86e296
3 changed files with 38 additions and 1 deletions

View File

@@ -23,6 +23,13 @@ static YGSize globalMeasureFunc(YGNodeRef nodeRef, float width, YGMeasureMode wi
return ygSize;
}
static void globalDirtiedFunc(YGNodeRef nodeRef)
{
Node const & node = *reinterpret_cast<Node const *>(YGNodeGetContext(nodeRef));
node.callDirtiedFunc();
}
/* static */ Node * Node::createDefault(void)
{
return new Node(nullptr);
@@ -429,6 +436,24 @@ Size Node::callMeasureFunc(double width, int widthMode, double height, int heigh
return m_measureFunc->call<Size>(width, widthMode, height, heightMode);
}
void Node::setDirtiedFunc(nbind::cbFunction & dirtiedFunc)
{
m_dirtiedFunc.reset(new nbind::cbFunction(dirtiedFunc));
YGNodeSetDirtiedFunc(m_node, &globalDirtiedFunc);
}
void Node::unsetDirtiedFunc(void) {
m_dirtiedFunc.reset(nullptr);
YGNodeSetDirtiedFunc(m_node, nullptr);
}
void Node::callDirtiedFunc(void) const
{
m_dirtiedFunc->call<void>();
}
void Node::markDirty(void)
{
YGNodeMarkDirty(m_node);

View File

@@ -161,6 +161,15 @@ class Node {
Size callMeasureFunc(double width, int widthMode, double height, int heightMode) const;
public: // Dirtied func mutators
void setDirtiedFunc(nbind::cbFunction & dirtiedFunc);
void unsetDirtiedFunc(void);
public: // Dirtied func inspectors
void callDirtiedFunc(void) const;
public: // Dirtiness accessors
void markDirty(void);
@@ -194,5 +203,5 @@ class Node {
YGNodeRef m_node;
std::unique_ptr<nbind::cbFunction> m_measureFunc;
std::unique_ptr<nbind::cbFunction> m_dirtiedFunc;
};

View File

@@ -155,6 +155,9 @@ NBIND_CLASS(Node)
method(setMeasureFunc);
method(unsetMeasureFunc);
method(setDirtiedFunc);
method(unsetDirtiedFunc);
method(markDirty);
method(isDirty);