Struct pixel_canvas::canvas::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
sourceimpl<State, Handler> Canvas<State, Handler> where
Handler: FnMut(&CanvasInfo, &mut State, &Event<'_, ()>) -> bool + 'static,
State: 'static,
impl<State, Handler> Canvas<State, Handler> where
Handler: FnMut(&CanvasInfo, &mut State, &Event<'_, ()>) -> bool + 'static,
State: 'static,
sourcepub fn state<NewState>(
self,
state: NewState
) -> Canvas<NewState, EventHandler<NewState>>
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.
sourcepub fn hidpi(self, enabled: bool) -> Self
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.
sourcepub fn show_ms(self, enabled: bool) -> Self
pub fn show_ms(self, enabled: bool) -> Self
Whether to show a frame duration in the title bar.
Defaults to false
.
sourcepub fn render_on_change(self, enabled: bool) -> Self
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.
sourcepub fn input<NewHandler>(
self,
callback: NewHandler
) -> Canvas<State, NewHandler> where
NewHandler: FnMut(&CanvasInfo, &mut State, &Event<'_, ()>) -> bool + 'static,
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.
sourcepub fn render(self, callback: impl FnMut(&mut State, &mut Image) + 'static)
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> 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more