[][src]Trait pushrod::event::event::EventListener

pub trait EventListener {
    fn handle_event(&self, event: &PushrodEvent);

    fn event_mask(&self) -> EventMask { ... }
}

Implement this trait to register for system-wide events. Only implement this if you plan to implement event trackers on your own. Make sure to specify the type of event mask you wish to use, otherwise, you will receive all events as they occur.

Example:

impl EventListener for TestEventListener {
    fn event_mask(&self) -> EventMask {
        MASK_EVENT_MOUSE_MOVED
    }

    fn handle_event(&self, event: &PushrodEvent) {
        match event {
            PushrodEvent::MouseEvent { point: _point } => eprintln!("Mouse moved!"),
            _ => (),
        }
    }
}

Programmers who use this event system are encouraged to override event_mask so that they only receive the events that pertain to your application. If this is strictly set to MASK_EVENT_ALL, all wrapped events will be sent to handle_event.

Required methods

fn handle_event(&self, event: &PushrodEvent)

Called when an event matching a masked type (in event_mask) occurs.

Loading content...

Provided methods

fn event_mask(&self) -> EventMask

Identifies which events to receive in the handle_event function. Any events that do not match the masks (defined in constants) will not trigger a handle_event callback.

Loading content...

Implementors

Loading content...