mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 21:21:17 +01:00
Explores an API for triggering events and querying them at runtime.
For Flutter we expose an onEvent callback that you can add a callback to on the StateMachineController:
```dart
final controller = StateMachineController.fromArtboard(artboard, 'bumpy', onEvent: {);
controller.onEvent = (event) {
// Do something with event. Like:
if(event is OpenURLEvent) {
launchUrl(event.url);
}
};
artboard.addController(controller!);
```
Note that I haven't piped onEvent to the Flutter runtime yet but you'll see it in the StateMachineController in core.
In C++:
```c++
auto count = stateMachineInstance->firedEventCount();
for(auto i = 0; i < count; i++) {
auto event = stateMachineInstance->firedEventAt(i);
if(event->is<OpenURLEvent>()) {
// Do something with the url.
auto url = event->as<OpenURLEvent>()->url();
}
}
```
You can see some of this in action in the state_machine_event_test.cpp.
You can also see the events in the console in the editor:
<img width="717" alt="CleanShot 2023-08-10 at 18 03 22@2x" src="https://github.com/rive-app/rive/assets/454182/af21902a-424d-435b-b5b0-2a43701fe186">
In a follow up PR:
- Ability to trigger events from State (in/out) and Transition (start/end).
- Add custom properties to Events C++ API (currently they are loaded but not tracked against their respective events).
Diffs=
8caa7d377 Event triggering (#5793)
Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
13 lines
279 B
C++
13 lines
279 B
C++
#ifndef _RIVE_CUSTOM_PROPERTY_NUMBER_HPP_
|
|
#define _RIVE_CUSTOM_PROPERTY_NUMBER_HPP_
|
|
#include "rive/generated/custom_property_number_base.hpp"
|
|
#include <stdio.h>
|
|
namespace rive
|
|
{
|
|
class CustomPropertyNumber : public CustomPropertyNumberBase
|
|
{
|
|
public:
|
|
};
|
|
} // namespace rive
|
|
|
|
#endif |