Skip to content

Commit 5a94a09

Browse files
bodymovinbodymovin
andcommitted
feature: add support for relative view model data bind paths for nested artboards (#11344) 923b32059d
feature: add support for relative view model data bind paths Co-authored-by: hernan <hernan@rive.app>
1 parent a78f52b commit 5a94a09

31 files changed

+614
-61
lines changed

.rive_head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
699b891b79a7af1220616e0900a3d4d5d1c40448
1+
923b32059d2ea012fdb47ae141b304f57095a48b
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "DataBindPath",
3+
"key": {
4+
"int": 643,
5+
"string": "databindpath"
6+
},
7+
"properties": {
8+
"path": {
9+
"type": "List<Id>",
10+
"typeRuntime": "Bytes",
11+
"encoded": true,
12+
"initialValue": "[]",
13+
"key": {
14+
"int": 920,
15+
"string": "path"
16+
},
17+
"description": "Path to the selected property"
18+
},
19+
"isRelative": {
20+
"type": "bool",
21+
"initialValue": "false",
22+
"key": {
23+
"int": 921,
24+
"string": "isrelative"
25+
},
26+
"description": "Whether the data bind path is relative"
27+
}
28+
}
29+
}

dev/defs/nested_artboard.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
},
3030
"description": "Path to the selected property."
3131
},
32+
"isDataBindPathRelative": {
33+
"type": "bool",
34+
"initialValue": "false",
35+
"key": {
36+
"int": 916,
37+
"string": "isdatabindpathrelative"
38+
},
39+
"description": "Whether the data bind path is relative",
40+
"runtime": false
41+
},
3242
"isPaused": {
3343
"type": "bool",
3444
"initialValue": "false",

include/rive/artboard_host.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _RIVE_ARTBOARD_HOST_HPP_
33
#include "rive/refcnt.hpp"
44
#include "rive/file.hpp"
5+
#include "rive/data_bind_path_referencer.hpp"
56
#include <stdio.h>
67
namespace rive
78
{
@@ -10,12 +11,11 @@ class DataBind;
1011
class DataContext;
1112
class ViewModelInstance;
1213

13-
class ArtboardHost
14+
class ArtboardHost : public DataBindPathReferencer
1415
{
1516
public:
1617
virtual size_t artboardCount() = 0;
1718
virtual ArtboardInstance* artboardInstance(int index = 0) = 0;
18-
virtual std::vector<uint32_t> dataBindPathIds() { return {}; }
1919
virtual void internalDataContext(DataContext* dataContext) = 0;
2020
virtual void bindViewModelInstance(rcp<ViewModelInstance> viewModelInstance,
2121
DataContext* parent) = 0;

include/rive/assets/manifest_asset.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#ifndef _RIVE_MANIFEST_ASSET_HPP_
22
#define _RIVE_MANIFEST_ASSET_HPP_
33
#include "rive/generated/assets/manifest_asset_base.hpp"
4-
#include "rive/name_resolver.hpp"
4+
#include "rive/data_resolver.hpp"
55
#include <stdio.h>
66
#include <unordered_map>
77
#include <string>
88
namespace rive
99
{
10-
class ManifestAsset : public ManifestAssetBase, public NameResolver
10+
class ManifestAsset : public ManifestAssetBase, public DataResolver
1111
{
1212
private:
1313
std::unordered_map<int, std::string> m_names;
14+
std::unordered_map<int, std::vector<uint32_t>> m_paths;
1415
static const std::string empty;
16+
static const std::vector<uint32_t> emptyIntVector;
17+
bool decodeNames(BinaryReader& reader);
18+
bool decodePaths(BinaryReader& reader);
1519

1620
protected:
1721
bool addsToBackboard() override { return false; }
@@ -20,6 +24,7 @@ class ManifestAsset : public ManifestAssetBase, public NameResolver
2024
bool decode(SimpleArray<uint8_t>&, Factory*) override;
2125
std::string fileExtension() const override;
2226
const std::string& resolveName(int id) override;
27+
const std::vector<uint32_t>& resolvePath(int id) override;
2328
};
2429
} // namespace rive
2530

include/rive/data_bind/data_bind_context.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class DataBindContext : public DataBindContextBase
1717
void decodeSourcePathIds(Span<const uint8_t> value) override;
1818
void copySourcePathIds(const DataBindContextBase& object) override;
1919
void bindFromContext(DataContext* dataContext);
20+
21+
private:
22+
void resolvePath();
23+
bool m_isPathResolved = false;
2024
};
2125
} // namespace rive
2226

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef _RIVE_DATA_BIND_PATH_HPP_
2+
#define _RIVE_DATA_BIND_PATH_HPP_
3+
#include "rive/generated/data_bind/data_bind_path_base.hpp"
4+
#include <stdio.h>
5+
namespace rive
6+
{
7+
class File;
8+
class DataBindPath : public DataBindPathBase
9+
{
10+
public:
11+
void decodePath(Span<const uint8_t> value) override;
12+
void copyPath(const DataBindPathBase& object) override;
13+
StatusCode import(ImportStack& importStack) override;
14+
std::vector<uint32_t>& path() { return m_pathBuffer; }
15+
const std::vector<uint32_t>& resolvedPath();
16+
void file(File* value);
17+
File* file() { return m_file; };
18+
void resolved(bool value) { m_resolved = value; }
19+
20+
protected:
21+
std::vector<uint32_t> m_pathBuffer;
22+
23+
private:
24+
File* m_file = nullptr;
25+
bool m_resolved = false;
26+
};
27+
} // namespace rive
28+
29+
#endif

include/rive/data_bind/data_context.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#define _RIVE_DATA_CONTEXT_HPP_
33
#include "rive/viewmodel/viewmodel_instance_value.hpp"
44
#include "rive/viewmodel/viewmodel_instance.hpp"
5-
#include "rive/name_resolver.hpp"
5+
#include "rive/data_resolver.hpp"
66
#include "rive/refcnt.hpp"
77

88
namespace rive
99
{
10+
class DataBindPath;
1011
class DataContext
1112
{
1213
private:
@@ -22,9 +23,13 @@ class DataContext
2223
const std::vector<uint32_t> path) const;
2324
ViewModelInstanceValue* getRelativeViewModelProperty(
2425
const std::vector<uint32_t> path,
25-
NameResolver* resolver) const;
26+
DataResolver* resolver) const;
2627
rcp<ViewModelInstance> getViewModelInstance(
2728
const std::vector<uint32_t> path) const;
29+
rcp<ViewModelInstance> getViewModelInstance(DataBindPath*) const;
30+
rcp<ViewModelInstance> getRelativeViewModelInstance(
31+
const std::vector<uint32_t> path,
32+
DataResolver* resolver) const;
2833
void viewModelInstance(rcp<ViewModelInstance> value);
2934
void advanced();
3035
rcp<ViewModelInstance> viewModelInstance() { return m_ViewModelInstance; };
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef _RIVE_DATA_BIND_PATH_REFERENCER_HPP_
2+
#define _RIVE_DATA_BIND_PATH_REFERENCER_HPP_
3+
#include <stdio.h>
4+
#include "rive/data_bind/data_bind_path.hpp"
5+
namespace rive
6+
{
7+
class File;
8+
class DataBindPathReferencer
9+
{
10+
public:
11+
~DataBindPathReferencer();
12+
DataBindPath* dataBindPath() const { return m_dataBindPath; }
13+
14+
void copyDataBindPath(DataBindPath* dataBindPath);
15+
void importDataBindPath(ImportStack& importStack);
16+
void decodeDataBindPath(Span<const uint8_t>& value);
17+
18+
protected:
19+
DataBindPath* m_dataBindPath = nullptr;
20+
};
21+
} // namespace rive
22+
23+
#endif

include/rive/data_resolver.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef _RIVE_DATA_RESOLVER_HPP_
2+
#define _RIVE_DATA_RESOLVER_HPP_
3+
#include <stdio.h>
4+
#include <string>
5+
namespace rive
6+
{
7+
class DataResolver
8+
{
9+
public:
10+
virtual const std::string& resolveName(int id) = 0;
11+
virtual const std::vector<uint32_t>& resolvePath(int id) = 0;
12+
};
13+
} // namespace rive
14+
15+
#endif

0 commit comments

Comments
 (0)