Skip to content

Commit

Permalink
Event triggering
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
luigi-rosso committed Aug 14, 2023
1 parent 71a0361 commit 2d34998
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e71ae68ba09767f246bf3d779f38bb731cf7da9a
8caa7d377f368af8c667ca209a2ce7aef8679be2
2 changes: 1 addition & 1 deletion wasm/submodules/rive-cpp

0 comments on commit 2d34998

Please sign in to comment.