Skip to content

Commit

Permalink
Nested artboard types: node, leaf, layout
Browse files Browse the repository at this point in the history
~~Adding as a draft to start testing.~~

- [x] Add node, leaf, and layout types.
- [x] Leaf supports fit and alignment.
- [x] Leaf alignment is floating point instead of enum allowing for animation later.
- [x] Layout allows external hosting artboards to take the nested layout node and host it in another hierarchy.
- [x] Measure and control size for NestedArtboard from native.
- [x] FFI changes for external layout node
- [x] WASM changes for external layout node.
- [x] Move layouts to RiveNative.

<img width="663" alt="CleanShot 2024-07-21 at 14 48 41@2x" src="https://github.com/user-attachments/assets/b2c70d55-5f09-421a-bde3-f49939c6effc">

~~For a follow up PR:
I think it's time to move some of rive_common into rive_native. I think the layout stuff would be a good start. @philter take a look at how the rive_binding.cpp is shared in rive_native for both FFI and WASM. I think it would simplify our layout bindings to use this model too.~~
Nevermind, we need it for this PR or ```LayoutNode.fromExternal``` doesn't work.

Diffs=
1a5f273bb Nested artboard types: node, leaf, layout (#7639)

Co-authored-by: Luigi Rosso <[email protected]>
  • Loading branch information
luigi-rosso and luigi-rosso committed Jul 24, 2024
1 parent 560a993 commit 9f0db02
Show file tree
Hide file tree
Showing 24 changed files with 743 additions and 269 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
50bc398c464061bb2ab5ac51e42901053ae63f1f
1a5f273bb6534a395d1c3cdcc11a1ba3cd80a96c
18 changes: 1 addition & 17 deletions dev/defs/nested_artboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,13 @@
},
"description": "Identifier used to track the Artboard nested."
},
"fit": {
"type": "uint",
"key": {
"int": 538,
"string": "fit"
},
"description": "Fit type for the nested artboard's runtime artboard."
},
"alignment": {
"type": "uint",
"key": {
"int": 539,
"string": "alignment"
},
"description": "Alignment type for the nested artboard's runtime artboard."
},
"dataBindPathIds": {
"type": "List<Id>",
"typeRuntime": "Bytes",
"encoded": true,
"initialValue": "[]",
"key": {
"int": 580,
"int": 582,
"string": "databindpathids"
},
"description": "Path to the selected property."
Expand Down
8 changes: 8 additions & 0 deletions dev/defs/nested_artboard_layout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "NestedArtboardLayout",
"key": {
"int": 452,
"string": "nestedartboardlayout"
},
"extends": "nested_artboard.json"
}
34 changes: 34 additions & 0 deletions dev/defs/nested_artboard_leaf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "NestedArtboardLeaf",
"key": {
"int": 451,
"string": "nested_artboard_leaf"
},
"extends": "nested_artboard.json",
"properties": {
"fit": {
"type": "uint",
"key": {
"int": 538,
"string": "fit"
},
"description": "Fit type for the nested artboard's runtime artboard."
},
"alignmentX": {
"type": "double",
"key": {
"int": 644,
"string": "alignmentx"
},
"description": "Alignment value on X."
},
"alignmentY": {
"type": "double",
"key": {
"int": 645,
"string": "alignmenty"
},
"description": "Alignment value on Y."
}
}
}
36 changes: 20 additions & 16 deletions include/rive/artboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class Artboard : public ArtboardBase, public CoreContext
std::unordered_set<LayoutComponent*> m_dirtyLayout;
float m_originalWidth = 0;
float m_originalHeight = 0;
bool m_updatesOwnLayout = true;
Artboard* parentArtboard() const;
NestedArtboard* m_host = nullptr;
bool sharesLayoutWithHost() const;

#ifdef EXTERNAL_RIVE_AUDIO_ENGINE
rcp<AudioEngine> m_audioEngine;
Expand All @@ -85,8 +89,14 @@ class Artboard : public ArtboardBase, public CoreContext
void sortDependencies();
void sortDrawOrder();
void updateDataBinds();
void performUpdate(ComponentDirt value) override;
void updateRenderPath() override;
void update(ComponentDirt value) override;

public:
void host(NestedArtboard* nestedArtboard);
NestedArtboard* host() const;

private:
#ifdef TESTING
public:
Artboard(Factory* factory) : m_Factory(factory) {}
Expand All @@ -96,7 +106,7 @@ class Artboard : public ArtboardBase, public CoreContext
void addStateMachine(StateMachine* object);

public:
Artboard() {}
Artboard();
~Artboard() override;
StatusCode initialize();

Expand Down Expand Up @@ -124,21 +134,10 @@ class Artboard : public ArtboardBase, public CoreContext
// Artboard is a special type of LayoutComponent
void updateWorldTransform() override {}

void markLayoutDirty(LayoutComponent* layoutComponent)
{
m_dirtyLayout.insert(layoutComponent);
}
void markLayoutDirty(LayoutComponent* layoutComponent);

#ifdef WITH_RIVE_LAYOUT
AABB layoutBounds() override
{
if (!hasLayoutMeasurements())
{
return AABB(x(), y(), x() + width(), y() + height());
}
return Super::layoutBounds();
}
#endif
void* takeLayoutNode();
bool syncStyleChanges();

bool advance(double elapsedSeconds, bool nested = true);
bool advanceInternal(double elapsedSeconds, bool isRoot, bool nested = true);
Expand Down Expand Up @@ -171,7 +170,10 @@ class Artboard : public ArtboardBase, public CoreContext
float originalHeight() const { return m_originalHeight; }
float layoutWidth() const;
float layoutHeight() const;
float layoutX() const;
float layoutY() const;
AABB bounds() const;
Vec2D origin() const;

// Can we hide these from the public? (they use playable)
bool isTranslucent() const;
Expand Down Expand Up @@ -366,9 +368,11 @@ class Artboard : public ArtboardBase, public CoreContext
float m_volume = 1.0f;
#ifdef WITH_RIVE_TOOLS
ArtboardCallback m_layoutChangedCallback = nullptr;
ArtboardCallback m_layoutDirtyCallback = nullptr;

public:
void onLayoutChanged(ArtboardCallback callback) { m_layoutChangedCallback = callback; }
void onLayoutDirty(ArtboardCallback callback) { m_layoutDirtyCallback = callback; }
#endif
};

Expand Down
46 changes: 30 additions & 16 deletions include/rive/generated/core_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
#include "rive/layout_component.hpp"
#include "rive/nested_animation.hpp"
#include "rive/nested_artboard.hpp"
#include "rive/nested_artboard_layout.hpp"
#include "rive/nested_artboard_leaf.hpp"
#include "rive/node.hpp"
#include "rive/open_url_event.hpp"
#include "rive/shapes/clipping_shape.hpp"
Expand Down Expand Up @@ -258,6 +260,8 @@ class CoreRegistry
return new NestedArtboard();
case SoloBase::typeKey:
return new Solo();
case NestedArtboardLayoutBase::typeKey:
return new NestedArtboardLayout();
case LayoutComponentStyleBase::typeKey:
return new LayoutComponentStyle();
case ListenerFireEventBase::typeKey:
Expand Down Expand Up @@ -428,6 +432,8 @@ class CoreRegistry
return new BindablePropertyEnum();
case BindablePropertyColorBase::typeKey:
return new BindablePropertyColor();
case NestedArtboardLeafBase::typeKey:
return new NestedArtboardLeaf();
case WeightBase::typeKey:
return new Weight();
case BoneBase::typeKey:
Expand Down Expand Up @@ -639,12 +645,6 @@ class CoreRegistry
case NestedArtboardBase::artboardIdPropertyKey:
object->as<NestedArtboardBase>()->artboardId(value);
break;
case NestedArtboardBase::fitPropertyKey:
object->as<NestedArtboardBase>()->fit(value);
break;
case NestedArtboardBase::alignmentPropertyKey:
object->as<NestedArtboardBase>()->alignment(value);
break;
case NestedAnimationBase::animationIdPropertyKey:
object->as<NestedAnimationBase>()->animationId(value);
break;
Expand Down Expand Up @@ -951,6 +951,9 @@ class CoreRegistry
case BindablePropertyEnumBase::propertyValuePropertyKey:
object->as<BindablePropertyEnumBase>()->propertyValue(value);
break;
case NestedArtboardLeafBase::fitPropertyKey:
object->as<NestedArtboardLeafBase>()->fit(value);
break;
case WeightBase::valuesPropertyKey:
object->as<WeightBase>()->values(value);
break;
Expand Down Expand Up @@ -1466,6 +1469,12 @@ class CoreRegistry
case BindablePropertyNumberBase::propertyValuePropertyKey:
object->as<BindablePropertyNumberBase>()->propertyValue(value);
break;
case NestedArtboardLeafBase::alignmentXPropertyKey:
object->as<NestedArtboardLeafBase>()->alignmentX(value);
break;
case NestedArtboardLeafBase::alignmentYPropertyKey:
object->as<NestedArtboardLeafBase>()->alignmentY(value);
break;
case BoneBase::lengthPropertyKey:
object->as<BoneBase>()->length(value);
break;
Expand Down Expand Up @@ -1721,10 +1730,6 @@ class CoreRegistry
return object->as<DrawableBase>()->drawableFlags();
case NestedArtboardBase::artboardIdPropertyKey:
return object->as<NestedArtboardBase>()->artboardId();
case NestedArtboardBase::fitPropertyKey:
return object->as<NestedArtboardBase>()->fit();
case NestedArtboardBase::alignmentPropertyKey:
return object->as<NestedArtboardBase>()->alignment();
case NestedAnimationBase::animationIdPropertyKey:
return object->as<NestedAnimationBase>()->animationId();
case SoloBase::activeComponentIdPropertyKey:
Expand Down Expand Up @@ -1929,6 +1934,8 @@ class CoreRegistry
return object->as<DataBindBase>()->flags();
case BindablePropertyEnumBase::propertyValuePropertyKey:
return object->as<BindablePropertyEnumBase>()->propertyValue();
case NestedArtboardLeafBase::fitPropertyKey:
return object->as<NestedArtboardLeafBase>()->fit();
case WeightBase::valuesPropertyKey:
return object->as<WeightBase>()->values();
case WeightBase::indicesPropertyKey:
Expand Down Expand Up @@ -2282,6 +2289,10 @@ class CoreRegistry
return object->as<JoystickBase>()->height();
case BindablePropertyNumberBase::propertyValuePropertyKey:
return object->as<BindablePropertyNumberBase>()->propertyValue();
case NestedArtboardLeafBase::alignmentXPropertyKey:
return object->as<NestedArtboardLeafBase>()->alignmentX();
case NestedArtboardLeafBase::alignmentYPropertyKey:
return object->as<NestedArtboardLeafBase>()->alignmentY();
case BoneBase::lengthPropertyKey:
return object->as<BoneBase>()->length();
case RootBoneBase::xPropertyKey:
Expand Down Expand Up @@ -2426,8 +2437,6 @@ class CoreRegistry
case DrawableBase::blendModeValuePropertyKey:
case DrawableBase::drawableFlagsPropertyKey:
case NestedArtboardBase::artboardIdPropertyKey:
case NestedArtboardBase::fitPropertyKey:
case NestedArtboardBase::alignmentPropertyKey:
case NestedAnimationBase::animationIdPropertyKey:
case SoloBase::activeComponentIdPropertyKey:
case LayoutComponentStyleBase::scaleTypePropertyKey:
Expand Down Expand Up @@ -2530,6 +2539,7 @@ class CoreRegistry
case DataBindBase::propertyKeyPropertyKey:
case DataBindBase::flagsPropertyKey:
case BindablePropertyEnumBase::propertyValuePropertyKey:
case NestedArtboardLeafBase::fitPropertyKey:
case WeightBase::valuesPropertyKey:
case WeightBase::indicesPropertyKey:
case TendonBase::boneIdPropertyKey:
Expand Down Expand Up @@ -2700,6 +2710,8 @@ class CoreRegistry
case JoystickBase::widthPropertyKey:
case JoystickBase::heightPropertyKey:
case BindablePropertyNumberBase::propertyValuePropertyKey:
case NestedArtboardLeafBase::alignmentXPropertyKey:
case NestedArtboardLeafBase::alignmentYPropertyKey:
case BoneBase::lengthPropertyKey:
case RootBoneBase::xPropertyKey:
case RootBoneBase::yPropertyKey:
Expand Down Expand Up @@ -2872,10 +2884,6 @@ class CoreRegistry
return object->is<DrawableBase>();
case NestedArtboardBase::artboardIdPropertyKey:
return object->is<NestedArtboardBase>();
case NestedArtboardBase::fitPropertyKey:
return object->is<NestedArtboardBase>();
case NestedArtboardBase::alignmentPropertyKey:
return object->is<NestedArtboardBase>();
case NestedAnimationBase::animationIdPropertyKey:
return object->is<NestedAnimationBase>();
case SoloBase::activeComponentIdPropertyKey:
Expand Down Expand Up @@ -3080,6 +3088,8 @@ class CoreRegistry
return object->is<DataBindBase>();
case BindablePropertyEnumBase::propertyValuePropertyKey:
return object->is<BindablePropertyEnumBase>();
case NestedArtboardLeafBase::fitPropertyKey:
return object->is<NestedArtboardLeafBase>();
case WeightBase::valuesPropertyKey:
return object->is<WeightBase>();
case WeightBase::indicesPropertyKey:
Expand Down Expand Up @@ -3412,6 +3422,10 @@ class CoreRegistry
return object->is<JoystickBase>();
case BindablePropertyNumberBase::propertyValuePropertyKey:
return object->is<BindablePropertyNumberBase>();
case NestedArtboardLeafBase::alignmentXPropertyKey:
return object->is<NestedArtboardLeafBase>();
case NestedArtboardLeafBase::alignmentYPropertyKey:
return object->is<NestedArtboardLeafBase>();
case BoneBase::lengthPropertyKey:
return object->is<BoneBase>();
case RootBoneBase::xPropertyKey:
Expand Down
38 changes: 1 addition & 37 deletions include/rive/generated/nested_artboard_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ class NestedArtboardBase : public Drawable
uint16_t coreType() const override { return typeKey; }

static const uint16_t artboardIdPropertyKey = 197;
static const uint16_t fitPropertyKey = 538;
static const uint16_t alignmentPropertyKey = 539;
static const uint16_t dataBindPathIdsPropertyKey = 580;
static const uint16_t dataBindPathIdsPropertyKey = 582;

private:
uint32_t m_ArtboardId = -1;
uint32_t m_Fit = 0;
uint32_t m_Alignment = 0;

public:
inline uint32_t artboardId() const { return m_ArtboardId; }
Expand All @@ -57,37 +53,13 @@ class NestedArtboardBase : public Drawable
artboardIdChanged();
}

inline uint32_t fit() const { return m_Fit; }
void fit(uint32_t value)
{
if (m_Fit == value)
{
return;
}
m_Fit = value;
fitChanged();
}

inline uint32_t alignment() const { return m_Alignment; }
void alignment(uint32_t value)
{
if (m_Alignment == value)
{
return;
}
m_Alignment = value;
alignmentChanged();
}

virtual void decodeDataBindPathIds(Span<const uint8_t> value) = 0;
virtual void copyDataBindPathIds(const NestedArtboardBase& object) = 0;

Core* clone() const override;
void copy(const NestedArtboardBase& object)
{
m_ArtboardId = object.m_ArtboardId;
m_Fit = object.m_Fit;
m_Alignment = object.m_Alignment;
copyDataBindPathIds(object);
Drawable::copy(object);
}
Expand All @@ -99,12 +71,6 @@ class NestedArtboardBase : public Drawable
case artboardIdPropertyKey:
m_ArtboardId = CoreUintType::deserialize(reader);
return true;
case fitPropertyKey:
m_Fit = CoreUintType::deserialize(reader);
return true;
case alignmentPropertyKey:
m_Alignment = CoreUintType::deserialize(reader);
return true;
case dataBindPathIdsPropertyKey:
decodeDataBindPathIds(CoreBytesType::deserialize(reader));
return true;
Expand All @@ -114,8 +80,6 @@ class NestedArtboardBase : public Drawable

protected:
virtual void artboardIdChanged() {}
virtual void fitChanged() {}
virtual void alignmentChanged() {}
virtual void dataBindPathIdsChanged() {}
};
} // namespace rive
Expand Down
Loading

0 comments on commit 9f0db02

Please sign in to comment.