From b22b0dd7ff56d433c459e0d14e14eb5472a6224d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 10 Mar 2021 01:16:26 +0100 Subject: Update `window_clipboard` to `0.2` --- winit/src/application.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index d1a94864..6f8cfc22 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -194,7 +194,7 @@ async fn run_instance( use winit::event; let surface = compositor.create_surface(&window); - let clipboard = Clipboard::new(&window); + let clipboard = Clipboard::connect(&window); let mut state = State::new(&application, &window); let mut viewport_version = state.viewport_version(); -- cgit From 21971e0037c2ddcb96fd48ea96332445de4137bb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 10 Mar 2021 01:59:02 +0100 Subject: Make `Clipboard` argument in `Widget` trait mutable --- winit/src/application.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 6f8cfc22..2cb2c016 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -194,7 +194,7 @@ async fn run_instance( use winit::event; let surface = compositor.create_surface(&window); - let clipboard = Clipboard::connect(&window); + let mut clipboard = Clipboard::connect(&window); let mut state = State::new(&application, &window); let mut viewport_version = state.viewport_version(); @@ -237,8 +237,8 @@ async fn run_instance( let statuses = user_interface.update( &events, state.cursor_position(), - clipboard.as_ref().map(|c| c as _), &mut renderer, + &mut clipboard, &mut messages, ); -- cgit From ae517b9fa033ba75df5fc6ce766698fab22504fa Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 11 Mar 2021 03:38:20 +0100 Subject: Add `clipboard` argument to `Application::update` --- winit/src/application.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 2cb2c016..d7d7660e 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -29,7 +29,7 @@ use std::mem::ManuallyDrop; /// /// When using an [`Application`] with the `debug` feature enabled, a debug view /// can be toggled by pressing `F12`. -pub trait Application: Program { +pub trait Application: Program { /// The data needed to initialize your [`Application`]. type Flags; @@ -257,6 +257,7 @@ async fn run_instance( &mut application, &mut runtime, &mut debug, + &mut clipboard, &mut messages, ); @@ -409,13 +410,14 @@ pub fn update( application: &mut A, runtime: &mut Runtime, A::Message>, debug: &mut Debug, + clipboard: &mut A::Clipboard, messages: &mut Vec, ) { for message in messages.drain(..) { debug.log_message(&message); debug.update_started(); - let command = runtime.enter(|| application.update(message)); + let command = runtime.enter(|| application.update(message, clipboard)); debug.update_finished(); runtime.spawn(command); -- cgit From d66a34b27272ed9d6c143483b0a700468b00e311 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 24 Mar 2021 04:59:13 +0100 Subject: Convert `ScaleFactorChanged` into `Resized` events in `iced_winit` ... instead of just dropping them when calling `to_static`. --- winit/src/application.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index d7d7660e..5aefb378 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -164,7 +164,22 @@ where return; } - if let Some(event) = event.to_static() { + let event = match event { + winit::event::Event::WindowEvent { + event: + winit::event::WindowEvent::ScaleFactorChanged { + new_inner_size, + .. + }, + window_id, + } => Some(winit::event::Event::WindowEvent { + event: winit::event::WindowEvent::Resized(*new_inner_size), + window_id, + }), + _ => event.to_static(), + }; + + if let Some(event) = event { sender.start_send(event).expect("Send event"); let poll = instance.as_mut().poll(&mut context); -- cgit From 1207afa7d0862b0fa06b8dd9dd01acb03e49acec Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 26 Mar 2021 14:46:19 +0100 Subject: Skip redrawing if window has no surface --- winit/src/application.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 5aefb378..ef6c8463 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -299,11 +299,16 @@ async fn run_instance( messages.push(message); } event::Event::RedrawRequested(_) => { + let physical_size = state.physical_size(); + + if physical_size.width == 0 || physical_size.height == 0 { + continue; + } + debug.render_started(); let current_viewport_version = state.viewport_version(); if viewport_version != current_viewport_version { - let physical_size = state.physical_size(); let logical_size = state.logical_size(); debug.layout_started(); -- cgit From 67db13ff7c727254182a8c4474bd962b205e2e99 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 30 Mar 2021 21:44:19 +0200 Subject: Add support for graceful exits in `Application` - `Settings` now contains an `exit_on_close_request` field - `Application` has a new `should_exit` method --- winit/src/application.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index ef6c8463..106d5218 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -91,6 +91,13 @@ pub trait Application: Program { fn scale_factor(&self) -> f64 { 1.0 } + + /// Returns whether the [`Application`] should be terminated. + /// + /// By default, it returns `false`. + fn should_exit(&self) -> bool { + false + } } /// Runs an [`Application`] with an executor, compositor, and the provided @@ -149,10 +156,11 @@ where application, compositor, renderer, - window, runtime, debug, receiver, + window, + settings.exit_on_close_request, )); let mut context = task::Context::from_waker(task::noop_waker_ref()); @@ -196,10 +204,11 @@ async fn run_instance( mut application: A, mut compositor: C, mut renderer: A::Renderer, - window: winit::window::Window, mut runtime: Runtime, A::Message>, mut debug: Debug, mut receiver: mpsc::UnboundedReceiver>, + window: winit::window::Window, + exit_on_close_request: bool, ) where A: Application + 'static, E: Executor + 'static, @@ -279,6 +288,8 @@ async fn run_instance( // Update window state.synchronize(&application, &window); + let should_exit = application.should_exit(); + user_interface = ManuallyDrop::new(build_user_interface( &mut application, cache, @@ -286,6 +297,10 @@ async fn run_instance( state.logical_size(), &mut debug, )); + + if should_exit { + break; + } } debug.draw_started(); @@ -358,7 +373,9 @@ async fn run_instance( event: window_event, .. } => { - if requests_exit(&window_event, state.modifiers()) { + if requests_exit(&window_event, state.modifiers()) + && exit_on_close_request + { break; } -- cgit From 3840b75beaa3925f3438a7b40f01aaac221b8206 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Wed, 5 May 2021 14:33:03 +0700 Subject: Provide `compatible_surface` in `iced_wgpu::Compositor` --- winit/src/application.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 106d5218..b1d5f418 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -118,8 +118,6 @@ where let mut debug = Debug::new(); debug.startup_started(); - let (compositor, renderer) = C::new(compositor_settings)?; - let event_loop = EventLoop::with_user_event(); let mut runtime = { @@ -150,6 +148,8 @@ where .build(&event_loop) .map_err(Error::WindowCreationFailed)?; + let (compositor, renderer) = C::new(compositor_settings, Some(&window))?; + let (mut sender, receiver) = mpsc::unbounded(); let mut instance = Box::pin(run_instance::( -- cgit From 9ae22b58d843d9a39212028478598c19a49bc2e6 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 21 Apr 2021 17:52:31 -0300 Subject: Added events for url handling and create example --- winit/src/application.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index b1d5f418..9f51ae68 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -310,6 +310,9 @@ async fn run_instance( window.request_redraw(); } + event::Event::ReceivedUrl(url) => { + events.push(iced_native::Event::UrlReceived(url)); + } event::Event::UserEvent(message) => { messages.push(message); } -- cgit From 96a462d2f2cb608ad14c93cc55896108a2dccb2b Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 9 Jun 2021 15:00:01 -0300 Subject: Use new enum variant and new winit repo --- winit/src/application.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 9f51ae68..ce57bd1d 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -310,8 +310,9 @@ async fn run_instance( window.request_redraw(); } - event::Event::ReceivedUrl(url) => { - events.push(iced_native::Event::UrlReceived(url)); + event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))) => { + use iced_native::event; + events.push(iced_native::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url)))); } event::Event::UserEvent(message) => { messages.push(message); -- cgit From 612585109ffc9a14a507c3c8423c6aa790c35cbf Mon Sep 17 00:00:00 2001 From: Richard Date: Mon, 14 Jun 2021 17:21:55 -0300 Subject: Use `winit` and `glutin` forks in `iced-rs` org --- winit/src/application.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index ce57bd1d..49f2f513 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -310,9 +310,15 @@ async fn run_instance( window.request_redraw(); } - event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))) => { + event::Event::PlatformSpecific(event::PlatformSpecific::MacOS( + event::MacOS::ReceivedUrl(url), + )) => { use iced_native::event; - events.push(iced_native::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url)))); + events.push(iced_native::Event::PlatformSpecific( + event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl( + url, + )), + )); } event::Event::UserEvent(message) => { messages.push(message); -- cgit From 9fc5ad23edca93553137100d167de7b69e88f785 Mon Sep 17 00:00:00 2001 From: Richard Date: Mon, 5 Jul 2021 16:23:44 -0300 Subject: Initial menu implementation --- winit/src/application.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 49f2f513..108c6d64 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -14,6 +14,7 @@ use iced_futures::futures; use iced_futures::futures::channel::mpsc; use iced_graphics::window; use iced_native::program::Program; +use iced_native::Menu; use iced_native::{Cache, UserInterface}; use std::mem::ManuallyDrop; @@ -98,6 +99,11 @@ pub trait Application: Program { fn should_exit(&self) -> bool { false } + + /// TODO + fn menu(&self) -> Menu { + Menu::new() + } } /// Runs an [`Application`] with an executor, compositor, and the provided -- cgit From 31997d255f263a0f47f5af0d8560f3d5bd37f077 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 12 Jul 2021 22:28:18 +0200 Subject: Store and synchronize `Menu` in `application::State` --- winit/src/application.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 108c6d64..bf4b2489 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -151,6 +151,7 @@ where application.mode(), event_loop.primary_monitor(), ) + .with_menu(Some(conversion::menu(&application.menu()))) .build(&event_loop) .map_err(Error::WindowCreationFailed)?; -- cgit From 6221adf2b1b1e8150931d4175e1e36870d45f6e5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 13 Jul 2021 20:55:21 +0200 Subject: Draft `conversion::menu_message` in `iced_winit` ... and wire it up to the runtime loop --- winit/src/application.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index bf4b2489..ada64dfc 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -386,6 +386,16 @@ async fn run_instance( // TODO: Handle animations! // Maybe we can use `ControlFlow::WaitUntil` for this. } + event::Event::WindowEvent { + event: event::WindowEvent::MenuEntryActivated(entry_id), + .. + } => { + if let Some(message) = + conversion::menu_message(state.menu(), entry_id) + { + messages.push(message); + } + } event::Event::WindowEvent { event: window_event, .. -- cgit From c8ac77e4e99414746adedf38cf69ac8dcd1601a4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 19 Jul 2021 21:05:16 +0700 Subject: Write documentation for `menu` method in `Application` --- winit/src/application.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index ada64dfc..5d1aabf9 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -100,7 +100,9 @@ pub trait Application: Program { false } - /// TODO + /// Returns the current system [`Menu`] of the [`Application`]. + /// + /// By default, it returns an empty [`Menu`]. fn menu(&self) -> Menu { Menu::new() } -- cgit