Return window::Id in window::open
This commit is contained in:
parent
8f33575719
commit
fd593f8fb0
3 changed files with 17 additions and 10 deletions
|
|
@ -40,12 +40,13 @@ enum Message {
|
||||||
|
|
||||||
impl Example {
|
impl Example {
|
||||||
fn new() -> (Self, Task<Message>) {
|
fn new() -> (Self, Task<Message>) {
|
||||||
|
let (_id, open) = window::open(window::Settings::default());
|
||||||
|
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
windows: BTreeMap::new(),
|
windows: BTreeMap::new(),
|
||||||
},
|
},
|
||||||
window::open(window::Settings::default())
|
open.map(Message::WindowOpened),
|
||||||
.map(Message::WindowOpened),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,10 +75,12 @@ impl Example {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
window::open(window::Settings {
|
let (_id, open) = window::open(window::Settings {
|
||||||
position,
|
position,
|
||||||
..window::Settings::default()
|
..window::Settings::default()
|
||||||
})
|
});
|
||||||
|
|
||||||
|
open
|
||||||
})
|
})
|
||||||
.map(Message::WindowOpened)
|
.map(Message::WindowOpened)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -218,12 +218,15 @@ pub fn close_requests() -> Subscription<Id> {
|
||||||
|
|
||||||
/// Opens a new window with the given [`Settings`]; producing the [`Id`]
|
/// Opens a new window with the given [`Settings`]; producing the [`Id`]
|
||||||
/// of the new window on completion.
|
/// of the new window on completion.
|
||||||
pub fn open(settings: Settings) -> Task<Id> {
|
pub fn open(settings: Settings) -> (Id, Task<Id>) {
|
||||||
let id = Id::unique();
|
let id = Id::unique();
|
||||||
|
|
||||||
|
(
|
||||||
|
id,
|
||||||
task::oneshot(|channel| {
|
task::oneshot(|channel| {
|
||||||
crate::Action::Window(Action::Open(id, settings, channel))
|
crate::Action::Window(Action::Open(id, settings, channel))
|
||||||
})
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Closes the window with `id`.
|
/// Closes the window with `id`.
|
||||||
|
|
|
||||||
|
|
@ -207,8 +207,9 @@ where
|
||||||
let task = if let Some(window_settings) = window_settings {
|
let task = if let Some(window_settings) = window_settings {
|
||||||
let mut task = Some(task);
|
let mut task = Some(task);
|
||||||
|
|
||||||
runtime::window::open(window_settings)
|
let (_id, open) = runtime::window::open(window_settings);
|
||||||
.then(move |_| task.take().unwrap_or(Task::none()))
|
|
||||||
|
open.then(move |_| task.take().unwrap_or(Task::none()))
|
||||||
} else {
|
} else {
|
||||||
task
|
task
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue