chore: wrap layout nodes for editor (#9641) 6af68fed8b

Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
This commit is contained in:
luigi-rosso
2025-05-10 16:16:37 +00:00
parent 346fb363eb
commit eef564bd17
8 changed files with 59 additions and 9 deletions

View File

@@ -1 +1 @@
2b1a85fa6f06cc20121fd26590bcfe3c1af36b12
6af68fed8b3491cf91d7d7b34aab79f9f4249a86

View File

@@ -160,7 +160,7 @@ public:
void markLayoutDirty(LayoutComponent* layoutComponent);
void cleanLayout(LayoutComponent* layoutComponent);
void* takeLayoutNode();
LayoutData* takeLayoutData();
bool syncStyleChanges() override;
bool canHaveOverrides() override { return true; }

View File

@@ -6,16 +6,56 @@
#include "yoga/YGStyle.h"
#include "yoga/Yoga.h"
#endif
#ifdef WITH_RIVE_TOOLS
#include "rive/refcnt.hpp"
#include <unordered_set>
#endif
namespace rive
{
struct LayoutData
class LayoutData
#ifdef WITH_RIVE_TOOLS
: public RefCnt<LayoutData>
#endif
{
public:
#ifdef WITH_RIVE_LAYOUT
#ifdef WITH_RIVE_TOOLS
std::unordered_set<LayoutData*> children;
#ifdef DEBUG
LayoutData() { count++; }
#endif
~LayoutData()
{
#ifdef DEBUG
count--;
#endif
clearChildren();
}
void clearChildren()
{
for (auto child : children)
{
child->unref();
}
children.clear();
}
#ifdef DEBUG
static uint32_t count;
#endif
#endif
YGNode node;
YGStyle style;
#endif
};
#ifdef WITH_RIVE_TOOLS
typedef rcp<LayoutData> LayoutDataRef;
#else
typedef LayoutData* LayoutDataRef;
#endif
} // namespace rive
#endif

View File

@@ -16,7 +16,7 @@ namespace rive
{
class AABB;
class KeyFrameInterpolator;
struct LayoutData;
class LayoutData;
class LayoutComponentStyle;
class LayoutConstraint;
class Layout

View File

@@ -811,11 +811,11 @@ bool Artboard::updateComponents()
return true;
}
void* Artboard::takeLayoutNode()
LayoutData* Artboard::takeLayoutData()
{
#ifdef WITH_RIVE_LAYOUT
m_updatesOwnLayout = false;
return static_cast<void*>(&m_layoutData->node);
return m_layoutData;
#else
return nullptr;
#endif

View File

@@ -5,6 +5,7 @@
#include "rive/constraints/layout_constraint.hpp"
#include "rive/layout_component.hpp"
#include "rive/viewmodel/viewmodel_instance_symbol_list_index.hpp"
#include "rive/layout/layout_data.hpp"
using namespace rive;
@@ -33,7 +34,7 @@ void* ArtboardComponentList::layoutNode(int index)
auto artboard = artboardInstance(index);
if (artboard != nullptr)
{
return artboard->takeLayoutNode();
return static_cast<void*>(&artboard->takeLayoutData()->node);
}
return nullptr;
}

View File

@@ -25,6 +25,10 @@
using namespace rive;
#if defined(WITH_RIVE_LAYOUT) && defined(WITH_RIVE_TOOLS) && defined(DEBUG)
uint32_t LayoutData::count = 0;
#endif
void LayoutComponent::buildDependencies()
{
Super::buildDependencies();
@@ -412,7 +416,7 @@ void* LayoutComponent::layoutNode(int index)
{
if (m_layoutData != nullptr)
{
return &m_layoutData->node;
return static_cast<void*>(&m_layoutData->node);
}
return nullptr;
}
@@ -1403,7 +1407,11 @@ LayoutComponent::~LayoutComponent()
{
artboard()->cleanLayout(this);
}
#ifdef WITH_RIVE_TOOLS
m_layoutData->unref();
#else
delete m_layoutData;
#endif
}
void LayoutComponent::clipChanged() { markLayoutNodeDirty(); }

View File

@@ -1,6 +1,7 @@
#include "rive/nested_artboard_layout.hpp"
#include "rive/artboard.hpp"
#include "rive/math/aabb.hpp"
#include "rive/layout/layout_data.hpp"
using namespace rive;
@@ -47,7 +48,7 @@ void* NestedArtboardLayout::layoutNode(int index)
{
return nullptr;
}
return artboardInstance()->takeLayoutNode();
return static_cast<void*>(&artboardInstance()->takeLayoutData()->node);
}
#endif