Struct Canvas

Source
pub struct Canvas<State, Handler = EventHandler<State>> { /* private fields */ }
Expand description

A Canvas manages a window and event loop, handing the current state to the renderer, and presenting its image on the screen.

Implementations§

Source§

impl Canvas<()>

Source

pub fn new(width: usize, height: usize) -> Canvas<()>

Create a new canvas with a given virtual window dimensions.

Source§

impl<State, Handler> Canvas<State, Handler>
where Handler: FnMut(&CanvasInfo, &mut State, &Event<'_, ()>) -> bool + 'static, State: 'static,

Source

pub fn state<NewState>( self, state: NewState, ) -> Canvas<NewState, EventHandler<NewState>>

Set the attached state.

Attaching a new state object will reset the input handler.

Source

pub fn title(self, text: impl Into<String>) -> Self

Set the title on the canvas window.

Source

pub fn hidpi(self, enabled: bool) -> Self

Toggle hidpi render.

Defaults to false. If you have a hidpi monitor, this will cause the image to be larger than the dimensions you specified when creating the canvas.

Source

pub fn show_ms(self, enabled: bool) -> Self

Whether to show a frame duration in the title bar.

Defaults to false.

Source

pub fn render_on_change(self, enabled: bool) -> Self

Whether to render a new frame only on state changes.

Defaults to false, which means it will render at a fixed framerate.

Source

pub fn input<NewHandler>( self, callback: NewHandler, ) -> Canvas<State, NewHandler>
where NewHandler: FnMut(&CanvasInfo, &mut State, &Event<'_, ()>) -> bool + 'static,

Attach an input handler.

Your input handler must be compatible with any state that you’ve set previously. Your event handler will be called for each event with the canvas information, the current state, and the inciting event.

Source

pub fn render(self, callback: impl FnMut(&mut State, &mut Image) + 'static)

Provide a rendering callback.

The canvas will call your rendering callback on demant, with the current state and a reference to the image. Depending on settings, this will either be called at 60fps, or only called when state changes. See render_on_change.

Auto Trait Implementations§

§

impl<State, Handler> Freeze for Canvas<State, Handler>
where State: Freeze, Handler: Freeze,

§

impl<State, Handler> RefUnwindSafe for Canvas<State, Handler>
where State: RefUnwindSafe, Handler: RefUnwindSafe,

§

impl<State, Handler> Send for Canvas<State, Handler>
where State: Send, Handler: Send,

§

impl<State, Handler> Sync for Canvas<State, Handler>
where State: Sync, Handler: Sync,

§

impl<State, Handler> Unpin for Canvas<State, Handler>
where State: Unpin, Handler: Unpin,

§

impl<State, Handler> UnwindSafe for Canvas<State, Handler>
where State: UnwindSafe, Handler: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.