chore: fix broken docs link Need a small change to go through to get the latest cpp commit that didn't make it downstream, downstream. Diffs= bd71143bc chore: fix broken docs link (#6360) 0f08dd379 prevent pointer event propagation to collapsed nested artboards (#6322) Co-authored-by: Zachary Plata <plata.zach@gmail.com> Co-authored-by: hernan <hernan@rive.app>
diff --git a/.rive_head b/.rive_head index a54f657..8b6016b 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -c357e7aa757f23486271df284a5c3aa5643f2ff5 +bd71143bc0964a789174f30f01d14fa551e33bb9
diff --git a/README.md b/README.md index 09a5e10..6c99f30 100644 --- a/README.md +++ b/README.md
@@ -14,7 +14,7 @@ - Querying LinearAnimations and StateMachines from Artboards. - Making changes to Artboard hierarchy (fundamentally same guts used by LinearAnimations and StateMachines) and effienclty solving those changes via Artboard::advance. - Abstract Renderer for submitting high level vector path commands with retained path objects to optimize and minimize path re-computation (ultimately up to the concrete rendering implementation). -- Example concrete renderer written in C++ with [Skia](https://skia.org/). Skia renderer code is in [skia/renderer/src/skia_renderer.cpp](skia/renderer/src/skia_renderer.cpp). +- Example concrete renderer written in C++ with [Skia](https://skia.org/). Skia renderer code is in [skia/renderer/src/skia_factory.cpp](skia/renderer/src/skia_factory.cpp). ## Build System We use [premake5](https://premake.github.io/). The Rive dev team primarily works on MacOS. There is some work done by the community to also support Windows and Linux. PRs welcomed for specific platforms you wish to support! We encourage you to use premake as it's highly extensible and configurable for a variety of platforms.
diff --git a/src/animation/state_machine_instance.cpp b/src/animation/state_machine_instance.cpp index 55dee4d..05fa3cb 100644 --- a/src/animation/state_machine_instance.cpp +++ b/src/animation/state_machine_instance.cpp
@@ -382,6 +382,10 @@ // as able to stop propagation) for (auto nestedArtboard : m_hitNestedArtboards) { + if (nestedArtboard->isCollapsed()) + { + continue; + } Vec2D nestedPosition; if (!nestedArtboard->worldToLocal(position, &nestedPosition)) {
diff --git a/test/assets/pointer_events_nested_artboards_in_solos.riv b/test/assets/pointer_events_nested_artboards_in_solos.riv new file mode 100644 index 0000000..ec39738 --- /dev/null +++ b/test/assets/pointer_events_nested_artboards_in_solos.riv Binary files differ
diff --git a/test/solo_test.cpp b/test/solo_test.cpp index 4584e41..e53b250 100644 --- a/test/solo_test.cpp +++ b/test/solo_test.cpp
@@ -1,7 +1,11 @@ #include <rive/solo.hpp> #include <rive/shapes/shape.hpp> +#include <rive/shapes/path.hpp> #include <rive/animation/state_machine_instance.hpp> #include <rive/animation/state_machine_input_instance.hpp> +#include <rive/nested_artboard.hpp> +#include <rive/shapes/paint/fill.hpp> +#include <rive/shapes/paint/solid_color.hpp> #include "rive_file_reader.hpp" #include <catch.hpp> #include <cstdio> @@ -214,3 +218,91 @@ stateMachine->pointerMove(rive::Vec2D(200.0f, 400.0f)); REQUIRE(toggle->value() == true); } + +TEST_CASE("hit test on nested artboards in solos", "[solo]") +{ + auto file = ReadRiveFile("../../test/assets/pointer_events_nested_artboards_in_solos.riv"); + + auto mainArtboard = file->artboard()->instance(); + + auto green_color = 0xFF00B511; + auto red_color = 0xFFC80000; + auto gray_color = 0xFF747474; + + REQUIRE(mainArtboard->find("Parent-Artboard") != nullptr); + auto artboard = mainArtboard->find<rive::Artboard>("Parent-Artboard"); + + REQUIRE(artboard != nullptr); + artboard->updateComponents(); + REQUIRE(artboard->is<rive::Artboard>()); + REQUIRE(artboard->find("Nested-Artboard-Active") != nullptr); + auto nestedArtboardActive = artboard->find<rive::NestedArtboard>("Nested-Artboard-Active"); + REQUIRE(nestedArtboardActive->artboard() != nullptr); + + auto nestedArtboardActiveArtboardInstance = nestedArtboardActive->artboard(); + auto activeRect = + nestedArtboardActiveArtboardInstance->find<rive::Shape>("Clickable-Rectangle"); + REQUIRE(activeRect != nullptr); + auto activeRectFill = activeRect->children()[1]->as<rive::Fill>(); + REQUIRE(activeRectFill != nullptr); + auto activeRectFillSolidColor = activeRectFill->paint()->as<rive::SolidColor>(); + REQUIRE(activeRectFillSolidColor != nullptr); + + REQUIRE(artboard->find("Nested-Artboard-Inactive") != nullptr); + auto nestedArtboardInactive = artboard->find<rive::NestedArtboard>("Nested-Artboard-Inactive"); + REQUIRE(nestedArtboardInactive->artboard() != nullptr); + auto nestedArtboardInactiveArtboardInstance = nestedArtboardInactive->artboard(); + auto inactiveRect = + nestedArtboardInactiveArtboardInstance->find<rive::Shape>("Clickable-Rectangle"); + REQUIRE(inactiveRect != nullptr); + auto inactiveRectFill = inactiveRect->children()[1]->as<rive::Fill>(); + REQUIRE(inactiveRectFill != nullptr); + auto inactiveRectFillSolidColor = inactiveRectFill->paint()->as<rive::SolidColor>(); + REQUIRE(inactiveRectFillSolidColor != nullptr); + + REQUIRE(artboard->stateMachineCount() == 1); + + auto stateMachine = mainArtboard->stateMachineAt(0); + REQUIRE(stateMachine != nullptr); + + // Initialize state machine + stateMachine->advance(0.0f); + mainArtboard->advance(0.0f); + + REQUIRE(nestedArtboardActive->isCollapsed() == false); + REQUIRE(nestedArtboardInactive->isCollapsed() == true); + REQUIRE(activeRectFillSolidColor->colorValue() == green_color); + REQUIRE(inactiveRectFillSolidColor->colorValue() == gray_color); + + // Advance to a position in the timeline where the inactive artboard + // is active so it is rendered once + stateMachine->advance(0.1f); + mainArtboard->advance(0.1f); + + REQUIRE(nestedArtboardActive->isCollapsed() == true); + REQUIRE(nestedArtboardInactive->isCollapsed() == false); + REQUIRE(inactiveRectFillSolidColor->colorValue() == green_color); + + // Advance to a position in the timeline where the active artboard is active + stateMachine->advance(0.1f); + mainArtboard->advance(0.1f); + + REQUIRE(nestedArtboardActive->isCollapsed() == false); + REQUIRE(nestedArtboardInactive->isCollapsed() == true); + + // Apply pointer up + stateMachine->pointerUp(rive::Vec2D(200.0f, 200.0f)); + stateMachine->advance(0.0f); + artboard->advance(0.0f); + + // Advance to activate the inactive artboard again so it redraws + stateMachine->advance(0.1f); + artboard->advance(0.1f); + REQUIRE(nestedArtboardActive->isCollapsed() == true); + REQUIRE(nestedArtboardInactive->isCollapsed() == false); + + // If the test succeeds the active nested artboard should have changed to red + REQUIRE(activeRectFillSolidColor->colorValue() == red_color); + // And the inactive artboard should have stayed green + REQUIRE(inactiveRectFillSolidColor->colorValue() == green_color); +}