Skip to content

Commit

Permalink
Xxxx databinding add boolean
Browse files Browse the repository at this point in the history
Adding booleans to the list of view model primitives

Diffs=
e66e242c6 Xxxx databinding add boolean (#7456)

Co-authored-by: hernan <[email protected]>
  • Loading branch information
bodymovin and bodymovin committed Jun 21, 2024
1 parent 8edc70f commit 3c092fd
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9cd8759a02aaa45684e80a8d77671c1536ab387d
e66e242c649e3e61f12a3adbd824bcd9a7525a53
29 changes: 29 additions & 0 deletions dev/defs/viewmodel/viewmodel_instance_boolean.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "ViewModelInstanceBoolean",
"key": {
"int": 449,
"string": "viewmodelinstanceboolean"
},
"extends": "viewmodel/viewmodel_instance_value.json",
"properties": {
"propertyValue": {
"type": "bool",
"initialValue": "false",
"key": {
"int": 593,
"string": "propertyvalue"
},
"description": "The boolean value."
},
"playbackValue": {
"type": "bool",
"initialValue": "false",
"key": {
"int": 594,
"string": "playbackvalue"
},
"runtime": false,
"coop": false
}
}
}
8 changes: 8 additions & 0 deletions dev/defs/viewmodel/viewmodel_property_boolean.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "ViewModelPropertyBoolean",
"key": {
"int": 448,
"string": "viewmodelpropertyboolean"
},
"extends": "viewmodel/viewmodel_property.json"
}
19 changes: 19 additions & 0 deletions include/rive/data_bind/context/context_value_boolean.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef _RIVE_DATA_BIND_CONTEXT_VALUE_BOOLEAN_HPP_
#define _RIVE_DATA_BIND_CONTEXT_VALUE_BOOLEAN_HPP_
#include "rive/data_bind/context/context_value.hpp"
namespace rive
{
class DataBindContextValueBoolean : public DataBindContextValue
{

public:
DataBindContextValueBoolean(ViewModelInstanceValue* value);
void apply(Component* component, uint32_t propertyKey) override;
virtual void applyToSource(Component* component, uint32_t propertyKey) override;

private:
bool m_Value;
};
} // namespace rive

#endif
14 changes: 14 additions & 0 deletions include/rive/generated/core_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
#include "rive/viewmodel/viewmodel.hpp"
#include "rive/viewmodel/viewmodel_component.hpp"
#include "rive/viewmodel/viewmodel_instance.hpp"
#include "rive/viewmodel/viewmodel_instance_boolean.hpp"
#include "rive/viewmodel/viewmodel_instance_color.hpp"
#include "rive/viewmodel/viewmodel_instance_enum.hpp"
#include "rive/viewmodel/viewmodel_instance_list.hpp"
Expand All @@ -167,6 +168,7 @@
#include "rive/viewmodel/viewmodel_instance_value.hpp"
#include "rive/viewmodel/viewmodel_instance_viewmodel.hpp"
#include "rive/viewmodel/viewmodel_property.hpp"
#include "rive/viewmodel/viewmodel_property_boolean.hpp"
#include "rive/viewmodel/viewmodel_property_color.hpp"
#include "rive/viewmodel/viewmodel_property_enum.hpp"
#include "rive/viewmodel/viewmodel_property_list.hpp"
Expand Down Expand Up @@ -205,12 +207,16 @@ class CoreRegistry
return new ViewModelPropertyViewModel();
case ViewModelInstanceBase::typeKey:
return new ViewModelInstance();
case ViewModelPropertyBooleanBase::typeKey:
return new ViewModelPropertyBoolean();
case DataEnumBase::typeKey:
return new DataEnum();
case ViewModelPropertyEnumBase::typeKey:
return new ViewModelPropertyEnum();
case ViewModelPropertyColorBase::typeKey:
return new ViewModelPropertyColor();
case ViewModelInstanceBooleanBase::typeKey:
return new ViewModelInstanceBoolean();
case ViewModelInstanceListBase::typeKey:
return new ViewModelInstanceList();
case ViewModelInstanceNumberBase::typeKey:
Expand Down Expand Up @@ -455,6 +461,9 @@ class CoreRegistry
case ViewModelInstanceListItemBase::useLinkedArtboardPropertyKey:
object->as<ViewModelInstanceListItemBase>()->useLinkedArtboard(value);
break;
case ViewModelInstanceBooleanBase::propertyValuePropertyKey:
object->as<ViewModelInstanceBooleanBase>()->propertyValue(value);
break;
case TransformComponentConstraintBase::offsetPropertyKey:
object->as<TransformComponentConstraintBase>()->offset(value);
break;
Expand Down Expand Up @@ -1459,6 +1468,8 @@ class CoreRegistry
{
case ViewModelInstanceListItemBase::useLinkedArtboardPropertyKey:
return object->as<ViewModelInstanceListItemBase>()->useLinkedArtboard();
case ViewModelInstanceBooleanBase::propertyValuePropertyKey:
return object->as<ViewModelInstanceBooleanBase>()->propertyValue();
case TransformComponentConstraintBase::offsetPropertyKey:
return object->as<TransformComponentConstraintBase>()->offset();
case TransformComponentConstraintBase::doesCopyPropertyKey:
Expand Down Expand Up @@ -2135,6 +2146,7 @@ class CoreRegistry
switch (propertyKey)
{
case ViewModelInstanceListItemBase::useLinkedArtboardPropertyKey:
case ViewModelInstanceBooleanBase::propertyValuePropertyKey:
case TransformComponentConstraintBase::offsetPropertyKey:
case TransformComponentConstraintBase::doesCopyPropertyKey:
case TransformComponentConstraintBase::minPropertyKey:
Expand Down Expand Up @@ -2487,6 +2499,8 @@ class CoreRegistry
{
case ViewModelInstanceListItemBase::useLinkedArtboardPropertyKey:
return object->is<ViewModelInstanceListItemBase>();
case ViewModelInstanceBooleanBase::propertyValuePropertyKey:
return object->is<ViewModelInstanceBooleanBase>();
case TransformComponentConstraintBase::offsetPropertyKey:
return object->is<TransformComponentConstraintBase>();
case TransformComponentConstraintBase::doesCopyPropertyKey:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef _RIVE_VIEW_MODEL_INSTANCE_BOOLEAN_BASE_HPP_
#define _RIVE_VIEW_MODEL_INSTANCE_BOOLEAN_BASE_HPP_
#include "rive/core/field_types/core_bool_type.hpp"
#include "rive/viewmodel/viewmodel_instance_value.hpp"
namespace rive
{
class ViewModelInstanceBooleanBase : public ViewModelInstanceValue
{
protected:
typedef ViewModelInstanceValue Super;

public:
static const uint16_t typeKey = 449;

/// Helper to quickly determine if a core object extends another without RTTI
/// at runtime.
bool isTypeOf(uint16_t typeKey) const override
{
switch (typeKey)
{
case ViewModelInstanceBooleanBase::typeKey:
case ViewModelInstanceValueBase::typeKey:
return true;
default:
return false;
}
}

uint16_t coreType() const override { return typeKey; }

static const uint16_t propertyValuePropertyKey = 593;

private:
bool m_PropertyValue = false;

public:
inline bool propertyValue() const { return m_PropertyValue; }
void propertyValue(bool value)
{
if (m_PropertyValue == value)
{
return;
}
m_PropertyValue = value;
propertyValueChanged();
}

Core* clone() const override;
void copy(const ViewModelInstanceBooleanBase& object)
{
m_PropertyValue = object.m_PropertyValue;
ViewModelInstanceValue::copy(object);
}

bool deserialize(uint16_t propertyKey, BinaryReader& reader) override
{
switch (propertyKey)
{
case propertyValuePropertyKey:
m_PropertyValue = CoreBoolType::deserialize(reader);
return true;
}
return ViewModelInstanceValue::deserialize(propertyKey, reader);
}

protected:
virtual void propertyValueChanged() {}
};
} // namespace rive

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef _RIVE_VIEW_MODEL_PROPERTY_BOOLEAN_BASE_HPP_
#define _RIVE_VIEW_MODEL_PROPERTY_BOOLEAN_BASE_HPP_
#include "rive/viewmodel/viewmodel_property.hpp"
namespace rive
{
class ViewModelPropertyBooleanBase : public ViewModelProperty
{
protected:
typedef ViewModelProperty Super;

public:
static const uint16_t typeKey = 448;

/// Helper to quickly determine if a core object extends another without RTTI
/// at runtime.
bool isTypeOf(uint16_t typeKey) const override
{
switch (typeKey)
{
case ViewModelPropertyBooleanBase::typeKey:
case ViewModelPropertyBase::typeKey:
case ViewModelComponentBase::typeKey:
return true;
default:
return false;
}
}

uint16_t coreType() const override { return typeKey; }

Core* clone() const override;

protected:
};
} // namespace rive

#endif
14 changes: 14 additions & 0 deletions include/rive/viewmodel/viewmodel_instance_boolean.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _RIVE_VIEW_MODEL_INSTANCE_BOOLEAN_HPP_
#define _RIVE_VIEW_MODEL_INSTANCE_BOOLEAN_HPP_
#include "rive/generated/viewmodel/viewmodel_instance_boolean_base.hpp"
#include <stdio.h>
namespace rive
{
class ViewModelInstanceBoolean : public ViewModelInstanceBooleanBase
{
protected:
void propertyValueChanged() override;
};
} // namespace rive

#endif
13 changes: 13 additions & 0 deletions include/rive/viewmodel/viewmodel_property_boolean.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _RIVE_VIEW_MODEL_PROPERTY_BOOLEAN_HPP_
#define _RIVE_VIEW_MODEL_PROPERTY_BOOLEAN_HPP_
#include "rive/generated/viewmodel/viewmodel_property_boolean_base.hpp"
#include <stdio.h>
namespace rive
{
class ViewModelPropertyBoolean : public ViewModelPropertyBooleanBase
{
public:
};
} // namespace rive

#endif
26 changes: 26 additions & 0 deletions src/data_bind/context/context_value_boolean.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "rive/data_bind/context/context_value_boolean.hpp"
#include "rive/generated/core_registry.hpp"

using namespace rive;

DataBindContextValueBoolean::DataBindContextValueBoolean(ViewModelInstanceValue* value)
{
m_Source = value;
}

void DataBindContextValueBoolean::apply(Component* target, uint32_t propertyKey)
{
CoreRegistry::setBool(target,
propertyKey,
m_Source->as<ViewModelInstanceBoolean>()->propertyValue());
}

void DataBindContextValueBoolean::applyToSource(Component* target, uint32_t propertyKey)
{
auto value = CoreRegistry::getBool(target, propertyKey);
if (m_Value != value)
{
m_Value = value;
m_Source->as<ViewModelInstanceBoolean>()->propertyValue(value);
}
}
4 changes: 4 additions & 0 deletions src/data_bind/data_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "rive/artboard.hpp"
#include "rive/generated/core_registry.hpp"
#include "rive/data_bind/context/context_value.hpp"
#include "rive/data_bind/context/context_value_boolean.hpp"
#include "rive/data_bind/context/context_value_number.hpp"
#include "rive/data_bind/context/context_value_string.hpp"
#include "rive/data_bind/context/context_value_enum.hpp"
Expand Down Expand Up @@ -66,6 +67,9 @@ void DataBind::bind()
case ViewModelInstanceColorBase::typeKey:
m_ContextValue = rivestd::make_unique<DataBindContextValueColor>(m_Source);
break;
case ViewModelInstanceBooleanBase::typeKey:
m_ContextValue = rivestd::make_unique<DataBindContextValueBoolean>(m_Source);
break;
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/generated/viewmodel/viewmodel_instance_boolean_base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "rive/generated/viewmodel/viewmodel_instance_boolean_base.hpp"
#include "rive/viewmodel/viewmodel_instance_boolean.hpp"

using namespace rive;

Core* ViewModelInstanceBooleanBase::clone() const
{
auto cloned = new ViewModelInstanceBoolean();
cloned->copy(*this);
return cloned;
}
11 changes: 11 additions & 0 deletions src/generated/viewmodel/viewmodel_property_boolean_base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "rive/generated/viewmodel/viewmodel_property_boolean_base.hpp"
#include "rive/viewmodel/viewmodel_property_boolean.hpp"

using namespace rive;

Core* ViewModelPropertyBooleanBase::clone() const
{
auto cloned = new ViewModelPropertyBoolean();
cloned->copy(*this);
return cloned;
}
10 changes: 10 additions & 0 deletions src/viewmodel/viewmodel_instance_boolean.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <sstream>
#include <iomanip>
#include <array>

#include "rive/viewmodel/viewmodel_instance_boolean.hpp"
#include "rive/component_dirt.hpp"

using namespace rive;

void ViewModelInstanceBoolean::propertyValueChanged() { addDirt(ComponentDirt::Bindings); }

0 comments on commit 3c092fd

Please sign in to comment.