Use map of windows internally
This commit is contained in:
parent
b896e41c6e
commit
12538d3c5b
1 changed files with 19 additions and 11 deletions
|
|
@ -21,6 +21,7 @@ use iced_native::user_interface::{self, UserInterface};
|
||||||
|
|
||||||
pub use iced_native::application::{Appearance, StyleSheet};
|
pub use iced_native::application::{Appearance, StyleSheet};
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
|
|
||||||
/// An interactive, native cross-platform application.
|
/// An interactive, native cross-platform application.
|
||||||
|
|
@ -169,6 +170,10 @@ where
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
.map_err(Error::WindowCreationFailed)?;
|
.map_err(Error::WindowCreationFailed)?;
|
||||||
|
|
||||||
|
let windows: HashMap<usize, winit::window::Window> =
|
||||||
|
HashMap::from([(0usize, window)]);
|
||||||
|
let window = windows.values().next().expect("No window found");
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
use winit::platform::web::WindowExtWebSys;
|
use winit::platform::web::WindowExtWebSys;
|
||||||
|
|
@ -197,7 +202,7 @@ where
|
||||||
debug,
|
debug,
|
||||||
receiver,
|
receiver,
|
||||||
init_command,
|
init_command,
|
||||||
window,
|
windows,
|
||||||
settings.exit_on_close_request,
|
settings.exit_on_close_request,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
@ -247,7 +252,7 @@ async fn run_instance<A, E, C>(
|
||||||
mut debug: Debug,
|
mut debug: Debug,
|
||||||
mut receiver: mpsc::UnboundedReceiver<winit::event::Event<'_, A::Message>>,
|
mut receiver: mpsc::UnboundedReceiver<winit::event::Event<'_, A::Message>>,
|
||||||
init_command: Command<A::Message>,
|
init_command: Command<A::Message>,
|
||||||
window: winit::window::Window,
|
windows: HashMap<usize, winit::window::Window>,
|
||||||
exit_on_close_request: bool,
|
exit_on_close_request: bool,
|
||||||
) where
|
) where
|
||||||
A: Application + 'static,
|
A: Application + 'static,
|
||||||
|
|
@ -258,11 +263,12 @@ async fn run_instance<A, E, C>(
|
||||||
use iced_futures::futures::stream::StreamExt;
|
use iced_futures::futures::stream::StreamExt;
|
||||||
use winit::event;
|
use winit::event;
|
||||||
|
|
||||||
let mut clipboard = Clipboard::connect(&window);
|
let window = windows.values().next().expect("No window found");
|
||||||
|
let mut clipboard = Clipboard::connect(window);
|
||||||
let mut cache = user_interface::Cache::default();
|
let mut cache = user_interface::Cache::default();
|
||||||
let mut surface = compositor.create_surface(&window);
|
let mut surface = compositor.create_surface(&window);
|
||||||
|
|
||||||
let mut state = State::new(&application, &window);
|
let mut state = State::new(&application, window);
|
||||||
let mut viewport_version = state.viewport_version();
|
let mut viewport_version = state.viewport_version();
|
||||||
|
|
||||||
let physical_size = state.physical_size();
|
let physical_size = state.physical_size();
|
||||||
|
|
@ -283,7 +289,7 @@ async fn run_instance<A, E, C>(
|
||||||
&mut clipboard,
|
&mut clipboard,
|
||||||
&mut proxy,
|
&mut proxy,
|
||||||
&mut debug,
|
&mut debug,
|
||||||
&window,
|
&windows,
|
||||||
|| compositor.fetch_information(),
|
|| compositor.fetch_information(),
|
||||||
);
|
);
|
||||||
runtime.track(application.subscription());
|
runtime.track(application.subscription());
|
||||||
|
|
@ -345,12 +351,12 @@ async fn run_instance<A, E, C>(
|
||||||
&mut proxy,
|
&mut proxy,
|
||||||
&mut debug,
|
&mut debug,
|
||||||
&mut messages,
|
&mut messages,
|
||||||
&window,
|
&windows,
|
||||||
|| compositor.fetch_information(),
|
|| compositor.fetch_information(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update window
|
// Update window
|
||||||
state.synchronize(&application, &window);
|
state.synchronize(&application, window);
|
||||||
|
|
||||||
let should_exit = application.should_exit();
|
let should_exit = application.should_exit();
|
||||||
|
|
||||||
|
|
@ -487,7 +493,7 @@ async fn run_instance<A, E, C>(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.update(&window, &window_event, &mut debug);
|
state.update(window, &window_event, &mut debug);
|
||||||
|
|
||||||
if let Some(event) = conversion::window_event(
|
if let Some(event) = conversion::window_event(
|
||||||
&window_event,
|
&window_event,
|
||||||
|
|
@ -564,7 +570,7 @@ pub fn update<A: Application, E: Executor>(
|
||||||
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
|
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
|
||||||
debug: &mut Debug,
|
debug: &mut Debug,
|
||||||
messages: &mut Vec<A::Message>,
|
messages: &mut Vec<A::Message>,
|
||||||
window: &winit::window::Window,
|
windows: &HashMap<usize, winit::window::Window>,
|
||||||
graphics_info: impl FnOnce() -> compositor::Information + Copy,
|
graphics_info: impl FnOnce() -> compositor::Information + Copy,
|
||||||
) where
|
) where
|
||||||
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
||||||
|
|
@ -586,7 +592,7 @@ pub fn update<A: Application, E: Executor>(
|
||||||
clipboard,
|
clipboard,
|
||||||
proxy,
|
proxy,
|
||||||
debug,
|
debug,
|
||||||
window,
|
windows,
|
||||||
graphics_info,
|
graphics_info,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -606,7 +612,7 @@ pub fn run_command<A, E>(
|
||||||
clipboard: &mut Clipboard,
|
clipboard: &mut Clipboard,
|
||||||
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
|
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
|
||||||
debug: &mut Debug,
|
debug: &mut Debug,
|
||||||
window: &winit::window::Window,
|
windows: &HashMap<usize, winit::window::Window>,
|
||||||
_graphics_info: impl FnOnce() -> compositor::Information + Copy,
|
_graphics_info: impl FnOnce() -> compositor::Information + Copy,
|
||||||
) where
|
) where
|
||||||
A: Application,
|
A: Application,
|
||||||
|
|
@ -617,6 +623,8 @@ pub fn run_command<A, E>(
|
||||||
use iced_native::system;
|
use iced_native::system;
|
||||||
use iced_native::window;
|
use iced_native::window;
|
||||||
|
|
||||||
|
let window = windows.values().next().expect("No window found");
|
||||||
|
|
||||||
for action in command.actions() {
|
for action in command.actions() {
|
||||||
match action {
|
match action {
|
||||||
command::Action::Future(future) => {
|
command::Action::Future(future) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue