Skip to content

Commit 7a7a1d0

Browse files
committed
Add default impl for AppDelegate
Also box the AppDelegate inside the function to make it cleaner to call.
1 parent 3af64f9 commit 7a7a1d0

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

druid/examples/multiwin.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ struct State {
3434
fn main() {
3535
simple_logger::init().unwrap();
3636
let main_window = WindowDesc::new(ui_builder).menu(make_menu(&State::default()));
37-
let delegate = Box::new(MultiwinDelegate {});
3837
AppLauncher::with_window(main_window)
39-
.delegate(delegate)
38+
.delegate(Delegate)
4039
.launch(State::default())
4140
.expect("launch failed");
4241
}
@@ -82,9 +81,9 @@ fn ui_builder() -> impl Widget<State> {
8281
col
8382
}
8483

85-
struct MultiwinDelegate {}
84+
struct Delegate;
8685

87-
impl AppDelegate<State> for MultiwinDelegate {
86+
impl AppDelegate<State> for Delegate {
8887
fn event(
8988
&mut self,
9089
event: Event,

druid/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ impl<T: Data + 'static> AppLauncher<T> {
7070
/// Set the [`AppDelegate`].
7171
///
7272
/// [`AppDelegate`]: struct.AppDelegate.html
73-
pub fn delegate(mut self, delegate: Box<dyn AppDelegate<T>>) -> Self {
74-
self.delegate = Some(delegate);
73+
pub fn delegate(mut self, delegate: impl AppDelegate<T> + 'static) -> Self {
74+
self.delegate = Some(Box::new(delegate));
7575
self
7676
}
7777

druid/src/app_delegate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ pub trait AppDelegate<T: Data> {
6262
/// The return value of this function will be passed down the tree. This can
6363
/// be the even that was passed in, a different event, or no event. In all cases,
6464
/// the `update` method will be called as usual.
65+
#[allow(unused)]
6566
fn event(
6667
&mut self,
6768
event: Event,
6869
data: &mut T,
6970
env: &Env,
7071
ctx: &mut DelegateCtx,
71-
) -> Option<Event>;
72+
) -> Option<Event> {
73+
Some(event)
74+
}
7275
}

0 commit comments

Comments
 (0)