Skip to main content

Input

Trait Input 

Source
pub trait Input {
    // Required method
    fn poll_event(&mut self, timeout: Duration) -> Option<Event>;

    // Provided method
    fn push_event(&mut self, _event: Event) { ... }
}
Expand description

Polls for and accepts input events.

Backends that never receive events from outside their own poll_event implementation (e.g. Crossterm, which reads its own event stream) can use the default no-op push_event via an empty impl Input for X {}.

§Examples

use core::time::Duration;
use retroglyph_core::backend::Input;
use retroglyph_core::event::Event;
use std::collections::VecDeque;

struct QueuedInput(VecDeque<Event>);

impl Input for QueuedInput {
    fn poll_event(&mut self, _timeout: Duration) -> Option<Event> {
        self.0.pop_front()
    }

    fn push_event(&mut self, event: Event) {
        self.0.push_back(event);
    }
}

Required Methods§

Source

fn poll_event(&mut self, timeout: Duration) -> Option<Event>

Poll for an input event, waiting up to timeout.

Provided Methods§

Source

fn push_event(&mut self, _event: Event)

Push an event into the backend’s event buffer.

Backends that receive events externally (e.g., from a window event loop or a test harness) override this to queue events for poll_event. The default is a no-op.

  • Windowed backends: called by ApplicationHandler on each event.
  • Headless: called by tests to inject synthetic events.
  • Crossterm: reads from its own event stream; no-op here.

Implementors§