Update winit to 0.30
This commit is contained in:
parent
db07b9ba9e
commit
2645524f88
12 changed files with 901 additions and 643 deletions
2
.github/workflows/check.yml
vendored
2
.github/workflows/check.yml
vendored
|
|
@ -17,8 +17,6 @@ jobs:
|
||||||
run: cargo build --package tour --target wasm32-unknown-unknown
|
run: cargo build --package tour --target wasm32-unknown-unknown
|
||||||
- name: Check compilation of `todos` example
|
- name: Check compilation of `todos` example
|
||||||
run: cargo build --package todos --target wasm32-unknown-unknown
|
run: cargo build --package todos --target wasm32-unknown-unknown
|
||||||
- name: Check compilation of `integration` example
|
|
||||||
run: cargo build --package integration --target wasm32-unknown-unknown
|
|
||||||
|
|
||||||
widget:
|
widget:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
||||||
|
|
@ -172,11 +172,11 @@ unicode-segmentation = "1.0"
|
||||||
wasm-bindgen-futures = "0.4"
|
wasm-bindgen-futures = "0.4"
|
||||||
wasm-timer = "0.2"
|
wasm-timer = "0.2"
|
||||||
web-sys = "=0.3.67"
|
web-sys = "=0.3.67"
|
||||||
web-time = "0.2"
|
web-time = "1.1"
|
||||||
wgpu = "0.19"
|
wgpu = "0.19"
|
||||||
winapi = "0.3"
|
winapi = "0.3"
|
||||||
window_clipboard = "0.4.1"
|
window_clipboard = "0.4.1"
|
||||||
winit = { git = "https://github.com/iced-rs/winit.git", rev = "592bd152f6d5786fae7d918532d7db752c0d164f" }
|
winit = { git = "https://github.com/iced-rs/winit.git", rev = "8affa522bc6dcc497d332a28c03491d22a22f5a7" }
|
||||||
|
|
||||||
[workspace.lints.rust]
|
[workspace.lints.rust]
|
||||||
rust_2018_idioms = "forbid"
|
rust_2018_idioms = "forbid"
|
||||||
|
|
|
||||||
|
|
@ -10,25 +10,8 @@ The __[`main`]__ file contains all the code of the example.
|
||||||
|
|
||||||
You can run it with `cargo run`:
|
You can run it with `cargo run`:
|
||||||
```
|
```
|
||||||
cargo run --package integration_wgpu
|
cargo run --package integration
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to run this example with WebGL backend
|
|
||||||
NOTE: Currently, WebGL backend is still experimental, so expect bugs.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# 0. Install prerequisites
|
|
||||||
cargo install wasm-bindgen-cli https
|
|
||||||
# 1. cd to the current folder
|
|
||||||
# 2. Compile wasm module
|
|
||||||
cargo build -p integration_wgpu --target wasm32-unknown-unknown
|
|
||||||
# 3. Invoke wasm-bindgen
|
|
||||||
wasm-bindgen ../../target/wasm32-unknown-unknown/debug/integration_wgpu.wasm --out-dir . --target web --no-typescript
|
|
||||||
# 4. run http server
|
|
||||||
http
|
|
||||||
# 5. Open 127.0.0.1:8000 in browser
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
[`main`]: src/main.rs
|
[`main`]: src/main.rs
|
||||||
[`wgpu`]: https://github.com/gfx-rs/wgpu
|
[`wgpu`]: https://github.com/gfx-rs/wgpu
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
|
|
||||||
<title>Iced - wgpu + WebGL integration</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>integration_wgpu</h1>
|
|
||||||
<canvas id="iced_canvas"></canvas>
|
|
||||||
<script type="module">
|
|
||||||
import init from "./integration.js";
|
|
||||||
init('./integration_bg.wasm');
|
|
||||||
</script>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -18,77 +18,74 @@ use iced_winit::winit;
|
||||||
use iced_winit::Clipboard;
|
use iced_winit::Clipboard;
|
||||||
|
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{Event, WindowEvent},
|
event::WindowEvent,
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
keyboard::ModifiersState,
|
keyboard::ModifiersState,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
pub fn main() -> Result<(), winit::error::EventLoopError> {
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
use web_sys::HtmlCanvasElement;
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
use winit::platform::web::WindowBuilderExtWebSys;
|
|
||||||
|
|
||||||
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
let canvas_element = {
|
|
||||||
console_log::init().expect("Initialize logger");
|
|
||||||
|
|
||||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
|
||||||
|
|
||||||
web_sys::window()
|
|
||||||
.and_then(|win| win.document())
|
|
||||||
.and_then(|doc| doc.get_element_by_id("iced_canvas"))
|
|
||||||
.and_then(|element| element.dyn_into::<HtmlCanvasElement>().ok())
|
|
||||||
.expect("Get canvas element")
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
// Initialize winit
|
// Initialize winit
|
||||||
let event_loop = EventLoop::new()?;
|
let event_loop = EventLoop::new()?;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[allow(clippy::large_enum_variant)]
|
||||||
let window = winit::window::WindowBuilder::new()
|
enum Runner {
|
||||||
.with_canvas(Some(canvas_element))
|
Loading,
|
||||||
.build(&event_loop)?;
|
Ready {
|
||||||
|
window: Arc<winit::window::Window>,
|
||||||
|
device: wgpu::Device,
|
||||||
|
queue: wgpu::Queue,
|
||||||
|
surface: wgpu::Surface<'static>,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
|
engine: Engine,
|
||||||
|
renderer: Renderer,
|
||||||
|
scene: Scene,
|
||||||
|
state: program::State<Controls>,
|
||||||
|
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
||||||
|
clipboard: Clipboard,
|
||||||
|
viewport: Viewport,
|
||||||
|
modifiers: ModifiersState,
|
||||||
|
resized: bool,
|
||||||
|
debug: Debug,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
impl winit::application::ApplicationHandler for Runner {
|
||||||
let window = winit::window::Window::new(&event_loop)?;
|
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
||||||
|
if let Self::Loading = self {
|
||||||
let window = Arc::new(window);
|
let window = Arc::new(
|
||||||
|
event_loop
|
||||||
|
.create_window(
|
||||||
|
winit::window::WindowAttributes::default(),
|
||||||
|
)
|
||||||
|
.expect("Create window"),
|
||||||
|
);
|
||||||
|
|
||||||
let physical_size = window.inner_size();
|
let physical_size = window.inner_size();
|
||||||
let mut viewport = Viewport::with_physical_size(
|
let viewport = Viewport::with_physical_size(
|
||||||
Size::new(physical_size.width, physical_size.height),
|
Size::new(physical_size.width, physical_size.height),
|
||||||
window.scale_factor(),
|
window.scale_factor(),
|
||||||
);
|
);
|
||||||
let mut cursor_position = None;
|
let clipboard = Clipboard::connect(&window);
|
||||||
let mut modifiers = ModifiersState::default();
|
|
||||||
let mut clipboard = Clipboard::connect(&window);
|
|
||||||
|
|
||||||
// Initialize wgpu
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
let default_backend = wgpu::Backends::GL;
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
let default_backend = wgpu::Backends::PRIMARY;
|
|
||||||
|
|
||||||
let backend =
|
let backend =
|
||||||
wgpu::util::backend_bits_from_env().unwrap_or(default_backend);
|
wgpu::util::backend_bits_from_env().unwrap_or_default();
|
||||||
|
|
||||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||||
backends: backend,
|
backends: backend,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
let surface = instance.create_surface(window.clone())?;
|
let surface = instance
|
||||||
|
.create_surface(window.clone())
|
||||||
|
.expect("Create window surface");
|
||||||
|
|
||||||
let (format, adapter, device, queue) =
|
let (format, adapter, device, queue) =
|
||||||
futures::futures::executor::block_on(async {
|
futures::futures::executor::block_on(async {
|
||||||
let adapter = wgpu::util::initialize_adapter_from_env_or_default(
|
let adapter =
|
||||||
|
wgpu::util::initialize_adapter_from_env_or_default(
|
||||||
&instance,
|
&instance,
|
||||||
Some(&surface),
|
Some(&surface),
|
||||||
)
|
)
|
||||||
|
|
@ -97,13 +94,6 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
let adapter_features = adapter.features();
|
let adapter_features = adapter.features();
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
let needed_limits = wgpu::Limits::downlevel_webgl2_defaults()
|
|
||||||
.using_resolution(adapter.limits());
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
let needed_limits = wgpu::Limits::default();
|
|
||||||
|
|
||||||
let capabilities = surface.get_capabilities(&adapter);
|
let capabilities = surface.get_capabilities(&adapter);
|
||||||
|
|
||||||
let (device, queue) = adapter
|
let (device, queue) = adapter
|
||||||
|
|
@ -112,7 +102,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
label: None,
|
label: None,
|
||||||
required_features: adapter_features
|
required_features: adapter_features
|
||||||
& wgpu::Features::default(),
|
& wgpu::Features::default(),
|
||||||
required_limits: needed_limits,
|
required_limits: wgpu::Limits::default(),
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
@ -125,7 +115,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.find(wgpu::TextureFormat::is_srgb)
|
.find(wgpu::TextureFormat::is_srgb)
|
||||||
.or_else(|| capabilities.formats.first().copied())
|
.or_else(|| {
|
||||||
|
capabilities.formats.first().copied()
|
||||||
|
})
|
||||||
.expect("Get preferred format"),
|
.expect("Get preferred format"),
|
||||||
adapter,
|
adapter,
|
||||||
device,
|
device,
|
||||||
|
|
@ -147,47 +139,92 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut resized = false;
|
|
||||||
|
|
||||||
// Initialize scene and GUI controls
|
// Initialize scene and GUI controls
|
||||||
let scene = Scene::new(&device, format);
|
let scene = Scene::new(&device, format);
|
||||||
let controls = Controls::new();
|
let controls = Controls::new();
|
||||||
|
|
||||||
// Initialize iced
|
// Initialize iced
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
let mut engine = Engine::new(&adapter, &device, &queue, format, None);
|
let engine =
|
||||||
let mut renderer =
|
Engine::new(&adapter, &device, &queue, format, None);
|
||||||
Renderer::new(&device, &engine, Font::default(), Pixels::from(16));
|
let mut renderer = Renderer::new(
|
||||||
|
&device,
|
||||||
|
&engine,
|
||||||
|
Font::default(),
|
||||||
|
Pixels::from(16),
|
||||||
|
);
|
||||||
|
|
||||||
let mut state = program::State::new(
|
let state = program::State::new(
|
||||||
controls,
|
controls,
|
||||||
viewport.logical_size(),
|
viewport.logical_size(),
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
&mut debug,
|
&mut debug,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Run event loop
|
|
||||||
event_loop.run(move |event, window_target| {
|
|
||||||
// You should change this if you want to render continuously
|
// You should change this if you want to render continuously
|
||||||
window_target.set_control_flow(ControlFlow::Wait);
|
event_loop.set_control_flow(ControlFlow::Wait);
|
||||||
|
|
||||||
|
*self = Self::Ready {
|
||||||
|
window,
|
||||||
|
device,
|
||||||
|
queue,
|
||||||
|
surface,
|
||||||
|
format,
|
||||||
|
engine,
|
||||||
|
renderer,
|
||||||
|
scene,
|
||||||
|
state,
|
||||||
|
cursor_position: None,
|
||||||
|
modifiers: ModifiersState::default(),
|
||||||
|
clipboard,
|
||||||
|
viewport,
|
||||||
|
resized: false,
|
||||||
|
debug,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn window_event(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
_window_id: winit::window::WindowId,
|
||||||
|
event: WindowEvent,
|
||||||
|
) {
|
||||||
|
let Self::Ready {
|
||||||
|
window,
|
||||||
|
device,
|
||||||
|
queue,
|
||||||
|
surface,
|
||||||
|
format,
|
||||||
|
engine,
|
||||||
|
renderer,
|
||||||
|
scene,
|
||||||
|
state,
|
||||||
|
viewport,
|
||||||
|
cursor_position,
|
||||||
|
modifiers,
|
||||||
|
clipboard,
|
||||||
|
resized,
|
||||||
|
debug,
|
||||||
|
} = self
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
WindowEvent::RedrawRequested => {
|
||||||
event: WindowEvent::RedrawRequested,
|
if *resized {
|
||||||
..
|
|
||||||
} => {
|
|
||||||
if resized {
|
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
|
|
||||||
viewport = Viewport::with_physical_size(
|
*viewport = Viewport::with_physical_size(
|
||||||
Size::new(size.width, size.height),
|
Size::new(size.width, size.height),
|
||||||
window.scale_factor(),
|
window.scale_factor(),
|
||||||
);
|
);
|
||||||
|
|
||||||
surface.configure(
|
surface.configure(
|
||||||
&device,
|
device,
|
||||||
&wgpu::SurfaceConfiguration {
|
&wgpu::SurfaceConfiguration {
|
||||||
format,
|
format: *format,
|
||||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
width: size.width,
|
width: size.width,
|
||||||
height: size.height,
|
height: size.height,
|
||||||
|
|
@ -198,7 +235,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
resized = false;
|
*resized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
match surface.get_current_texture() {
|
match surface.get_current_texture() {
|
||||||
|
|
@ -227,23 +264,23 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
// And then iced on top
|
// And then iced on top
|
||||||
renderer.present(
|
renderer.present(
|
||||||
&mut engine,
|
engine,
|
||||||
&device,
|
device,
|
||||||
&queue,
|
queue,
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
None,
|
None,
|
||||||
frame.texture.format(),
|
frame.texture.format(),
|
||||||
&view,
|
&view,
|
||||||
&viewport,
|
viewport,
|
||||||
&debug.overlay(),
|
&debug.overlay(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Then we submit the work
|
// Then we submit the work
|
||||||
queue.submit(Some(encoder.finish()));
|
engine.submit(queue, encoder);
|
||||||
frame.present();
|
frame.present();
|
||||||
|
|
||||||
// Update the mouse cursor
|
// Update the mouse cursor
|
||||||
window.set_cursor_icon(
|
window.set_cursor(
|
||||||
iced_winit::conversion::mouse_interaction(
|
iced_winit::conversion::mouse_interaction(
|
||||||
state.mouse_interaction(),
|
state.mouse_interaction(),
|
||||||
),
|
),
|
||||||
|
|
@ -263,19 +300,17 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::WindowEvent { event, .. } => {
|
|
||||||
match event {
|
|
||||||
WindowEvent::CursorMoved { position, .. } => {
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
cursor_position = Some(position);
|
*cursor_position = Some(position);
|
||||||
}
|
}
|
||||||
WindowEvent::ModifiersChanged(new_modifiers) => {
|
WindowEvent::ModifiersChanged(new_modifiers) => {
|
||||||
modifiers = new_modifiers.state();
|
*modifiers = new_modifiers.state();
|
||||||
}
|
}
|
||||||
WindowEvent::Resized(_) => {
|
WindowEvent::Resized(_) => {
|
||||||
resized = true;
|
*resized = true;
|
||||||
}
|
}
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
window_target.exit();
|
event_loop.exit();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
@ -285,13 +320,10 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
window::Id::MAIN,
|
window::Id::MAIN,
|
||||||
event,
|
event,
|
||||||
window.scale_factor(),
|
window.scale_factor(),
|
||||||
modifiers,
|
*modifiers,
|
||||||
) {
|
) {
|
||||||
state.queue_event(event);
|
state.queue_event(event);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are events pending
|
// If there are events pending
|
||||||
if !state.is_queue_empty() {
|
if !state.is_queue_empty() {
|
||||||
|
|
@ -300,23 +332,28 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
viewport.logical_size(),
|
viewport.logical_size(),
|
||||||
cursor_position
|
cursor_position
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
conversion::cursor_position(p, viewport.scale_factor())
|
conversion::cursor_position(
|
||||||
|
p,
|
||||||
|
viewport.scale_factor(),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.map(mouse::Cursor::Available)
|
.map(mouse::Cursor::Available)
|
||||||
.unwrap_or(mouse::Cursor::Unavailable),
|
.unwrap_or(mouse::Cursor::Unavailable),
|
||||||
&mut renderer,
|
renderer,
|
||||||
&Theme::Dark,
|
&Theme::Dark,
|
||||||
&renderer::Style {
|
&renderer::Style {
|
||||||
text_color: Color::WHITE,
|
text_color: Color::WHITE,
|
||||||
},
|
},
|
||||||
&mut clipboard,
|
clipboard,
|
||||||
&mut debug,
|
debug,
|
||||||
);
|
);
|
||||||
|
|
||||||
// and request a redraw
|
// and request a redraw
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
})?;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
let mut runner = Runner::Loading;
|
||||||
|
event_loop.run_app(&mut runner)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,26 +212,11 @@ where
|
||||||
..crate::graphics::Settings::default()
|
..crate::graphics::Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let run = crate::shell::application::run::<
|
Ok(crate::shell::application::run::<
|
||||||
Instance<Self>,
|
Instance<Self>,
|
||||||
Self::Executor,
|
Self::Executor,
|
||||||
<Self::Renderer as compositor::Default>::Compositor,
|
<Self::Renderer as compositor::Default>::Compositor,
|
||||||
>(settings.into(), renderer_settings);
|
>(settings.into(), renderer_settings)?)
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
{
|
|
||||||
use crate::futures::FutureExt;
|
|
||||||
use iced_futures::backend::wasm::wasm_bindgen::Executor;
|
|
||||||
|
|
||||||
Executor::new()
|
|
||||||
.expect("Create Wasm executor")
|
|
||||||
.spawn(run.map(|_| ()));
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
Ok(crate::futures::executor::block_on(run)?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,6 @@ use crate::core::{
|
||||||
use crate::graphics::text::{Editor, Paragraph};
|
use crate::graphics::text::{Editor, Paragraph};
|
||||||
use crate::graphics::Viewport;
|
use crate::graphics::Viewport;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
|
|
||||||
/// A [`wgpu`] graphics renderer for [`iced`].
|
/// A [`wgpu`] graphics renderer for [`iced`].
|
||||||
///
|
///
|
||||||
/// [`wgpu`]: https://github.com/gfx-rs/wgpu-rs
|
/// [`wgpu`]: https://github.com/gfx-rs/wgpu-rs
|
||||||
|
|
@ -84,7 +82,7 @@ pub struct Renderer {
|
||||||
|
|
||||||
// TODO: Centralize all the image feature handling
|
// TODO: Centralize all the image feature handling
|
||||||
#[cfg(any(feature = "svg", feature = "image"))]
|
#[cfg(any(feature = "svg", feature = "image"))]
|
||||||
image_cache: RefCell<image::Cache>,
|
image_cache: std::cell::RefCell<image::Cache>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Renderer {
|
impl Renderer {
|
||||||
|
|
@ -103,7 +101,9 @@ impl Renderer {
|
||||||
text_storage: text::Storage::new(),
|
text_storage: text::Storage::new(),
|
||||||
|
|
||||||
#[cfg(any(feature = "svg", feature = "image"))]
|
#[cfg(any(feature = "svg", feature = "image"))]
|
||||||
image_cache: RefCell::new(_engine.create_image_cache(_device)),
|
image_cache: std::cell::RefCell::new(
|
||||||
|
_engine.create_image_cache(_device),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ wayland-csd-adwaita = ["winit/wayland-csd-adwaita"]
|
||||||
multi-window = ["iced_runtime/multi-window"]
|
multi-window = ["iced_runtime/multi-window"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
iced_futures.workspace = true
|
||||||
iced_graphics.workspace = true
|
iced_graphics.workspace = true
|
||||||
iced_runtime.workspace = true
|
iced_runtime.workspace = true
|
||||||
|
|
||||||
|
|
@ -32,6 +33,7 @@ log.workspace = true
|
||||||
rustc-hash.workspace = true
|
rustc-hash.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
|
wasm-bindgen-futures.workspace = true
|
||||||
window_clipboard.workspace = true
|
window_clipboard.workspace = true
|
||||||
winit.workspace = true
|
winit.workspace = true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,9 @@ use crate::runtime::{Command, Debug};
|
||||||
use crate::{Clipboard, Error, Proxy, Settings};
|
use crate::{Clipboard, Error, Proxy, Settings};
|
||||||
|
|
||||||
use futures::channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
|
use futures::channel::oneshot;
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
|
@ -129,7 +131,7 @@ pub fn default(theme: &Theme) -> Appearance {
|
||||||
|
|
||||||
/// Runs an [`Application`] with an executor, compositor, and the provided
|
/// Runs an [`Application`] with an executor, compositor, and the provided
|
||||||
/// settings.
|
/// settings.
|
||||||
pub async fn run<A, E, C>(
|
pub fn run<A, E, C>(
|
||||||
settings: Settings<A::Flags>,
|
settings: Settings<A::Flags>,
|
||||||
graphics_settings: graphics::Settings,
|
graphics_settings: graphics::Settings,
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
|
|
@ -141,12 +143,12 @@ where
|
||||||
{
|
{
|
||||||
use futures::task;
|
use futures::task;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use winit::event_loop::EventLoopBuilder;
|
use winit::event_loop::EventLoop;
|
||||||
|
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
debug.startup_started();
|
debug.startup_started();
|
||||||
|
|
||||||
let event_loop = EventLoopBuilder::with_user_event()
|
let event_loop = EventLoop::with_user_event()
|
||||||
.build()
|
.build()
|
||||||
.expect("Create event loop");
|
.expect("Create event loop");
|
||||||
|
|
||||||
|
|
@ -165,27 +167,136 @@ where
|
||||||
runtime.enter(|| A::new(flags))
|
runtime.enter(|| A::new(flags))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let id = settings.id;
|
||||||
|
let title = application.title();
|
||||||
|
|
||||||
|
let (boot_sender, boot_receiver) = oneshot::channel();
|
||||||
|
let (event_sender, event_receiver) = mpsc::unbounded();
|
||||||
|
let (control_sender, control_receiver) = mpsc::unbounded();
|
||||||
|
|
||||||
|
let instance = Box::pin(run_instance::<A, E, C>(
|
||||||
|
application,
|
||||||
|
runtime,
|
||||||
|
proxy,
|
||||||
|
debug,
|
||||||
|
boot_receiver,
|
||||||
|
event_receiver,
|
||||||
|
control_sender,
|
||||||
|
init_command,
|
||||||
|
settings.fonts,
|
||||||
|
));
|
||||||
|
|
||||||
|
let context = task::Context::from_waker(task::noop_waker_ref());
|
||||||
|
|
||||||
|
struct Runner<Message: 'static, F, C> {
|
||||||
|
instance: std::pin::Pin<Box<F>>,
|
||||||
|
context: task::Context<'static>,
|
||||||
|
boot: Option<BootConfig<C>>,
|
||||||
|
sender: mpsc::UnboundedSender<winit::event::Event<Message>>,
|
||||||
|
receiver: mpsc::UnboundedReceiver<winit::event_loop::ControlFlow>,
|
||||||
|
error: Option<Error>,
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
let target = settings.window.platform_specific.target.clone();
|
is_booted: std::rc::Rc<std::cell::RefCell<bool>>,
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
queued_events: Vec<winit::event::Event<Message>>,
|
||||||
|
}
|
||||||
|
|
||||||
let should_be_visible = settings.window.visible;
|
struct BootConfig<C> {
|
||||||
let exit_on_close_request = settings.window.exit_on_close_request;
|
sender: oneshot::Sender<Boot<C>>,
|
||||||
|
id: Option<String>,
|
||||||
|
title: String,
|
||||||
|
window_settings: window::Settings,
|
||||||
|
graphics_settings: graphics::Settings,
|
||||||
|
}
|
||||||
|
|
||||||
let builder = conversion::window_settings(
|
let runner = Runner {
|
||||||
settings.window,
|
instance,
|
||||||
&application.title(),
|
context,
|
||||||
|
boot: Some(BootConfig {
|
||||||
|
sender: boot_sender,
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
window_settings: settings.window,
|
||||||
|
graphics_settings,
|
||||||
|
}),
|
||||||
|
sender: event_sender,
|
||||||
|
receiver: control_receiver,
|
||||||
|
error: None,
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
is_booted: std::rc::Rc::new(std::cell::RefCell::new(false)),
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
queued_events: Vec::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<Message, F, C> winit::application::ApplicationHandler<Message>
|
||||||
|
for Runner<Message, F, C>
|
||||||
|
where
|
||||||
|
F: Future<Output = ()>,
|
||||||
|
C: Compositor + 'static,
|
||||||
|
{
|
||||||
|
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
||||||
|
let Some(BootConfig {
|
||||||
|
sender,
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
window_settings,
|
||||||
|
graphics_settings,
|
||||||
|
}) = self.boot.take()
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let should_be_visible = window_settings.visible;
|
||||||
|
let exit_on_close_request = window_settings.exit_on_close_request;
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
let target = window_settings.platform_specific.target.clone();
|
||||||
|
|
||||||
|
let window_attributes = conversion::window_attributes(
|
||||||
|
window_settings,
|
||||||
|
&title,
|
||||||
event_loop.primary_monitor(),
|
event_loop.primary_monitor(),
|
||||||
settings.id,
|
id,
|
||||||
)
|
)
|
||||||
.with_visible(false);
|
.with_visible(false);
|
||||||
|
|
||||||
log::debug!("Window builder: {builder:#?}");
|
log::debug!("Window attributes: {window_attributes:#?}");
|
||||||
|
|
||||||
let window = Arc::new(
|
let window = match event_loop.create_window(window_attributes) {
|
||||||
builder
|
Ok(window) => Arc::new(window),
|
||||||
.build(&event_loop)
|
Err(error) => {
|
||||||
.map_err(Error::WindowCreationFailed)?,
|
self.error = Some(Error::WindowCreationFailed(error));
|
||||||
);
|
event_loop.exit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let finish_boot = {
|
||||||
|
let window = window.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
|
let compositor =
|
||||||
|
C::new(graphics_settings, window.clone()).await?;
|
||||||
|
|
||||||
|
sender
|
||||||
|
.send(Boot {
|
||||||
|
window,
|
||||||
|
compositor,
|
||||||
|
should_be_visible,
|
||||||
|
exit_on_close_request,
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
.expect("Send boot event");
|
||||||
|
|
||||||
|
Ok::<_, graphics::Error>(())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
if let Err(error) = futures::executor::block_on(finish_boot) {
|
||||||
|
self.error = Some(Error::GraphicsCreationFailed(error));
|
||||||
|
event_loop.exit();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
|
|
@ -209,9 +320,9 @@ where
|
||||||
|
|
||||||
match target {
|
match target {
|
||||||
Some(node) => {
|
Some(node) => {
|
||||||
let _ = node
|
let _ = node.replace_with_with_node_1(&canvas).expect(
|
||||||
.replace_with_with_node_1(&canvas)
|
&format!("Could not replace #{}", node.id()),
|
||||||
.expect(&format!("Could not replace #{}", node.id()));
|
);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let _ = body
|
let _ = body
|
||||||
|
|
@ -219,59 +330,34 @@ where
|
||||||
.expect("Append canvas to HTML body");
|
.expect("Append canvas to HTML body");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
let mut compositor = C::new(graphics_settings, window.clone()).await?;
|
let is_booted = self.is_booted.clone();
|
||||||
let renderer = compositor.create_renderer();
|
|
||||||
|
|
||||||
for font in settings.fonts {
|
wasm_bindgen_futures::spawn_local(async move {
|
||||||
compositor.load_font(font);
|
finish_boot.await.expect("Finish boot!");
|
||||||
}
|
|
||||||
|
|
||||||
let (mut event_sender, event_receiver) = mpsc::unbounded();
|
*is_booted.borrow_mut() = true;
|
||||||
let (control_sender, mut control_receiver) = mpsc::unbounded();
|
});
|
||||||
|
|
||||||
let mut instance = Box::pin(run_instance::<A, E, C>(
|
|
||||||
application,
|
|
||||||
compositor,
|
|
||||||
renderer,
|
|
||||||
runtime,
|
|
||||||
proxy,
|
|
||||||
debug,
|
|
||||||
event_receiver,
|
|
||||||
control_sender,
|
|
||||||
init_command,
|
|
||||||
window,
|
|
||||||
should_be_visible,
|
|
||||||
exit_on_close_request,
|
|
||||||
));
|
|
||||||
|
|
||||||
let mut context = task::Context::from_waker(task::noop_waker_ref());
|
|
||||||
|
|
||||||
let process_event =
|
|
||||||
move |event, event_loop: &winit::event_loop::EventLoopWindowTarget<_>| {
|
|
||||||
if event_loop.exiting() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event_sender.start_send(event).expect("Send event");
|
|
||||||
|
|
||||||
let poll = instance.as_mut().poll(&mut context);
|
|
||||||
|
|
||||||
match poll {
|
|
||||||
task::Poll::Pending => {
|
|
||||||
if let Ok(Some(flow)) = control_receiver.try_next() {
|
|
||||||
event_loop.set_control_flow(flow);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
task::Poll::Ready(_) => {
|
|
||||||
event_loop.exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
fn window_event(
|
||||||
let _ = event_loop.run(process_event);
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
window_id: winit::window::WindowId,
|
||||||
|
event: winit::event::WindowEvent,
|
||||||
|
) {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let is_move_or_resize = matches!(
|
||||||
|
event,
|
||||||
|
winit::event::WindowEvent::Resized(_)
|
||||||
|
| winit::event::WindowEvent::Moved(_)
|
||||||
|
);
|
||||||
|
|
||||||
|
self.process_event(
|
||||||
|
event_loop,
|
||||||
|
winit::event::Event::WindowEvent { window_id, event },
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: Remove when unnecessary
|
// TODO: Remove when unnecessary
|
||||||
// On Windows, we emulate an `AboutToWait` event after every `Resized` event
|
// On Windows, we emulate an `AboutToWait` event after every `Resized` event
|
||||||
|
|
@ -279,43 +365,115 @@ where
|
||||||
// More details: https://github.com/rust-windowing/winit/issues/3272
|
// More details: https://github.com/rust-windowing/winit/issues/3272
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
let mut process_event = process_event;
|
if is_move_or_resize {
|
||||||
|
self.process_event(
|
||||||
|
event_loop,
|
||||||
|
winit::event::Event::AboutToWait,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let _ = event_loop.run(move |event, event_loop| {
|
fn user_event(
|
||||||
if matches!(
|
&mut self,
|
||||||
event,
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
winit::event::Event::WindowEvent {
|
message: Message,
|
||||||
event: winit::event::WindowEvent::Resized(_)
|
|
||||||
| winit::event::WindowEvent::Moved(_),
|
|
||||||
..
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
process_event(event, event_loop);
|
self.process_event(
|
||||||
process_event(winit::event::Event::AboutToWait, event_loop);
|
event_loop,
|
||||||
} else {
|
winit::event::Event::UserEvent(message),
|
||||||
process_event(event, event_loop);
|
);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
fn about_to_wait(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
) {
|
||||||
|
self.process_event(event_loop, winit::event::Event::AboutToWait);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Message, F, C> Runner<Message, F, C>
|
||||||
|
where
|
||||||
|
F: Future<Output = ()>,
|
||||||
|
{
|
||||||
|
fn process_event(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
event: winit::event::Event<Message>,
|
||||||
|
) {
|
||||||
|
// On Wasm, events may start being processed before the compositor
|
||||||
|
// boots up. We simply queue them and process them once ready.
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
if !*self.is_booted.borrow() {
|
||||||
|
self.queued_events.push(event);
|
||||||
|
return;
|
||||||
|
} else if !self.queued_events.is_empty() {
|
||||||
|
let queued_events = std::mem::take(&mut self.queued_events);
|
||||||
|
|
||||||
|
// This won't infinitely recurse, since we `mem::take`
|
||||||
|
for event in queued_events {
|
||||||
|
self.process_event(event_loop, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if event_loop.exiting() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.sender.start_send(event).expect("Send event");
|
||||||
|
|
||||||
|
let poll = self.instance.as_mut().poll(&mut self.context);
|
||||||
|
|
||||||
|
match poll {
|
||||||
|
task::Poll::Pending => {
|
||||||
|
if let Ok(Some(flow)) = self.receiver.try_next() {
|
||||||
|
event_loop.set_control_flow(flow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task::Poll::Ready(_) => {
|
||||||
|
event_loop.exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
{
|
||||||
|
let mut runner = runner;
|
||||||
|
let _ = event_loop.run_app(&mut runner);
|
||||||
|
|
||||||
|
runner.error.map(Err).unwrap_or(Ok(()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
{
|
||||||
|
use winit::platform::web::EventLoopExtWebSys;
|
||||||
|
let _ = event_loop.spawn_app(runner);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Boot<C> {
|
||||||
|
window: Arc<winit::window::Window>,
|
||||||
|
compositor: C,
|
||||||
|
should_be_visible: bool,
|
||||||
|
exit_on_close_request: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_instance<A, E, C>(
|
async fn run_instance<A, E, C>(
|
||||||
mut application: A,
|
mut application: A,
|
||||||
mut compositor: C,
|
|
||||||
mut renderer: A::Renderer,
|
|
||||||
mut runtime: Runtime<E, Proxy<A::Message>, A::Message>,
|
mut runtime: Runtime<E, Proxy<A::Message>, A::Message>,
|
||||||
mut proxy: Proxy<A::Message>,
|
mut proxy: Proxy<A::Message>,
|
||||||
mut debug: Debug,
|
mut debug: Debug,
|
||||||
|
mut boot: oneshot::Receiver<Boot<C>>,
|
||||||
mut event_receiver: mpsc::UnboundedReceiver<
|
mut event_receiver: mpsc::UnboundedReceiver<
|
||||||
winit::event::Event<A::Message>,
|
winit::event::Event<A::Message>,
|
||||||
>,
|
>,
|
||||||
mut control_sender: mpsc::UnboundedSender<winit::event_loop::ControlFlow>,
|
mut control_sender: mpsc::UnboundedSender<winit::event_loop::ControlFlow>,
|
||||||
init_command: Command<A::Message>,
|
init_command: Command<A::Message>,
|
||||||
window: Arc<winit::window::Window>,
|
fonts: Vec<Cow<'static, [u8]>>,
|
||||||
should_be_visible: bool,
|
|
||||||
exit_on_close_request: bool,
|
|
||||||
) where
|
) where
|
||||||
A: Application + 'static,
|
A: Application + 'static,
|
||||||
E: Executor + 'static,
|
E: Executor + 'static,
|
||||||
|
|
@ -326,6 +484,19 @@ async fn run_instance<A, E, C>(
|
||||||
use winit::event;
|
use winit::event;
|
||||||
use winit::event_loop::ControlFlow;
|
use winit::event_loop::ControlFlow;
|
||||||
|
|
||||||
|
let Boot {
|
||||||
|
window,
|
||||||
|
mut compositor,
|
||||||
|
should_be_visible,
|
||||||
|
exit_on_close_request,
|
||||||
|
} = boot.try_recv().ok().flatten().expect("Receive boot");
|
||||||
|
|
||||||
|
let mut renderer = compositor.create_renderer();
|
||||||
|
|
||||||
|
for font in fonts {
|
||||||
|
compositor.load_font(font);
|
||||||
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|
@ -480,7 +651,7 @@ async fn run_instance<A, E, C>(
|
||||||
debug.draw_finished();
|
debug.draw_finished();
|
||||||
|
|
||||||
if new_mouse_interaction != mouse_interaction {
|
if new_mouse_interaction != mouse_interaction {
|
||||||
window.set_cursor_icon(conversion::mouse_interaction(
|
window.set_cursor(conversion::mouse_interaction(
|
||||||
new_mouse_interaction,
|
new_mouse_interaction,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,16 @@ use crate::core::touch;
|
||||||
use crate::core::window;
|
use crate::core::window;
|
||||||
use crate::core::{Event, Point, Size};
|
use crate::core::{Event, Point, Size};
|
||||||
|
|
||||||
/// Converts some [`window::Settings`] into a `WindowBuilder` from `winit`.
|
/// Converts some [`window::Settings`] into some `WindowAttributes` from `winit`.
|
||||||
pub fn window_settings(
|
pub fn window_attributes(
|
||||||
settings: window::Settings,
|
settings: window::Settings,
|
||||||
title: &str,
|
title: &str,
|
||||||
primary_monitor: Option<winit::monitor::MonitorHandle>,
|
primary_monitor: Option<winit::monitor::MonitorHandle>,
|
||||||
_id: Option<String>,
|
_id: Option<String>,
|
||||||
) -> winit::window::WindowBuilder {
|
) -> winit::window::WindowAttributes {
|
||||||
let mut window_builder = winit::window::WindowBuilder::new();
|
let mut attributes = winit::window::WindowAttributes::default();
|
||||||
|
|
||||||
window_builder = window_builder
|
attributes = attributes
|
||||||
.with_title(title)
|
.with_title(title)
|
||||||
.with_inner_size(winit::dpi::LogicalSize {
|
.with_inner_size(winit::dpi::LogicalSize {
|
||||||
width: settings.size.width,
|
width: settings.size.width,
|
||||||
|
|
@ -39,20 +39,18 @@ pub fn window_settings(
|
||||||
if let Some(position) =
|
if let Some(position) =
|
||||||
position(primary_monitor.as_ref(), settings.size, settings.position)
|
position(primary_monitor.as_ref(), settings.size, settings.position)
|
||||||
{
|
{
|
||||||
window_builder = window_builder.with_position(position);
|
attributes = attributes.with_position(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(min_size) = settings.min_size {
|
if let Some(min_size) = settings.min_size {
|
||||||
window_builder =
|
attributes = attributes.with_min_inner_size(winit::dpi::LogicalSize {
|
||||||
window_builder.with_min_inner_size(winit::dpi::LogicalSize {
|
|
||||||
width: min_size.width,
|
width: min_size.width,
|
||||||
height: min_size.height,
|
height: min_size.height,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(max_size) = settings.max_size {
|
if let Some(max_size) = settings.max_size {
|
||||||
window_builder =
|
attributes = attributes.with_max_inner_size(winit::dpi::LogicalSize {
|
||||||
window_builder.with_max_inner_size(winit::dpi::LogicalSize {
|
|
||||||
width: max_size.width,
|
width: max_size.width,
|
||||||
height: max_size.height,
|
height: max_size.height,
|
||||||
});
|
});
|
||||||
|
|
@ -65,35 +63,33 @@ pub fn window_settings(
|
||||||
target_os = "openbsd"
|
target_os = "openbsd"
|
||||||
))]
|
))]
|
||||||
{
|
{
|
||||||
// `with_name` is available on both `WindowBuilderExtWayland` and `WindowBuilderExtX11` and they do
|
use ::winit::platform::wayland::WindowAttributesExtWayland;
|
||||||
// exactly the same thing. We arbitrarily choose `WindowBuilderExtWayland` here.
|
|
||||||
use ::winit::platform::wayland::WindowBuilderExtWayland;
|
|
||||||
|
|
||||||
if let Some(id) = _id {
|
if let Some(id) = _id {
|
||||||
window_builder = window_builder.with_name(id.clone(), id);
|
attributes = attributes.with_name(id.clone(), id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
use winit::platform::windows::WindowBuilderExtWindows;
|
use winit::platform::windows::WindowAttributesExtWindows;
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe {
|
unsafe {
|
||||||
window_builder = window_builder
|
attributes = attributes
|
||||||
.with_parent_window(settings.platform_specific.parent);
|
.with_parent_window(settings.platform_specific.parent);
|
||||||
}
|
}
|
||||||
window_builder = window_builder
|
attributes = attributes
|
||||||
.with_drag_and_drop(settings.platform_specific.drag_and_drop);
|
.with_drag_and_drop(settings.platform_specific.drag_and_drop);
|
||||||
|
|
||||||
window_builder = window_builder
|
attributes = attributes
|
||||||
.with_skip_taskbar(settings.platform_specific.skip_taskbar);
|
.with_skip_taskbar(settings.platform_specific.skip_taskbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
use winit::platform::macos::WindowBuilderExtMacOS;
|
use winit::platform::macos::WindowAttributesExtMacOS;
|
||||||
|
|
||||||
window_builder = window_builder
|
attributes = attributes
|
||||||
.with_title_hidden(settings.platform_specific.title_hidden)
|
.with_title_hidden(settings.platform_specific.title_hidden)
|
||||||
.with_titlebar_transparent(
|
.with_titlebar_transparent(
|
||||||
settings.platform_specific.titlebar_transparent,
|
settings.platform_specific.titlebar_transparent,
|
||||||
|
|
@ -107,25 +103,25 @@ pub fn window_settings(
|
||||||
{
|
{
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
{
|
{
|
||||||
use winit::platform::x11::WindowBuilderExtX11;
|
use winit::platform::x11::WindowAttributesExtX11;
|
||||||
|
|
||||||
window_builder = window_builder.with_name(
|
attributes = attributes.with_name(
|
||||||
&settings.platform_specific.application_id,
|
&settings.platform_specific.application_id,
|
||||||
&settings.platform_specific.application_id,
|
&settings.platform_specific.application_id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
{
|
{
|
||||||
use winit::platform::wayland::WindowBuilderExtWayland;
|
use winit::platform::wayland::WindowAttributesExtWayland;
|
||||||
|
|
||||||
window_builder = window_builder.with_name(
|
attributes = attributes.with_name(
|
||||||
&settings.platform_specific.application_id,
|
&settings.platform_specific.application_id,
|
||||||
&settings.platform_specific.application_id,
|
&settings.platform_specific.application_id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window_builder
|
attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a winit window event into an iced event.
|
/// Converts a winit window event into an iced event.
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ use crate::core::widget::operation;
|
||||||
use crate::core::window;
|
use crate::core::window;
|
||||||
use crate::core::{Point, Size};
|
use crate::core::{Point, Size};
|
||||||
use crate::futures::futures::channel::mpsc;
|
use crate::futures::futures::channel::mpsc;
|
||||||
|
use crate::futures::futures::channel::oneshot;
|
||||||
use crate::futures::futures::executor;
|
use crate::futures::futures::executor;
|
||||||
use crate::futures::futures::task;
|
use crate::futures::futures::task;
|
||||||
use crate::futures::futures::{Future, StreamExt};
|
use crate::futures::futures::{Future, StreamExt};
|
||||||
|
|
@ -114,12 +115,12 @@ where
|
||||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||||
A::Theme: DefaultStyle,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
use winit::event_loop::EventLoopBuilder;
|
use winit::event_loop::EventLoop;
|
||||||
|
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
debug.startup_started();
|
debug.startup_started();
|
||||||
|
|
||||||
let event_loop = EventLoopBuilder::with_user_event()
|
let event_loop = EventLoop::with_user_event()
|
||||||
.build()
|
.build()
|
||||||
.expect("Create event loop");
|
.expect("Create event loop");
|
||||||
|
|
||||||
|
|
@ -138,99 +139,204 @@ where
|
||||||
runtime.enter(|| A::new(flags))
|
runtime.enter(|| A::new(flags))
|
||||||
};
|
};
|
||||||
|
|
||||||
let should_main_be_visible = settings.window.visible;
|
let id = settings.id;
|
||||||
let exit_on_close_request = settings.window.exit_on_close_request;
|
let title = application.title(window::Id::MAIN);
|
||||||
|
|
||||||
let builder = conversion::window_settings(
|
let (boot_sender, boot_receiver) = oneshot::channel();
|
||||||
settings.window,
|
let (event_sender, event_receiver) = mpsc::unbounded();
|
||||||
&application.title(window::Id::MAIN),
|
let (control_sender, control_receiver) = mpsc::unbounded();
|
||||||
event_loop.primary_monitor(),
|
|
||||||
settings.id,
|
|
||||||
)
|
|
||||||
.with_visible(false);
|
|
||||||
|
|
||||||
log::info!("Window builder: {:#?}", builder);
|
let instance = Box::pin(run_instance::<A, E, C>(
|
||||||
|
|
||||||
let main_window = Arc::new(
|
|
||||||
builder
|
|
||||||
.build(&event_loop)
|
|
||||||
.map_err(Error::WindowCreationFailed)?,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
{
|
|
||||||
use winit::platform::web::WindowExtWebSys;
|
|
||||||
|
|
||||||
let canvas = main_window.canvas();
|
|
||||||
|
|
||||||
let window = web_sys::window().unwrap();
|
|
||||||
let document = window.document().unwrap();
|
|
||||||
let body = document.body().unwrap();
|
|
||||||
|
|
||||||
let target = target.and_then(|target| {
|
|
||||||
body.query_selector(&format!("#{}", target))
|
|
||||||
.ok()
|
|
||||||
.unwrap_or(None)
|
|
||||||
});
|
|
||||||
|
|
||||||
match target {
|
|
||||||
Some(node) => {
|
|
||||||
let _ = node
|
|
||||||
.replace_with_with_node_1(&canvas)
|
|
||||||
.expect(&format!("Could not replace #{}", node.id()));
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
let _ = body
|
|
||||||
.append_child(&canvas)
|
|
||||||
.expect("Append canvas to HTML body");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut compositor =
|
|
||||||
executor::block_on(C::new(graphics_settings, main_window.clone()))?;
|
|
||||||
|
|
||||||
let mut window_manager = WindowManager::new();
|
|
||||||
let _ = window_manager.insert(
|
|
||||||
window::Id::MAIN,
|
|
||||||
main_window,
|
|
||||||
&application,
|
|
||||||
&mut compositor,
|
|
||||||
exit_on_close_request,
|
|
||||||
);
|
|
||||||
|
|
||||||
let (mut event_sender, event_receiver) = mpsc::unbounded();
|
|
||||||
let (control_sender, mut control_receiver) = mpsc::unbounded();
|
|
||||||
|
|
||||||
let mut instance = Box::pin(run_instance::<A, E, C>(
|
|
||||||
application,
|
application,
|
||||||
compositor,
|
|
||||||
runtime,
|
runtime,
|
||||||
proxy,
|
proxy,
|
||||||
debug,
|
debug,
|
||||||
|
boot_receiver,
|
||||||
event_receiver,
|
event_receiver,
|
||||||
control_sender,
|
control_sender,
|
||||||
init_command,
|
init_command,
|
||||||
window_manager,
|
|
||||||
should_main_be_visible,
|
|
||||||
));
|
));
|
||||||
|
|
||||||
let mut context = task::Context::from_waker(task::noop_waker_ref());
|
let context = task::Context::from_waker(task::noop_waker_ref());
|
||||||
|
|
||||||
let process_event = move |event, event_loop: &winit::event_loop::EventLoopWindowTarget<_>| {
|
struct Runner<Message: 'static, F, C> {
|
||||||
|
instance: std::pin::Pin<Box<F>>,
|
||||||
|
context: task::Context<'static>,
|
||||||
|
boot: Option<BootConfig<C>>,
|
||||||
|
sender: mpsc::UnboundedSender<Event<Message>>,
|
||||||
|
receiver: mpsc::UnboundedReceiver<Control>,
|
||||||
|
error: Option<Error>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct BootConfig<C> {
|
||||||
|
sender: oneshot::Sender<Boot<C>>,
|
||||||
|
id: Option<String>,
|
||||||
|
title: String,
|
||||||
|
window_settings: window::Settings,
|
||||||
|
graphics_settings: graphics::Settings,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut runner = Runner {
|
||||||
|
instance,
|
||||||
|
context,
|
||||||
|
boot: Some(BootConfig {
|
||||||
|
sender: boot_sender,
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
window_settings: settings.window,
|
||||||
|
graphics_settings,
|
||||||
|
}),
|
||||||
|
sender: event_sender,
|
||||||
|
receiver: control_receiver,
|
||||||
|
error: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<Message, F, C> winit::application::ApplicationHandler<Message>
|
||||||
|
for Runner<Message, F, C>
|
||||||
|
where
|
||||||
|
F: Future<Output = ()>,
|
||||||
|
C: Compositor,
|
||||||
|
{
|
||||||
|
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
||||||
|
let Some(BootConfig {
|
||||||
|
sender,
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
window_settings,
|
||||||
|
graphics_settings,
|
||||||
|
}) = self.boot.take()
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let should_be_visible = window_settings.visible;
|
||||||
|
let exit_on_close_request = window_settings.exit_on_close_request;
|
||||||
|
|
||||||
|
let window_attributes = conversion::window_attributes(
|
||||||
|
window_settings,
|
||||||
|
&title,
|
||||||
|
event_loop.primary_monitor(),
|
||||||
|
id,
|
||||||
|
)
|
||||||
|
.with_visible(false);
|
||||||
|
|
||||||
|
log::debug!("Window attributes: {window_attributes:#?}");
|
||||||
|
|
||||||
|
let window = match event_loop.create_window(window_attributes) {
|
||||||
|
Ok(window) => Arc::new(window),
|
||||||
|
Err(error) => {
|
||||||
|
self.error = Some(Error::WindowCreationFailed(error));
|
||||||
|
event_loop.exit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let finish_boot = async move {
|
||||||
|
let compositor =
|
||||||
|
C::new(graphics_settings, window.clone()).await?;
|
||||||
|
|
||||||
|
sender
|
||||||
|
.send(Boot {
|
||||||
|
window,
|
||||||
|
compositor,
|
||||||
|
should_be_visible,
|
||||||
|
exit_on_close_request,
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
.expect("Send boot event");
|
||||||
|
|
||||||
|
Ok::<_, graphics::Error>(())
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(error) = executor::block_on(finish_boot) {
|
||||||
|
self.error = Some(Error::GraphicsCreationFailed(error));
|
||||||
|
event_loop.exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn window_event(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
window_id: winit::window::WindowId,
|
||||||
|
event: winit::event::WindowEvent,
|
||||||
|
) {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let is_move_or_resize = matches!(
|
||||||
|
event,
|
||||||
|
winit::event::WindowEvent::Resized(_)
|
||||||
|
| winit::event::WindowEvent::Moved(_)
|
||||||
|
);
|
||||||
|
|
||||||
|
self.process_event(
|
||||||
|
event_loop,
|
||||||
|
Event::EventLoopAwakened(winit::event::Event::WindowEvent {
|
||||||
|
window_id,
|
||||||
|
event,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: Remove when unnecessary
|
||||||
|
// On Windows, we emulate an `AboutToWait` event after every `Resized` event
|
||||||
|
// since the event loop does not resume during resize interaction.
|
||||||
|
// More details: https://github.com/rust-windowing/winit/issues/3272
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
if is_move_or_resize {
|
||||||
|
self.process_event(
|
||||||
|
event_loop,
|
||||||
|
Event::EventLoopAwakened(
|
||||||
|
winit::event::Event::AboutToWait,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn user_event(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
message: Message,
|
||||||
|
) {
|
||||||
|
self.process_event(
|
||||||
|
event_loop,
|
||||||
|
Event::EventLoopAwakened(winit::event::Event::UserEvent(
|
||||||
|
message,
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn about_to_wait(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
) {
|
||||||
|
self.process_event(
|
||||||
|
event_loop,
|
||||||
|
Event::EventLoopAwakened(winit::event::Event::AboutToWait),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Message, F, C> Runner<Message, F, C>
|
||||||
|
where
|
||||||
|
F: Future<Output = ()>,
|
||||||
|
C: Compositor,
|
||||||
|
{
|
||||||
|
fn process_event(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
event: Event<Message>,
|
||||||
|
) {
|
||||||
if event_loop.exiting() {
|
if event_loop.exiting() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_sender
|
self.sender.start_send(event).expect("Send event");
|
||||||
.start_send(Event::EventLoopAwakened(event))
|
|
||||||
.expect("Send event");
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let poll = instance.as_mut().poll(&mut context);
|
let poll = self.instance.as_mut().poll(&mut self.context);
|
||||||
|
|
||||||
match poll {
|
match poll {
|
||||||
task::Poll::Pending => match control_receiver.try_next() {
|
task::Poll::Pending => match self.receiver.try_next() {
|
||||||
Ok(Some(control)) => match control {
|
Ok(Some(control)) => match control {
|
||||||
Control::ChangeFlow(flow) => {
|
Control::ChangeFlow(flow) => {
|
||||||
use winit::event_loop::ControlFlow;
|
use winit::event_loop::ControlFlow;
|
||||||
|
|
@ -258,19 +364,22 @@ where
|
||||||
let exit_on_close_request =
|
let exit_on_close_request =
|
||||||
settings.exit_on_close_request;
|
settings.exit_on_close_request;
|
||||||
|
|
||||||
let window = conversion::window_settings(
|
let window = event_loop
|
||||||
|
.create_window(
|
||||||
|
conversion::window_attributes(
|
||||||
settings, &title, monitor, None,
|
settings, &title, monitor, None,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.build(event_loop)
|
.expect("Create window");
|
||||||
.expect("Failed to build window");
|
|
||||||
|
|
||||||
event_sender
|
self.process_event(
|
||||||
.start_send(Event::WindowCreated {
|
event_loop,
|
||||||
|
Event::WindowCreated {
|
||||||
id,
|
id,
|
||||||
window,
|
window,
|
||||||
exit_on_close_request,
|
exit_on_close_request,
|
||||||
})
|
},
|
||||||
.expect("Send event");
|
);
|
||||||
}
|
}
|
||||||
Control::Exit => {
|
Control::Exit => {
|
||||||
event_loop.exit();
|
event_loop.exit();
|
||||||
|
|
@ -286,39 +395,21 @@ where
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
let _ = event_loop.run(process_event);
|
|
||||||
|
|
||||||
// TODO: Remove when unnecessary
|
|
||||||
// On Windows, we emulate an `AboutToWait` event after every `Resized` event
|
|
||||||
// since the event loop does not resume during resize interaction.
|
|
||||||
// More details: https://github.com/rust-windowing/winit/issues/3272
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
let mut process_event = process_event;
|
|
||||||
|
|
||||||
let _ = event_loop.run(move |event, event_loop| {
|
|
||||||
if matches!(
|
|
||||||
event,
|
|
||||||
winit::event::Event::WindowEvent {
|
|
||||||
event: winit::event::WindowEvent::Resized(_)
|
|
||||||
| winit::event::WindowEvent::Moved(_),
|
|
||||||
..
|
|
||||||
}
|
}
|
||||||
) {
|
|
||||||
process_event(event, event_loop);
|
|
||||||
process_event(winit::event::Event::AboutToWait, event_loop);
|
|
||||||
} else {
|
|
||||||
process_event(event, event_loop);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let _ = event_loop.run_app(&mut runner);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Boot<C> {
|
||||||
|
window: Arc<winit::window::Window>,
|
||||||
|
compositor: C,
|
||||||
|
should_be_visible: bool,
|
||||||
|
exit_on_close_request: bool,
|
||||||
|
}
|
||||||
|
|
||||||
enum Event<Message: 'static> {
|
enum Event<Message: 'static> {
|
||||||
WindowCreated {
|
WindowCreated {
|
||||||
id: window::Id,
|
id: window::Id,
|
||||||
|
|
@ -341,15 +432,13 @@ enum Control {
|
||||||
|
|
||||||
async fn run_instance<A, E, C>(
|
async fn run_instance<A, E, C>(
|
||||||
mut application: A,
|
mut application: A,
|
||||||
mut compositor: C,
|
|
||||||
mut runtime: Runtime<E, Proxy<A::Message>, A::Message>,
|
mut runtime: Runtime<E, Proxy<A::Message>, A::Message>,
|
||||||
mut proxy: Proxy<A::Message>,
|
mut proxy: Proxy<A::Message>,
|
||||||
mut debug: Debug,
|
mut debug: Debug,
|
||||||
|
mut boot: oneshot::Receiver<Boot<C>>,
|
||||||
mut event_receiver: mpsc::UnboundedReceiver<Event<A::Message>>,
|
mut event_receiver: mpsc::UnboundedReceiver<Event<A::Message>>,
|
||||||
mut control_sender: mpsc::UnboundedSender<Control>,
|
mut control_sender: mpsc::UnboundedSender<Control>,
|
||||||
init_command: Command<A::Message>,
|
init_command: Command<A::Message>,
|
||||||
mut window_manager: WindowManager<A, C>,
|
|
||||||
should_main_window_be_visible: bool,
|
|
||||||
) where
|
) where
|
||||||
A: Application + 'static,
|
A: Application + 'static,
|
||||||
E: Executor + 'static,
|
E: Executor + 'static,
|
||||||
|
|
@ -359,11 +448,28 @@ async fn run_instance<A, E, C>(
|
||||||
use winit::event;
|
use winit::event;
|
||||||
use winit::event_loop::ControlFlow;
|
use winit::event_loop::ControlFlow;
|
||||||
|
|
||||||
|
let Boot {
|
||||||
|
window: main_window,
|
||||||
|
mut compositor,
|
||||||
|
should_be_visible,
|
||||||
|
exit_on_close_request,
|
||||||
|
} = boot.try_recv().ok().flatten().expect("Receive boot");
|
||||||
|
|
||||||
|
let mut window_manager = WindowManager::new();
|
||||||
|
|
||||||
|
let _ = window_manager.insert(
|
||||||
|
window::Id::MAIN,
|
||||||
|
main_window.clone(),
|
||||||
|
&application,
|
||||||
|
&mut compositor,
|
||||||
|
exit_on_close_request,
|
||||||
|
);
|
||||||
|
|
||||||
let main_window = window_manager
|
let main_window = window_manager
|
||||||
.get_mut(window::Id::MAIN)
|
.get_mut(window::Id::MAIN)
|
||||||
.expect("Get main window");
|
.expect("Get main window");
|
||||||
|
|
||||||
if should_main_window_be_visible {
|
if should_be_visible {
|
||||||
main_window.raw.set_visible(true);
|
main_window.raw.set_visible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -532,7 +638,7 @@ async fn run_instance<A, E, C>(
|
||||||
debug.draw_finished();
|
debug.draw_finished();
|
||||||
|
|
||||||
if new_mouse_interaction != window.mouse_interaction {
|
if new_mouse_interaction != window.mouse_interaction {
|
||||||
window.raw.set_cursor_icon(
|
window.raw.set_cursor(
|
||||||
conversion::mouse_interaction(
|
conversion::mouse_interaction(
|
||||||
new_mouse_interaction,
|
new_mouse_interaction,
|
||||||
),
|
),
|
||||||
|
|
@ -603,7 +709,7 @@ async fn run_instance<A, E, C>(
|
||||||
|
|
||||||
if new_mouse_interaction != window.mouse_interaction
|
if new_mouse_interaction != window.mouse_interaction
|
||||||
{
|
{
|
||||||
window.raw.set_cursor_icon(
|
window.raw.set_cursor(
|
||||||
conversion::mouse_interaction(
|
conversion::mouse_interaction(
|
||||||
new_mouse_interaction,
|
new_mouse_interaction,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@ use std::sync::Arc;
|
||||||
use winit::monitor::MonitorHandle;
|
use winit::monitor::MonitorHandle;
|
||||||
|
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct WindowManager<A: Application, C: Compositor>
|
pub struct WindowManager<A, C>
|
||||||
where
|
where
|
||||||
|
A: Application,
|
||||||
C: Compositor<Renderer = A::Renderer>,
|
C: Compositor<Renderer = A::Renderer>,
|
||||||
A::Theme: DefaultStyle,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue