pub struct HeadlessBackend {
pub painted: Vec<(WidgetId, Vec<PaintCall>)>,
pub draws: Vec<(WidgetId, Rect)>,
pub frames: usize,
pub mask: Option<EventMask>,
pub text_input: bool,
pub clipboard: Option<String>,
pub opened_urls: Vec<String>,
/* private fields */
}Expand description
A Backend with no window: input is scripted, drawing is recorded, and nothing needs a
display.
Queue input with HeadlessBackend::push_event; after the engine runs, read
painted, draws and
frames. Each Widget is painted with a RecordingPainter.
§Examples
use pushrod::backend::Backend;
use pushrod::backend::headless::HeadlessBackend;
use pushrod::geometry::size;
use pushrod::input::InputEvent;
let mut backend = HeadlessBackend::new(size(320, 200));
backend.push_event(InputEvent::Quit);
assert_eq!(backend.poll_events(None), vec![InputEvent::Quit]);Fields§
§painted: Vec<(WidgetId, Vec<PaintCall>)>Every Widget paint, in order: the widget, and the calls it made.
draws: Vec<(WidgetId, Rect)>Every Widget texture drawn into a frame, in order, with its bounds.
frames: usizeThe number of frames presented.
mask: Option<EventMask>The last mask the engine set.
text_input: boolWhether text input is currently on.
clipboard: Option<String>The clipboard contents.
opened_urls: Vec<String>The URLs the engine asked to open.
Implementations§
Source§impl HeadlessBackend
impl HeadlessBackend
Sourcepub fn push_event(&mut self, event: InputEvent)
pub fn push_event(&mut self, event: InputEvent)
Trait Implementations§
Source§impl Backend for HeadlessBackend
impl Backend for HeadlessBackend
Source§fn cache_policy(&self) -> CachePolicy
fn cache_policy(&self) -> CachePolicy
Source§fn window_size(&self) -> Size
fn window_size(&self) -> Size
Source§fn resize_window(&mut self, size: Size)
fn resize_window(&mut self, size: Size)
Source§fn set_event_mask(&mut self, mask: EventMask)
fn set_event_mask(&mut self, mask: EventMask)
Source§fn set_text_input(&mut self, active: bool)
fn set_text_input(&mut self, active: bool)
Records the text input state in HeadlessBackend::text_input.
§Arguments
active- Whether text input is on.
Source§fn poll_events(&mut self, _wait: Option<Duration>) -> Vec<InputEvent>
fn poll_events(&mut self, _wait: Option<Duration>) -> Vec<InputEvent>
Returns the scripted events, all at once; it never waits. With an empty script the window is treated as closed, so a loop run against this backend always ends.
§Arguments
_wait- Ignored.
§Returns
The scripted events, or InputEvent::Quit if there are none.
Source§fn paint_widget(
&mut self,
id: WidgetId,
_size: Size,
paint: &mut dyn FnMut(&mut dyn Painter),
)
fn paint_widget( &mut self, id: WidgetId, _size: Size, paint: &mut dyn FnMut(&mut dyn Painter), )
Paints the Widget with a RecordingPainter and stores the calls in
HeadlessBackend::painted.
§Arguments
id- TheWidget._size- TheWidget’s size; not needed to record.paint- Draws theWidget.
Source§fn begin_frame(&mut self, _clear: Color)
fn begin_frame(&mut self, _clear: Color)
Source§fn draw_widget(&mut self, id: WidgetId, bounds: Rect)
fn draw_widget(&mut self, id: WidgetId, bounds: Rect)
Records the draw in HeadlessBackend::draws.
§Arguments
id- TheWidgetdrawn.bounds- Where it was drawn.
Source§fn present(&mut self)
fn present(&mut self)
Counts a presented frame in HeadlessBackend::frames.