Skip to content

Commit 30a36bd

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 30a36bd

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,10 @@ pub trait AppDelegate<T: Data> {
6868
data: &mut T,
6969
env: &Env,
7070
ctx: &mut DelegateCtx,
71-
) -> Option<Event>;
71+
) -> Option<Event> {
72+
let _ = data;
73+
let _ = env;
74+
let _ = ctx;
75+
Some(event)
76+
}
7277
}

0 commit comments

Comments
 (0)