Skip to main content

Backend

Trait Backend 

Source
pub trait Backend {
Show 16 methods // Required methods fn cache_policy(&self) -> CachePolicy; fn window_size(&self) -> Size; fn resize_window(&mut self, size: Size); fn set_event_mask(&mut self, mask: EventMask); fn set_text_input(&mut self, active: bool); fn poll_events(&mut self, wait: Option<Duration>) -> Vec<InputEvent>; fn waker(&self) -> Option<Waker>; fn paint_widget( &mut self, id: WidgetId, size: Size, paint: &mut dyn FnMut(&mut dyn Painter), ); fn begin_frame(&mut self, clear: Color); fn draw_widget(&mut self, id: WidgetId, bounds: Rect); fn present(&mut self); fn take_notices(&mut self) -> Vec<EngineEvent>; fn clipboard_text(&mut self) -> Option<String>; fn set_clipboard_text(&mut self, text: &str); fn open_url(&mut self, url: &str) -> Result<(), String>; // Provided method fn now(&self) -> Instant { ... }
}
Expand description

The services a windowing system provides to the engine.

A backend owns the window and one texture per Widget. The engine asks it to paint a Widget only when that Widget is invalidated, then composes each frame by drawing the cached textures. Window creation happens when the backend is built (each backend has its own settings); Backend::resize_window changes it afterward.

Required Methods§

Source

fn cache_policy(&self) -> CachePolicy

Returns how this backend caches painted Widgets.

§Returns

The backend’s CachePolicy.

Source

fn window_size(&self) -> Size

Returns the size of the window.

§Returns

The window’s size in pixels.

Source

fn resize_window(&mut self, size: Size)

Resizes the window.

§Arguments
  • size - The new size in pixels.
Source

fn set_event_mask(&mut self, mask: EventMask)

Tells the backend which input classes the application wants, so it can stop delivering the rest. A backend may ignore this; the engine filters as well.

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

fn set_text_input(&mut self, active: bool)

Starts or stops text input to match the focused Widget.

§Arguments
  • active - true while a text editor has focus.
Source

fn poll_events(&mut self, wait: Option<Duration>) -> Vec<InputEvent>

Collects waiting input.

§Arguments
  • wait - How long to block for the first event; None returns at once.
§Returns

The events that arrived, in order; empty if none did.

Source

fn waker(&self) -> Option<Waker>

Returns a function other threads call to end a Backend::poll_events wait early; the next poll then yields InputEvent::Wake.

§Returns

The waker, or None if the backend cannot be woken (the loop then notices posted events within a frame).

Source

fn paint_widget( &mut self, id: WidgetId, size: Size, paint: &mut dyn FnMut(&mut dyn Painter), )

Paints one Widget into its own texture, creating or resizing the texture as needed.

§Arguments
  • id - The Widget the texture belongs to.
  • size - The Widget’s size in pixels; never zero in either dimension.
  • paint - Draws the Widget, given the backend’s Painter.
Source

fn begin_frame(&mut self, clear: Color)

Starts a frame by clearing the window.

§Arguments
  • clear - The color to clear to.
Source

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

Copies a Widget’s cached texture into the frame; nothing happens if it has none.

§Arguments
  • id - The Widget to draw.
  • bounds - Where to draw it, in window coordinates.
Source

fn present(&mut self)

Finishes the frame and shows it.

Source

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

Returns the engine events the backend produced since the last call (fonts loaded, glyph atlas pages added).

§Returns

The events, in order.

Source

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

Reads the clipboard.

§Returns

The clipboard text, or None if it is empty or unavailable.

Source

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

Writes the clipboard.

§Arguments
  • text - The text to store.
Source

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

Opens a URL in the system’s default handler.

§Arguments
  • url - The URL to open.
§Returns

Ok if the request was made.

§Errors

Returns the reason the request failed, such as no handler for the URL.

Provided Methods§

Source

fn now(&self) -> Instant

Returns the current time.

§Returns

The backend’s clock reading.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§