Skip to content

Commit 5fbbeb4

Browse files
authored
Merge pull request #1526 from Maan2003/delegatectx-get-external-handle
Provide get_external_handle on DelegateCtx
2 parents d8041c2 + 8b37b44 commit 5fbbeb4

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ You can find its changes [documented below](#070---2021-01-01).
1010
### Added
1111
- Sub windows: Allow opening windows that share state with arbitrary parts of the widget hierarchy ([#1254] by [@rjwittams])
1212
- WindowCloseRequested/WindowDisconnected event when a window is closing ([#1254] by [@rjwittams])
13+
- RichTextBuilder ([#1520] by [@Maan2003])
14+
- `get_external_handle` on `DelegateCtx` ([#1526] by [@Maan2003])
1315

1416
### Changed
1517

@@ -19,7 +21,7 @@ You can find its changes [documented below](#070---2021-01-01).
1921

2022
### Fixed
2123

22-
- Fixed docs of derived Lens ([(#1523)] by [@Maan2003])
24+
- Fixed docs of derived Lens ([#1523] by [@Maan2003])
2325

2426
### Visual
2527

@@ -592,7 +594,9 @@ Last release without a changelog :(
592594
[#1448]: https://github.com/linebender/druid/pull/1448
593595
[#1463]: https://github.com/linebender/druid/pull/1463
594596
[#1452]: https://github.com/linebender/druid/pull/1452
597+
[#1520]: https://github.com/linebender/druid/pull/1520
595598
[#1523]: https://github.com/linebender/druid/pull/1523
599+
[#1526]: https://github.com/linebender/druid/pull/1523
596600

597601
[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
598602
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0

druid/src/app_delegate.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
use std::any::{Any, TypeId};
1818

1919
use crate::{
20-
commands, core::CommandQueue, Command, Data, Env, Event, Handled, MenuDesc, SingleUse, Target,
21-
WindowDesc, WindowId,
20+
commands, core::CommandQueue, ext_event::ExtEventHost, Command, Data, Env, Event, ExtEventSink,
21+
Handled, MenuDesc, SingleUse, Target, WindowDesc, WindowId,
2222
};
2323

2424
/// A context passed in to [`AppDelegate`] functions.
2525
///
2626
/// [`AppDelegate`]: trait.AppDelegate.html
2727
pub struct DelegateCtx<'a> {
2828
pub(crate) command_queue: &'a mut CommandQueue,
29+
pub(crate) ext_event_host: &'a ExtEventHost,
2930
pub(crate) app_data_type: TypeId,
3031
}
3132

@@ -45,6 +46,14 @@ impl<'a> DelegateCtx<'a> {
4546
.push_back(command.into().default_to(Target::Global))
4647
}
4748

49+
/// Returns an [`ExtEventSink`] that can be moved between threads,
50+
/// and can be used to submit commands back to the application.
51+
///
52+
/// [`ExtEventSink`]: struct.ExtEventSink.html
53+
pub fn get_external_handle(&self) -> ExtEventSink {
54+
self.ext_event_host.make_sink()
55+
}
56+
4857
/// Create a new window.
4958
/// `T` must be the application's root `Data` type (the type provided to [`AppLauncher::launch`]).
5059
///

druid/src/win_handler.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,22 @@ impl<T: Data> Inner<T> {
193193
/// is configured.
194194
fn with_delegate<R, F>(&mut self, f: F) -> Option<R>
195195
where
196-
F: FnOnce(&mut Box<dyn AppDelegate<T>>, &mut T, &Env, &mut DelegateCtx) -> R,
196+
F: FnOnce(&mut dyn AppDelegate<T>, &mut T, &Env, &mut DelegateCtx) -> R,
197197
{
198198
let Inner {
199199
ref mut delegate,
200200
ref mut command_queue,
201201
ref mut data,
202+
ref ext_event_host,
202203
ref env,
203204
..
204205
} = self;
205206
let mut ctx = DelegateCtx {
206207
command_queue,
207208
app_data_type: TypeId::of::<T>(),
209+
ext_event_host,
208210
};
209-
if let Some(delegate) = delegate {
211+
if let Some(delegate) = delegate.as_deref_mut() {
210212
Some(f(delegate, data, env, &mut ctx))
211213
} else {
212214
None

0 commit comments

Comments
 (0)