Struct hookmap_core::common::handler::HandlerFunction [−][src]
pub struct HandlerFunction<E> { /* fields omitted */ }
Expand description
An optional input event handler.
Implementations
Creates a new HandlerFunction<E>
with None
.
Examples
use hookmap_core::{HandlerFunction, KeyboardEvent}; let handler = HandlerFunction::<KeyboardEvent>::new();
pub fn register_handler<F>(&mut self, handler: F) where
F: Fn(E) -> EventBlock + Send + Sync + 'static,
pub fn register_handler<F>(&mut self, handler: F) where
F: Fn(E) -> EventBlock + Send + Sync + 'static,
Registers a callback function.
Examples
use hookmap_core::{EventBlock, HandlerFunction, KeyboardEvent}; let mut handler = HandlerFunction::<KeyboardEvent>::new(); handler.register_handler(|e| { println!("Event target: {:?}", e.target); println!("Event action: {:?}", e.action); EventBlock::Unblock });
Returns true
if the HandlerFunction
registers a callback function.
Examples
use hookmap_core::{EventBlock, HandlerFunction, KeyboardEvent}; let mut handler = HandlerFunction::<KeyboardEvent>::new(); assert!(!handler.is_handler_registered()); handler.register_handler(|_| EventBlock::Unblock); assert!(handler.is_handler_registered());
Calls a registered handler and returns value returned by the handler.
Panics
Panics if the handler has not yet been registered.
Examples
use hookmap_core::{ButtonAction, ButtonEvent, EventBlock, HandlerFunction, Key, KeyboardEvent}; let mut handler = HandlerFunction::<KeyboardEvent>::new(); handler.register_handler(|_| EventBlock::Block); let event_block = handler.emit(ButtonEvent::new(Key::A, ButtonAction::Press)); assert_eq!(event_block, EventBlock::Block);