[−][src]Trait druid_shell::WinHandler
App behavior, supplied by the app.
Many of the "window procedure" messages map to calls to this trait.
The methods are non-mut because the window procedure can be called
recursively; implementers are expected to use RefCell
or the like,
but should be careful to keep the lifetime of the borrow short.
Required methods
fn connect(&mut self, handle: &WindowHandle)
Provide the handler with a handle to the window so that it can invalidate or make other requests.
This method passes the WindowHandle
directly, because the handler may
wish to stash it.
fn paint(&mut self, piet: &mut Piet) -> bool
Request the handler to paint the window contents. Return value indicates whether window is animating, i.e. whether another paint should be scheduled for the next animation frame.
fn as_any(&mut self) -> &mut dyn Any
Get a reference to the handler state. Used mostly by idle handlers.
Provided methods
fn size(&mut self, width: u32, height: u32)
Called when the size of the window is changed. Note that size is in physical pixels.
fn rebuild_resources(&mut self)
Called when the resources need to be rebuilt.
Discussion: this function is mostly motivated by using
GenericRenderTarget
on Direct2D. If we move to DeviceContext
instead, then it's possible we don't need this.
fn command(&mut self, id: u32)
Called when a menu item is selected.
fn key_down(&mut self, event: KeyEvent) -> bool
Called on a key down event.
Return true
if the event is handled.
fn key_up(&mut self, event: KeyEvent)
Called when a key is released. This corresponds to the WM_KEYUP message on Windows, or keyUp(withEvent:) on macOS.
fn wheel(&mut self, delta: Vec2, mods: KeyModifiers)
Called on a mouse wheel event.
The polarity is the amount to be added to the scroll position, in other words the opposite of the direction the content should move on scrolling. This polarity is consistent with the deltaX and deltaY values in a web WheelEvent.
fn zoom(&mut self, delta: f64)
Called when a platform-defined zoom gesture occurs (such as pinching on the trackpad).
fn mouse_move(&mut self, event: &MouseEvent)
Called when the mouse moves.
fn mouse_down(&mut self, event: &MouseEvent)
Called on mouse button down.
fn mouse_up(&mut self, event: &MouseEvent)
Called on mouse button up.
fn timer(&mut self, token: TimerToken)
Called on timer event.
This is called at (approximately) the requested deadline by a
WindowHandle::request_timer()
call. The token argument here is the same
as the return value of that call.
fn got_focus(&mut self)
Called when this window becomes the focused window.
fn destroy(&mut self)
Called when the window is being destroyed. Note that this happens earlier in the sequence than drop (at WM_DESTROY, while the latter is WM_NCDESTROY).
fn idle(&mut self, token: IdleToken)
Called when a idle token is requested by IdleHandle::schedule_idle()
call.