Skip to content

Commit

Permalink
add fixes and code improvements
Browse files Browse the repository at this point in the history
some small fixes and changes
commented the more relevant parts

Diffs=
a84aea792 add fixes and code improvements (#8095)

Co-authored-by: hernan <[email protected]>
  • Loading branch information
bodymovin and bodymovin committed Sep 7, 2024
1 parent 699b1fd commit 5a2bb50
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5cd451423d0ff240bebc7fe455ec9898d11768fa
a84aea792f208119fbea5c0fe0704c9d484aaa2c
4 changes: 2 additions & 2 deletions include/rive/data_bind/context/context_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DataBindContextValue
{
return dataValue->as<T>()->value();
}
return (new T())->value();
return T::defaultValue;
};
template <typename T = DataValue, typename U> U getReverseDataValue(DataValue* input)
{
Expand All @@ -36,7 +36,7 @@ class DataBindContextValue
{
return dataValue->as<T>()->value();
}
return (new T())->value();
return T::defaultValue;
};
template <typename T = DataValue, typename U>
U calculateValue(DataValue* input, bool isMainDirection)
Expand Down
4 changes: 0 additions & 4 deletions include/rive/data_bind/data_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ class DataContext
{
private:
DataContext* m_Parent = nullptr;
std::vector<ViewModelInstance*> m_ViewModelInstances;
ViewModelInstance* m_ViewModelInstance;

public:
DataContext();
DataContext(ViewModelInstance* viewModelInstance);
~DataContext();

DataContext* parent() { return m_Parent; }
void parent(DataContext* value) { m_Parent = value; }
void addViewModelInstance(ViewModelInstance* value);
ViewModelInstanceValue* getViewModelProperty(const std::vector<uint32_t> path) const;
ViewModelInstance* getViewModelInstance(const std::vector<uint32_t> path) const;
void viewModelInstance(ViewModelInstance* value);
Expand Down
1 change: 1 addition & 0 deletions include/rive/data_bind/data_values/data_value_boolean.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class DataValueBoolean : public DataValue
bool isTypeOf(DataType typeKey) const override { return typeKey == DataType::boolean; }
bool value() { return m_value; };
void value(bool value) { m_value = value; };
static const bool defaultValue = false;
};
} // namespace rive

Expand Down
3 changes: 2 additions & 1 deletion include/rive/data_bind/data_values/data_value_color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace rive
class DataValueColor : public DataValue
{
private:
int m_value = false;
int m_value = 0;

public:
DataValueColor(int value) : m_value(value){};
Expand All @@ -17,6 +17,7 @@ class DataValueColor : public DataValue
bool isTypeOf(DataType typeKey) const override { return typeKey == DataType::color; }
int value() { return m_value; };
void value(int value) { m_value = value; };
static const int defaultValue = 0;
};
} // namespace rive

Expand Down
1 change: 1 addition & 0 deletions include/rive/data_bind/data_values/data_value_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DataValueEnum : public DataValue
void value(uint32_t value) { m_value = value; };
DataEnum* dataEnum() { return m_dataEnum; };
void dataEnum(DataEnum* value) { m_dataEnum = value; };
static const uint32_t defaultValue = 0;
};
} // namespace rive
#endif
1 change: 1 addition & 0 deletions include/rive/data_bind/data_values/data_value_number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class DataValueNumber : public DataValue
bool isTypeOf(DataType typeKey) const override { return typeKey == DataType::number; }
float value() { return m_value; };
void value(float value) { m_value = value; };
constexpr static const float defaultValue = 0;
};
} // namespace rive

Expand Down
1 change: 1 addition & 0 deletions include/rive/data_bind/data_values/data_value_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class DataValueString : public DataValue
bool isTypeOf(DataType typeKey) const override { return typeKey == DataType::string; };
std::string value() { return m_value; };
void value(std::string value) { m_value = value; };
constexpr static const char* defaultValue = "";
};
} // namespace rive
#endif
1 change: 1 addition & 0 deletions include/rive/data_bind/data_values/data_value_trigger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class DataValueTrigger : public DataValue
bool isTypeOf(DataType typeKey) const override { return typeKey == DataType::trigger; }
uint32_t value() { return m_value; };
void value(uint32_t value) { m_value = value; };
constexpr static const uint32_t defaultValue = 0;
};
} // namespace rive

Expand Down
3 changes: 1 addition & 2 deletions src/artboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ void Artboard::internalDataContext(DataContext* value, DataContext* parent, bool
if (dataBind->is<DataBindContext>())
{
dataBind->as<DataBindContext>()->bindFromContext(m_DataContext);
dataBind->addDirt(ComponentDirt::Bindings, true);
}
}
if (isRoot)
Expand All @@ -1207,8 +1208,6 @@ void Artboard::internalDataContext(DataContext* value, DataContext* parent, bool

void Artboard::sortDataBinds(std::vector<DataBind*> dataBinds)
{
// TODO: @hernan review this. Should not need to push to a component list to sort.

for (auto dataBind : dataBinds)
{
m_AllDataBinds.push_back(dataBind->as<DataBind>());
Expand Down
25 changes: 0 additions & 25 deletions src/data_bind/data_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ DataContext::DataContext(ViewModelInstance* viewModelInstance) :
m_ViewModelInstance(viewModelInstance)
{}

DataContext::DataContext() : m_ViewModelInstances({}) {}

DataContext::~DataContext() {}

void DataContext::addViewModelInstance(ViewModelInstance* value)
{
m_ViewModelInstances.push_back(value);
}

void DataContext::viewModelInstance(ViewModelInstance* value) { m_ViewModelInstance = value; }

ViewModelInstanceValue* DataContext::getViewModelProperty(const std::vector<uint32_t> path) const
Expand All @@ -25,22 +16,6 @@ ViewModelInstanceValue* DataContext::getViewModelProperty(const std::vector<uint
{
return nullptr;
}
// TODO: @hernan review. We should probably remove the std::vector and only keep the instance
for (auto viewModel : m_ViewModelInstances)
{
if (viewModel->viewModelId() == path[0])
{
ViewModelInstance* instance = viewModel;
for (it = path.begin() + 1; it != path.end() - 1; it++)
{
instance = instance->propertyValue(*it)
->as<ViewModelInstanceViewModel>()
->referenceViewModelInstance();
}
ViewModelInstanceValue* value = instance->propertyValue(*it++);
return value;
}
}
if (m_ViewModelInstance != nullptr && m_ViewModelInstance->viewModelId() == path[0])
{
ViewModelInstance* instance = m_ViewModelInstance;
Expand Down

0 comments on commit 5a2bb50

Please sign in to comment.