Trait druid::AppDelegate
source · pub trait AppDelegate<T: Data> {
// Provided methods
fn event(
&mut self,
ctx: &mut DelegateCtx<'_>,
window_id: WindowId,
event: Event,
data: &mut T,
env: &Env
) -> Option<Event> { ... }
fn command(
&mut self,
ctx: &mut DelegateCtx<'_>,
target: Target,
cmd: &Command,
data: &mut T,
env: &Env
) -> Handled { ... }
fn window_added(
&mut self,
id: WindowId,
handle: WindowHandle,
data: &mut T,
env: &Env,
ctx: &mut DelegateCtx<'_>
) { ... }
fn window_removed(
&mut self,
id: WindowId,
data: &mut T,
env: &Env,
ctx: &mut DelegateCtx<'_>
) { ... }
}
Expand description
A type that provides hooks for handling and modifying top-level events.
The AppDelegate
is a trait that is allowed to handle and modify
events before they are passed down the widget tree.
It is a natural place for things like window and menu management.
You customize the AppDelegate
by implementing its methods on your own type.
Provided Methods§
sourcefn event(
&mut self,
ctx: &mut DelegateCtx<'_>,
window_id: WindowId,
event: Event,
data: &mut T,
env: &Env
) -> Option<Event>
fn event( &mut self, ctx: &mut DelegateCtx<'_>, window_id: WindowId, event: Event, data: &mut T, env: &Env ) -> Option<Event>
The AppDelegate
’s event handler. This function receives all
non-command events, before they are passed down the tree.
The return value of this function will be passed down the tree. This can
be the event that was passed in, a different event, or no event. In all cases,
the update
method will be called as usual.
sourcefn command(
&mut self,
ctx: &mut DelegateCtx<'_>,
target: Target,
cmd: &Command,
data: &mut T,
env: &Env
) -> Handled
fn command( &mut self, ctx: &mut DelegateCtx<'_>, target: Target, cmd: &Command, data: &mut T, env: &Env ) -> Handled
The AppDelegate
s Command
handler.
This function is called with each (Target
, Command
) pair before
they are sent down the tree.
If your implementation returns Handled::No
, the command will be sent down
the widget tree. Otherwise it will not.
To do anything fancier than this, you can submit arbitrary commands
via DelegateCtx::submit_command
.
sourcefn window_added(
&mut self,
id: WindowId,
handle: WindowHandle,
data: &mut T,
env: &Env,
ctx: &mut DelegateCtx<'_>
)
fn window_added( &mut self, id: WindowId, handle: WindowHandle, data: &mut T, env: &Env, ctx: &mut DelegateCtx<'_> )
The handler for window creation events. This function is called after a window has been added, allowing you to customize the window creation behavior of your app.
sourcefn window_removed(
&mut self,
id: WindowId,
data: &mut T,
env: &Env,
ctx: &mut DelegateCtx<'_>
)
fn window_removed( &mut self, id: WindowId, data: &mut T, env: &Env, ctx: &mut DelegateCtx<'_> )
The handler for window deletion events. This function is called after a window has been removed.