Skip to main content

reflow_components/input/
mod.rs

1//! System/browser input event actors.
2//!
3//! Source actors triggered by the runtime when input events occur.
4//! The runtime sends event data as `Message::Object` via
5//! `network.send_to_actor(actor_id, "_event", event_data)`.
6//!
7//! Feature flags:
8//! - `window-events`: keyboard, mouse, touch, window actors (winit on native)
9//! - `browser-events`: all of the above + browser-specific APIs (web_sys on Wasm)
10
11mod gamepad;
12mod keyboard;
13mod mouse;
14mod touch;
15mod window;
16
17pub use gamepad::GamepadInputActor;
18pub use keyboard::KeyboardInputActor;
19pub use mouse::MouseInputActor;
20pub use touch::TouchInputActor;
21pub use window::WindowEventActor;
22
23use reflow_actor::ActorContext;
24
25/// Extract event data from the first Object message in the payload.
26/// Falls back to config hashmap for static/testing scenarios.
27pub(crate) fn extract_event_data(ctx: &ActorContext) -> serde_json::Value {
28    let payload = ctx.get_payload();
29    for (_port, msg) in payload.iter() {
30        if let crate::Message::Object(obj) = msg {
31            return obj.as_ref().clone().into();
32        }
33    }
34    let config = ctx.get_config_hashmap();
35    serde_json::to_value(config).unwrap_or_default()
36}