[][src]Struct pixel_canvas::canvas::Canvas

pub struct Canvas<State, Handler = EventHandler<State>> { /* fields omitted */ }

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

Implementations

impl Canvas<()>[src]

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

Create a new canvas with a given virtual window dimensions.

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

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

Set the attached state.

Attaching a new state object will reset the input handler.

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

Set the title on the canvas window.

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

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.

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

Whether to show a frame duration in the title bar.

Defaults to false.

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

Whether to render a new frame only on state changes.

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

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

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.

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

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> RefUnwindSafe for Canvas<State, Handler> where
    Handler: RefUnwindSafe,
    State: RefUnwindSafe

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.