Expose dirtied func in Javascript bindings (#842)
Summary: Yoga currently has the concept of a 'dirtied func', which is called when a Node becomes dirty, which can be useful to trigger a repaint. This PR exposes that functionality in the Javascript bindings. Pull Request resolved: https://github.com/facebook/yoga/pull/842 Reviewed By: SidharthGuglani Differential Revision: D13847093 Pulled By: davidaurelio fbshipit-source-id: 41913abd6eedc46ee7d66929140e08a084f23972
This commit is contained in:
committed by
Facebook Github Bot
parent
4a6b1e19b8
commit
8691cdaed6
@@ -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);
|
||||
@@ -46,6 +53,7 @@ static YGSize globalMeasureFunc(YGNodeRef nodeRef, float width, YGMeasureMode wi
|
||||
Node::Node(Config * config)
|
||||
: m_node(config != nullptr ? YGNodeNewWithConfig(config->m_config) : YGNodeNew())
|
||||
, m_measureFunc(nullptr)
|
||||
, m_dirtiedFunc(nullptr)
|
||||
{
|
||||
YGNodeSetContext(m_node, reinterpret_cast<void *>(this));
|
||||
}
|
||||
@@ -58,6 +66,7 @@ Node::~Node(void)
|
||||
void Node::reset(void)
|
||||
{
|
||||
m_measureFunc.reset(nullptr);
|
||||
m_dirtiedFunc.reset(nullptr);
|
||||
|
||||
YGNodeReset(m_node);
|
||||
}
|
||||
@@ -429,6 +438,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);
|
||||
|
Reference in New Issue
Block a user