Skip to main content

HeadlessBackend

Struct HeadlessBackend 

Source
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: usize

The number of frames presented.

§mask: Option<EventMask>

The last mask the engine set.

§text_input: bool

Whether 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

Source

pub fn new(size: Size) -> Self

Creates a headless backend.

§Arguments
  • size - The size of the pretend window.
§Returns

A new HeadlessBackend with no scripted input.

Source

pub fn push_event(&mut self, event: InputEvent)

Queues an input event for the next Backend::poll_events.

§Arguments
  • event - The event to deliver.

Trait Implementations§

Source§

impl Backend for HeadlessBackend

Source§

fn cache_policy(&self) -> CachePolicy

Returns the cache policy.

§Returns

CachePolicy::TextureCache.

Source§

fn window_size(&self) -> Size

Returns the size of the pretend window.

§Returns

The size.

Source§

fn resize_window(&mut self, size: Size)

Records a new window size.

§Arguments
  • size - The new size.
Source§

fn set_event_mask(&mut self, mask: EventMask)

Records the event mask in HeadlessBackend::mask.

§Arguments
  • mask - The run loop’s event mask.
Source§

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>

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 waker(&self) -> Option<Waker>

A headless backend cannot be woken.

§Returns

None.

Source§

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 - The Widget.
  • _size - The Widget’s size; not needed to record.
  • paint - Draws the Widget.
Source§

fn begin_frame(&mut self, _clear: Color)

Starts a frame; nothing to clear.

§Arguments
  • _clear - The clear color; ignored.
Source§

fn draw_widget(&mut self, id: WidgetId, bounds: Rect)

Records the draw in HeadlessBackend::draws.

§Arguments
  • id - The Widget drawn.
  • bounds - Where it was drawn.
Source§

fn present(&mut self)

Counts a presented frame in HeadlessBackend::frames.

Source§

fn take_notices(&mut self) -> Vec<EngineEvent>

A headless backend loads no fonts, so it has no notices.

§Returns

An empty list.

Source§

fn clipboard_text(&mut self) -> Option<String>

Reads the stored clipboard text.

§Returns

The text, or None if nothing was stored.

Source§

fn set_clipboard_text(&mut self, text: &str)

Stores clipboard text.

§Arguments
  • text - The text to store.
Source§

fn open_url(&mut self, url: &str) -> Result<(), String>

Records the URL in HeadlessBackend::opened_urls without opening anything.

§Arguments
  • url - The URL.
§Returns

Always Ok.

§Errors

Never fails.

Source§

fn now(&self) -> Instant

Returns the current time. Read more
Source§

impl Debug for HeadlessBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HeadlessBackend

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.