Apply NestedInput initial values This update applies the initial values for nested inputs (as set in the Inputs panel of the Editor), so that NestedInputs behave in the same way as regular StateMachineInputs. There are a couple of reasons to do this: 1. Currently if you have a nested artboard and set the initial nested input value, it will only apply in the editor when viewing that artboard. If you nest that artboard in another artboard, the initial values do not apply. Similarly, initial nested values do not apply in the runtimes. Currently StateMachineInputs do apply initial values, so this brings NestedInputs in line with that. 2. There was a bug Hernan noticed where there in certain cases, NestedInput values that were keyed on a timeline did not apply properly in cases where the keyed value was the same as the default value. In these cases, the keyed value is ignored because it and the default values were the same. In addition, since the initial value wasn't being applied, the state wasn't being update properly based on the nested input's value. Diffs= 6d9aa0179 Apply NestedInput initial values (#6140) Co-authored-by: Philip Chung <philterdesign@gmail.com>
diff --git a/.rive_head b/.rive_head index 2e9e535..90492b7 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -92c8f1164db98bb5462f26dd73c89da4fa2c8b76 +6d9aa017961638f7576a2ea52a8928c813e28dbb
diff --git a/include/rive/animation/nested_bool.hpp b/include/rive/animation/nested_bool.hpp index 2900390..813ece2 100644 --- a/include/rive/animation/nested_bool.hpp +++ b/include/rive/animation/nested_bool.hpp
@@ -7,6 +7,8 @@ class NestedBool : public NestedBoolBase { public: + void applyValue() override; + protected: void nestedValueChanged() override; };
diff --git a/include/rive/animation/nested_input.hpp b/include/rive/animation/nested_input.hpp index 495bafb..16d5bf9 100644 --- a/include/rive/animation/nested_input.hpp +++ b/include/rive/animation/nested_input.hpp
@@ -8,6 +8,19 @@ class NestedInput : public NestedInputBase { public: + StatusCode onAddedDirty(CoreContext* context) override + { + StatusCode result = Super::onAddedDirty(context); + auto parent = this->parent(); + if (parent != nullptr && parent->is<NestedStateMachine>()) + { + parent->as<NestedStateMachine>()->addNestedInput(this); + } + return result; + } + + virtual void applyValue() {} + protected: SMIInput* input() {
diff --git a/include/rive/animation/nested_number.hpp b/include/rive/animation/nested_number.hpp index 6b51594..b21dfc3 100644 --- a/include/rive/animation/nested_number.hpp +++ b/include/rive/animation/nested_number.hpp
@@ -7,6 +7,8 @@ class NestedNumber : public NestedNumberBase { public: + void applyValue() override; + protected: void nestedValueChanged() override; };
diff --git a/include/rive/animation/nested_state_machine.hpp b/include/rive/animation/nested_state_machine.hpp index da13c5a..a320c85 100644 --- a/include/rive/animation/nested_state_machine.hpp +++ b/include/rive/animation/nested_state_machine.hpp
@@ -8,11 +8,13 @@ namespace rive { class ArtboardInstance; +class NestedInput; class StateMachineInstance; class NestedStateMachine : public NestedStateMachineBase { private: std::unique_ptr<StateMachineInstance> m_StateMachineInstance; + std::vector<NestedInput*> m_nestedInputs; public: NestedStateMachine(); @@ -24,6 +26,8 @@ void pointerMove(Vec2D position); void pointerDown(Vec2D position); void pointerUp(Vec2D position); + + void addNestedInput(NestedInput* input); }; } // namespace rive
diff --git a/include/rive/animation/nested_trigger.hpp b/include/rive/animation/nested_trigger.hpp index 5f1d67c..989eac8 100644 --- a/include/rive/animation/nested_trigger.hpp +++ b/include/rive/animation/nested_trigger.hpp
@@ -7,6 +7,7 @@ class NestedTrigger : public NestedTriggerBase { public: + void applyValue() override; void fire(const CallbackData& value) override; }; } // namespace rive
diff --git a/src/animation/nested_bool.cpp b/src/animation/nested_bool.cpp index 6fda258..29cd646 100644 --- a/src/animation/nested_bool.cpp +++ b/src/animation/nested_bool.cpp
@@ -6,7 +6,9 @@ using namespace rive; class StateMachineInstance; -void NestedBool::nestedValueChanged() +void NestedBool::nestedValueChanged() { this->applyValue(); } + +void NestedBool::applyValue() { auto inputInstance = input(); if (inputInstance != nullptr)
diff --git a/src/animation/nested_number.cpp b/src/animation/nested_number.cpp index e5256bc..a81236f 100644 --- a/src/animation/nested_number.cpp +++ b/src/animation/nested_number.cpp
@@ -6,7 +6,9 @@ using namespace rive; class StateMachineInstance; -void NestedNumber::nestedValueChanged() +void NestedNumber::nestedValueChanged() { this->applyValue(); } + +void NestedNumber::applyValue() { auto inputInstance = input(); if (inputInstance != nullptr)
diff --git a/src/animation/nested_state_machine.cpp b/src/animation/nested_state_machine.cpp index 8a2d1ca..a686f14 100644 --- a/src/animation/nested_state_machine.cpp +++ b/src/animation/nested_state_machine.cpp
@@ -1,3 +1,6 @@ +#include "rive/animation/nested_bool.hpp" +#include "rive/animation/nested_input.hpp" +#include "rive/animation/nested_number.hpp" #include "rive/animation/nested_state_machine.hpp" #include "rive/animation/state_machine_instance.hpp" @@ -17,6 +20,16 @@ void NestedStateMachine::initializeAnimation(ArtboardInstance* artboard) { m_StateMachineInstance = artboard->stateMachineAt(animationId()); + auto count = m_nestedInputs.size(); + for (size_t i = 0; i < count; i++) + { + auto nestedInput = m_nestedInputs[i]; + if (nestedInput->is<NestedBool>() || nestedInput->is<NestedNumber>()) + { + nestedInput->applyValue(); + } + } + m_nestedInputs.clear(); } StateMachineInstance* NestedStateMachine::stateMachineInstance() @@ -46,4 +59,6 @@ { m_StateMachineInstance->pointerUp(position); } -} \ No newline at end of file +} + +void NestedStateMachine::addNestedInput(NestedInput* input) { m_nestedInputs.push_back(input); } \ No newline at end of file
diff --git a/src/animation/nested_trigger.cpp b/src/animation/nested_trigger.cpp index 26b7990..89fb586 100644 --- a/src/animation/nested_trigger.cpp +++ b/src/animation/nested_trigger.cpp
@@ -6,7 +6,9 @@ using namespace rive; class StateMachineInstance; -void NestedTrigger::fire(const CallbackData& value) +void NestedTrigger::fire(const CallbackData& value) { this->applyValue(); } + +void NestedTrigger::applyValue() { auto inputInstance = input(); if (inputInstance != nullptr)