From d53ccc857da4d4cda769904342aeb5a82a64f146 Mon Sep 17 00:00:00 2001 From: Bingus Date: Wed, 12 Jul 2023 19:21:05 -0700 Subject: refactored window storage; new helper window events (Destroyed, Created); clippy + fmt; --- examples/integration/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/integration/src/main.rs') diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index a560959a..90beb097 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -6,8 +6,8 @@ use scene::Scene; use iced_wgpu::graphics::Viewport; use iced_wgpu::{wgpu, Backend, Renderer, Settings}; -use iced_winit::core::mouse; use iced_winit::core::renderer; +use iced_winit::core::{mouse, window}; use iced_winit::core::{Color, Size}; use iced_winit::runtime::program; use iced_winit::runtime::Debug; -- cgit From 781ef1f94c4859aeeb852f801b72be095b8ff82b Mon Sep 17 00:00:00 2001 From: Bingus Date: Thu, 14 Sep 2023 13:58:36 -0700 Subject: Added support for custom shader widget for iced_wgpu backend. --- examples/integration/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/integration/src/main.rs') diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index c26d52fe..0f32fca0 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -271,6 +271,7 @@ pub fn main() -> Result<(), Box> { &queue, &mut encoder, None, + frame.texture.format(), &view, primitive, &viewport, -- cgit From e819c2390bad76e811265245bd5fab63fc30a8b2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 15 Dec 2023 13:15:44 +0100 Subject: Update `winit` to `0.29.4` --- examples/integration/src/main.rs | 124 ++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 61 deletions(-) (limited to 'examples/integration/src/main.rs') diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 276794c8..fab81553 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -19,8 +19,9 @@ use iced_winit::winit; use iced_winit::Clipboard; use winit::{ - event::{Event, ModifiersState, WindowEvent}, + event::{Event, WindowEvent}, event_loop::{ControlFlow, EventLoop}, + keyboard::ModifiersState, }; #[cfg(target_arch = "wasm32")] @@ -48,7 +49,7 @@ pub fn main() -> Result<(), Box> { tracing_subscriber::fmt::init(); // Initialize winit - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; #[cfg(target_arch = "wasm32")] let window = winit::window::WindowBuilder::new() @@ -160,67 +161,15 @@ pub fn main() -> Result<(), Box> { ); // Run event loop - event_loop.run(move |event, _, control_flow| { + event_loop.run(move |event, window_target| { // You should change this if you want to render continuosly - *control_flow = ControlFlow::Wait; + window_target.set_control_flow(ControlFlow::Wait); match event { - Event::WindowEvent { event, .. } => { - match event { - WindowEvent::CursorMoved { position, .. } => { - cursor_position = Some(position); - } - WindowEvent::ModifiersChanged(new_modifiers) => { - modifiers = new_modifiers; - } - WindowEvent::Resized(_) => { - resized = true; - } - WindowEvent::CloseRequested => { - *control_flow = ControlFlow::Exit; - } - _ => {} - } - - // Map window event to iced event - if let Some(event) = iced_winit::conversion::window_event( - window::Id::MAIN, - &event, - window.scale_factor(), - modifiers, - ) { - state.queue_event(event); - } - } - Event::MainEventsCleared => { - // If there are events pending - if !state.is_queue_empty() { - // We update iced - let _ = state.update( - viewport.logical_size(), - cursor_position - .map(|p| { - conversion::cursor_position( - p, - viewport.scale_factor(), - ) - }) - .map(mouse::Cursor::Available) - .unwrap_or(mouse::Cursor::Unavailable), - &mut renderer, - &Theme::Dark, - &renderer::Style { - text_color: Color::WHITE, - }, - &mut clipboard, - &mut debug, - ); - - // and request a redraw - window.request_redraw(); - } - } - Event::RedrawRequested(_) => { + Event::WindowEvent { + event: WindowEvent::RedrawRequested, + .. + } => { if resized { let size = window.inner_size(); @@ -309,7 +258,60 @@ pub fn main() -> Result<(), Box> { }, } } + Event::WindowEvent { event, .. } => { + match event { + WindowEvent::CursorMoved { position, .. } => { + cursor_position = Some(position); + } + WindowEvent::ModifiersChanged(new_modifiers) => { + modifiers = new_modifiers.state(); + } + WindowEvent::Resized(_) => { + resized = true; + } + WindowEvent::CloseRequested => { + window_target.exit(); + } + _ => {} + } + + // Map window event to iced event + if let Some(event) = iced_winit::conversion::window_event( + window::Id::MAIN, + &event, + window.scale_factor(), + modifiers, + ) { + state.queue_event(event); + } + } _ => {} } - }) + + // If there are events pending + if !state.is_queue_empty() { + // We update iced + let _ = state.update( + viewport.logical_size(), + cursor_position + .map(|p| { + conversion::cursor_position(p, viewport.scale_factor()) + }) + .map(mouse::Cursor::Available) + .unwrap_or(mouse::Cursor::Unavailable), + &mut renderer, + &Theme::Dark, + &renderer::Style { + text_color: Color::WHITE, + }, + &mut clipboard, + &mut debug, + ); + + // and request a redraw + window.request_redraw(); + } + })?; + + Ok(()) } -- cgit From 64d1ce5532f55d152fa5819532a138da2dca1a39 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 16 Jan 2024 13:28:00 +0100 Subject: Refactor `KeyCode` into `Key` and `Location` --- examples/integration/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/integration/src/main.rs') diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index fab81553..b0939d68 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -278,7 +278,7 @@ pub fn main() -> Result<(), Box> { // Map window event to iced event if let Some(event) = iced_winit::conversion::window_event( window::Id::MAIN, - &event, + event, window.scale_factor(), modifiers, ) { -- cgit From 8bf238697226e827dc983f9d89afbd0e252c5254 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 18 Jan 2024 09:55:27 +0100 Subject: Remove `Compositor` window generic And update `glyphon` and `window_clipboard` --- examples/integration/src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'examples/integration/src/main.rs') diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index b0939d68..ed61459f 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -24,6 +24,8 @@ use winit::{ keyboard::ModifiersState, }; +use std::sync::Arc; + #[cfg(target_arch = "wasm32")] use wasm_bindgen::JsCast; #[cfg(target_arch = "wasm32")] @@ -59,6 +61,8 @@ pub fn main() -> Result<(), Box> { #[cfg(not(target_arch = "wasm32"))] let window = winit::window::Window::new(&event_loop)?; + let window = Arc::new(window); + let physical_size = window.inner_size(); let mut viewport = Viewport::with_physical_size( Size::new(physical_size.width, physical_size.height), @@ -81,7 +85,7 @@ pub fn main() -> Result<(), Box> { backends: backend, ..Default::default() }); - let surface = unsafe { instance.create_surface(&window) }?; + let surface = instance.create_surface(window.clone())?; let (format, (device, queue)) = futures::futures::executor::block_on(async { @@ -115,9 +119,9 @@ pub fn main() -> Result<(), Box> { .request_device( &wgpu::DeviceDescriptor { label: None, - features: adapter_features + required_features: adapter_features & wgpu::Features::default(), - limits: needed_limits, + required_limits: needed_limits, }, None, ) @@ -136,6 +140,7 @@ pub fn main() -> Result<(), Box> { present_mode: wgpu::PresentMode::AutoVsync, alpha_mode: wgpu::CompositeAlphaMode::Auto, view_formats: vec![], + desired_maximum_frame_latency: 2, }, ); @@ -188,6 +193,7 @@ pub fn main() -> Result<(), Box> { present_mode: wgpu::PresentMode::AutoVsync, alpha_mode: wgpu::CompositeAlphaMode::Auto, view_formats: vec![], + desired_maximum_frame_latency: 2, }, ); -- cgit