From 238154af4ac8dda7f12dd90aa7be106e933bcb30 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Feb 2023 11:12:15 +0100 Subject: Implement `font::load` command in `iced_native` --- winit/src/application.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 9781a453..889becad 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -851,6 +851,16 @@ pub fn run_command( current_cache = user_interface.into_cache(); *cache = current_cache; } + command::Action::LoadFont { bytes, tagger } => { + use crate::text::Renderer; + + // TODO: Error handling (?) + renderer.load_font(bytes); + + proxy + .send_event(tagger(Ok(()))) + .expect("Send message to event loop"); + } } } } -- cgit From a0597471b81b122b43e1bb90e43e1bcde1e8a892 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 10 Feb 2023 20:24:18 +0100 Subject: Remove `iced_glutin` and `iced_glow` leftovers --- winit/src/settings.rs | 8 -------- 1 file changed, 8 deletions(-) (limited to 'winit/src') diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 78d58000..5c64727b 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -51,14 +51,6 @@ pub struct Settings { /// /// [`Application`]: crate::Application pub exit_on_close_request: bool, - - /// Whether the [`Application`] should try to build the context - /// using OpenGL ES first then OpenGL. - /// - /// NOTE: Only works for the `glow` backend. - /// - /// [`Application`]: crate::Application - pub try_opengles_first: bool, } /// The window settings of an application. -- cgit From 5100b5d0a1f654ec1254b7765ceadfb9091d6939 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 24 Feb 2023 23:24:48 +0100 Subject: Introduce `iced_renderer` subcrate featuring runtime renderer fallback --- winit/src/application.rs | 2 +- winit/src/system.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 889becad..1bfce3a1 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -17,8 +17,8 @@ use crate::{ use iced_futures::futures; use iced_futures::futures::channel::mpsc; -use iced_graphics::compositor; use iced_graphics::window; +use iced_graphics::window::compositor; use iced_native::program::Program; use iced_native::time::Instant; use iced_native::user_interface::{self, UserInterface}; diff --git a/winit/src/system.rs b/winit/src/system.rs index 619086b8..8a7b2a11 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -2,7 +2,7 @@ use crate::command::{self, Command}; pub use iced_native::system::*; -use iced_graphics::compositor; +use iced_graphics::window::compositor; /// Query for available system information. pub fn fetch_information( -- cgit From 535d7a4d57e131e661587b36e41820dd6ccccc3e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 25 Feb 2023 16:05:42 +0100 Subject: Implement basic presentation with `softbuffer` for `iced_tiny_skia` --- winit/src/application.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 1bfce3a1..b52f0197 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -285,21 +285,18 @@ async fn run_instance( use winit::event; use winit::event_loop::ControlFlow; - let mut clipboard = Clipboard::connect(&window); - let mut cache = user_interface::Cache::default(); - let mut surface = compositor.create_surface(&window); - let mut should_exit = false; - let mut state = State::new(&application, &window); let mut viewport_version = state.viewport_version(); - let physical_size = state.physical_size(); - compositor.configure_surface( - &mut surface, + let mut clipboard = Clipboard::connect(&window); + let mut cache = user_interface::Cache::default(); + let mut surface = compositor.create_surface( + &window, physical_size.width, physical_size.height, ); + let mut should_exit = false; if should_be_visible { window.set_visible(true); -- cgit From 3a0d34c0240f4421737a6a08761f99d6f8140d02 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Mar 2023 05:37:11 +0100 Subject: Create `iced_widget` subcrate and re-organize the whole codebase --- winit/src/application.rs | 77 ++++++++++++++++++++---------------------- winit/src/application/state.rs | 14 +++++--- winit/src/clipboard.rs | 7 ++-- winit/src/conversion.rs | 11 +++--- winit/src/error.rs | 7 ++-- winit/src/lib.rs | 8 +++-- winit/src/proxy.rs | 2 +- winit/src/system.rs | 7 ++-- winit/src/window.rs | 52 +++++++++++----------------- 9 files changed, 87 insertions(+), 98 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index b52f0197..c8162c9b 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -5,25 +5,25 @@ mod state; pub use state::State; -use crate::clipboard::{self, Clipboard}; use crate::conversion; -use crate::mouse; -use crate::renderer; -use crate::widget::operation; -use crate::{ - Command, Debug, Error, Event, Executor, Proxy, Runtime, Settings, Size, - Subscription, -}; - -use iced_futures::futures; -use iced_futures::futures::channel::mpsc; -use iced_graphics::window; -use iced_graphics::window::compositor; -use iced_native::program::Program; -use iced_native::time::Instant; -use iced_native::user_interface::{self, UserInterface}; - -pub use iced_native::application::{Appearance, StyleSheet}; +use crate::core; +use crate::core::mouse; +use crate::core::renderer; +use crate::core::time::Instant; +use crate::core::widget::operation; +use crate::core::window; +use crate::core::{Event, Size}; +use crate::futures::futures; +use crate::futures::Executor; +use crate::graphics::compositor::{self, Compositor}; +use crate::native::clipboard; +use crate::native::program::Program; +use crate::native::user_interface::{self, UserInterface}; +use crate::native::{Command, Debug, Runtime, Subscription}; +use crate::style::application::{Appearance, StyleSheet}; +use crate::{Clipboard, Error, Proxy, Settings}; + +use futures::channel::mpsc; use std::mem::ManuallyDrop; @@ -45,7 +45,7 @@ use tracing::{info_span, instrument::Instrument}; /// can be toggled by pressing `F12`. pub trait Application: Program where - ::Theme: StyleSheet, + ::Theme: StyleSheet, { /// The data needed to initialize your [`Application`]. type Flags; @@ -67,12 +67,12 @@ where fn title(&self) -> String; /// Returns the current `Theme` of the [`Application`]. - fn theme(&self) -> ::Theme; + fn theme(&self) -> ::Theme; /// Returns the `Style` variation of the `Theme`. fn style( &self, - ) -> <::Theme as StyleSheet>::Style { + ) -> <::Theme as StyleSheet>::Style { Default::default() } @@ -112,8 +112,8 @@ pub fn run( where A: Application + 'static, E: Executor + 'static, - C: window::Compositor + 'static, - ::Theme: StyleSheet, + C: Compositor + 'static, + ::Theme: StyleSheet, { use futures::task; use futures::Future; @@ -278,10 +278,10 @@ async fn run_instance( ) where A: Application + 'static, E: Executor + 'static, - C: window::Compositor + 'static, - ::Theme: StyleSheet, + C: Compositor + 'static, + ::Theme: StyleSheet, { - use iced_futures::futures::stream::StreamExt; + use futures::stream::StreamExt; use winit::event; use winit::event_loop::ControlFlow; @@ -411,7 +411,7 @@ async fn run_instance( // Then, we can use the `interface_state` here to decide if a redraw // is needed right away, or simply wait until a specific time. let redraw_event = Event::Window( - crate::window::Event::RedrawRequested(Instant::now()), + window::Event::RedrawRequested(Instant::now()), ); let (interface_state, _) = user_interface.update( @@ -442,17 +442,14 @@ async fn run_instance( } window.request_redraw(); - runtime - .broadcast((redraw_event, crate::event::Status::Ignored)); + runtime.broadcast((redraw_event, core::event::Status::Ignored)); let _ = control_sender.start_send(match interface_state { user_interface::State::Updated { redraw_request: Some(redraw_request), } => match redraw_request { - crate::window::RedrawRequest::NextFrame => { - ControlFlow::Poll - } - crate::window::RedrawRequest::At(at) => { + window::RedrawRequest::NextFrame => ControlFlow::Poll, + window::RedrawRequest::At(at) => { ControlFlow::WaitUntil(at) } }, @@ -464,9 +461,9 @@ async fn run_instance( event::Event::PlatformSpecific(event::PlatformSpecific::MacOS( event::MacOS::ReceivedUrl(url), )) => { - use iced_native::event; + use crate::core::event; - events.push(iced_native::Event::PlatformSpecific( + events.push(Event::PlatformSpecific( event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl( url, )), @@ -615,7 +612,7 @@ pub fn build_user_interface<'a, A: Application>( debug: &mut Debug, ) -> UserInterface<'a, A::Message, A::Renderer> where - ::Theme: StyleSheet, + ::Theme: StyleSheet, { #[cfg(feature = "trace")] let view_span = info_span!("Application", "VIEW").entered(); @@ -656,7 +653,7 @@ pub fn update( window: &winit::window::Window, graphics_info: impl FnOnce() -> compositor::Information + Copy, ) where - ::Theme: StyleSheet, + ::Theme: StyleSheet, { for message in messages.drain(..) { #[cfg(feature = "trace")] @@ -708,7 +705,7 @@ pub fn run_command( ) where A: Application, E: Executor, - ::Theme: StyleSheet, + ::Theme: StyleSheet, { use iced_native::command; use iced_native::system; @@ -767,7 +764,7 @@ pub fn run_command( let mode = if window.is_visible().unwrap_or(true) { conversion::mode(window.fullscreen()) } else { - window::Mode::Hidden + core::window::Mode::Hidden }; proxy @@ -849,7 +846,7 @@ pub fn run_command( *cache = current_cache; } command::Action::LoadFont { bytes, tagger } => { - use crate::text::Renderer; + use crate::core::text::Renderer; // TODO: Error handling (?) renderer.load_font(bytes); diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs index 8d6a1df1..b727e03c 100644 --- a/winit/src/application/state.rs +++ b/winit/src/application/state.rs @@ -1,6 +1,10 @@ use crate::application::{self, StyleSheet as _}; use crate::conversion; -use crate::{Application, Color, Debug, Point, Size, Viewport}; +use crate::core; +use crate::core::{Color, Point, Size}; +use crate::graphics::Viewport; +use crate::native::Debug; +use crate::Application; use std::marker::PhantomData; use winit::event::{Touch, WindowEvent}; @@ -10,7 +14,7 @@ use winit::window::Window; #[allow(missing_debug_implementations)] pub struct State where - ::Theme: application::StyleSheet, + ::Theme: application::StyleSheet, { title: String, scale_factor: f64, @@ -18,14 +22,14 @@ where viewport_version: usize, cursor_position: winit::dpi::PhysicalPosition, modifiers: winit::event::ModifiersState, - theme: ::Theme, + theme: ::Theme, appearance: application::Appearance, application: PhantomData, } impl State where - ::Theme: application::StyleSheet, + ::Theme: application::StyleSheet, { /// Creates a new [`State`] for the provided [`Application`] and window. pub fn new(application: &A, window: &Window) -> Self { @@ -98,7 +102,7 @@ where } /// Returns the current theme of the [`State`]. - pub fn theme(&self) -> &::Theme { + pub fn theme(&self) -> &::Theme { &self.theme } diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index c1fd8813..22509130 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -1,7 +1,6 @@ //! Access the clipboard. -pub use iced_native::clipboard::Action; - -use crate::command::{self, Command}; +use crate::native::clipboard::Action; +use crate::native::command::{self, Command}; /// A buffer for short-term storage and transfer within and between /// applications. @@ -56,7 +55,7 @@ impl Clipboard { } } -impl iced_native::Clipboard for Clipboard { +impl crate::core::Clipboard for Clipboard { fn read(&self) -> Option { self.read() } diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 1b2ead36..0759ad9d 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -2,11 +2,12 @@ //! //! [`winit`]: https://github.com/rust-windowing/winit //! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native -use crate::keyboard; -use crate::mouse; -use crate::touch; -use crate::window; -use crate::{Event, Point, Position}; +use crate::core::keyboard; +use crate::core::mouse; +use crate::core::touch; +use crate::core::window; +use crate::core::{Event, Point}; +use crate::Position; /// Converts a winit window event into an iced event. pub fn window_event( diff --git a/winit/src/error.rs b/winit/src/error.rs index eaeafd51..7687fb17 100644 --- a/winit/src/error.rs +++ b/winit/src/error.rs @@ -1,4 +1,5 @@ -use iced_futures::futures; +use crate::futures::futures; +use crate::graphics; /// An error that occurred while running an application. #[derive(Debug, thiserror::Error)] @@ -13,10 +14,10 @@ pub enum Error { /// The application graphics context could not be created. #[error("the application graphics context could not be created")] - GraphicsCreationFailed(iced_graphics::Error), + GraphicsCreationFailed(graphics::Error), } -impl From for Error { +impl From for Error { fn from(error: iced_graphics::Error) -> Error { Error::GraphicsCreationFailed(error) } diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 3a33e174..0d8c04d3 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -30,9 +30,11 @@ #![forbid(rust_2018_idioms, unsafe_code)] #![allow(clippy::inherent_to_string, clippy::type_complexity)] #![cfg_attr(docsrs, feature(doc_cfg))] - -#[doc(no_inline)] -pub use iced_native::*; +pub use iced_graphics as graphics; +pub use iced_native as native; +pub use iced_native::core; +pub use iced_native::futures; +pub use iced_style as style; pub use winit; #[cfg(feature = "application")] diff --git a/winit/src/proxy.rs b/winit/src/proxy.rs index 7b9074d7..1d6c48bb 100644 --- a/winit/src/proxy.rs +++ b/winit/src/proxy.rs @@ -1,4 +1,4 @@ -use iced_native::futures::{ +use crate::futures::futures::{ channel::mpsc, task::{Context, Poll}, Sink, diff --git a/winit/src/system.rs b/winit/src/system.rs index 8a7b2a11..3a6a8a8e 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -1,8 +1,7 @@ //! Access the native system. -use crate::command::{self, Command}; -pub use iced_native::system::*; - -use iced_graphics::window::compositor; +use crate::graphics::compositor; +use crate::native::command::{self, Command}; +use crate::native::system::{Action, Information}; /// Query for available system information. pub fn fetch_information( diff --git a/winit/src/window.rs b/winit/src/window.rs index 961562bd..6ac58e20 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -1,68 +1,58 @@ //! Interact with the window of your application. -use crate::command::{self, Command}; -use iced_native::window; - -pub use window::{frames, Event, Mode, RedrawRequest, UserAttention}; +use crate::core::window::{Mode, UserAttention}; +use crate::native::command::{self, Command}; +use crate::native::window::Action; /// Closes the current window and exits the application. pub fn close() -> Command { - Command::single(command::Action::Window(window::Action::Close)) + Command::single(command::Action::Window(Action::Close)) } /// Begins dragging the window while the left mouse button is held. pub fn drag() -> Command { - Command::single(command::Action::Window(window::Action::Drag)) + Command::single(command::Action::Window(Action::Drag)) } /// Resizes the window to the given logical dimensions. pub fn resize(width: u32, height: u32) -> Command { - Command::single(command::Action::Window(window::Action::Resize { - width, - height, - })) + Command::single(command::Action::Window(Action::Resize { width, height })) } /// Maximizes the window. pub fn maximize(maximized: bool) -> Command { - Command::single(command::Action::Window(window::Action::Maximize( - maximized, - ))) + Command::single(command::Action::Window(Action::Maximize(maximized))) } /// Minimes the window. pub fn minimize(minimized: bool) -> Command { - Command::single(command::Action::Window(window::Action::Minimize( - minimized, - ))) + Command::single(command::Action::Window(Action::Minimize(minimized))) } /// Moves a window to the given logical coordinates. pub fn move_to(x: i32, y: i32) -> Command { - Command::single(command::Action::Window(window::Action::Move { x, y })) + Command::single(command::Action::Window(Action::Move { x, y })) } /// Sets the [`Mode`] of the window. pub fn change_mode(mode: Mode) -> Command { - Command::single(command::Action::Window(window::Action::ChangeMode(mode))) + Command::single(command::Action::Window(Action::ChangeMode(mode))) } /// Fetches the current [`Mode`] of the window. pub fn fetch_mode( f: impl FnOnce(Mode) -> Message + 'static, ) -> Command { - Command::single(command::Action::Window(window::Action::FetchMode( - Box::new(f), - ))) + Command::single(command::Action::Window(Action::FetchMode(Box::new(f)))) } /// Toggles the window to maximized or back. pub fn toggle_maximize() -> Command { - Command::single(command::Action::Window(window::Action::ToggleMaximize)) + Command::single(command::Action::Window(Action::ToggleMaximize)) } /// Toggles the window decorations. pub fn toggle_decorations() -> Command { - Command::single(command::Action::Window(window::Action::ToggleDecorations)) + Command::single(command::Action::Window(Action::ToggleDecorations)) } /// Request user attention to the window, this has no effect if the application @@ -74,9 +64,9 @@ pub fn toggle_decorations() -> Command { pub fn request_user_attention( user_attention: Option, ) -> Command { - Command::single(command::Action::Window( - window::Action::RequestUserAttention(user_attention), - )) + Command::single(command::Action::Window(Action::RequestUserAttention( + user_attention, + ))) } /// Brings the window to the front and sets input focus. Has no effect if the window is @@ -86,21 +76,17 @@ pub fn request_user_attention( /// you are certain that's what the user wants. Focus stealing can cause an extremely disruptive /// user experience. pub fn gain_focus() -> Command { - Command::single(command::Action::Window(window::Action::GainFocus)) + Command::single(command::Action::Window(Action::GainFocus)) } /// Changes whether or not the window will always be on top of other windows. pub fn change_always_on_top(on_top: bool) -> Command { - Command::single(command::Action::Window(window::Action::ChangeAlwaysOnTop( - on_top, - ))) + Command::single(command::Action::Window(Action::ChangeAlwaysOnTop(on_top))) } /// Fetches an identifier unique to the window. pub fn fetch_id( f: impl FnOnce(u64) -> Message + 'static, ) -> Command { - Command::single(command::Action::Window(window::Action::FetchId(Box::new( - f, - )))) + Command::single(command::Action::Window(Action::FetchId(Box::new(f)))) } -- cgit From f4cf488e0b083b5d7b7612c650917233163ee9cb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Mar 2023 04:15:10 +0100 Subject: Remove generic `Hasher` and `Event` from `subscription::Recipe` --- winit/src/application.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index c8162c9b..c95dbf62 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -14,12 +14,12 @@ use crate::core::widget::operation; use crate::core::window; use crate::core::{Event, Size}; use crate::futures::futures; -use crate::futures::Executor; +use crate::futures::{Executor, Runtime, Subscription}; use crate::graphics::compositor::{self, Compositor}; use crate::native::clipboard; use crate::native::program::Program; use crate::native::user_interface::{self, UserInterface}; -use crate::native::{Command, Debug, Runtime, Subscription}; +use crate::native::{Command, Debug}; use crate::style::application::{Appearance, StyleSheet}; use crate::{Clipboard, Error, Proxy, Settings}; @@ -316,7 +316,7 @@ async fn run_instance( &window, || compositor.fetch_information(), ); - runtime.track(application.subscription()); + runtime.track(application.subscription().into_recipes()); let mut user_interface = ManuallyDrop::new(build_user_interface( &application, @@ -360,8 +360,10 @@ async fn run_instance( debug.event_processing_finished(); - for event in events.drain(..).zip(statuses.into_iter()) { - runtime.broadcast(event); + for (event, status) in + events.drain(..).zip(statuses.into_iter()) + { + runtime.broadcast(event, status); } if !messages.is_empty() @@ -442,7 +444,7 @@ async fn run_instance( } window.request_redraw(); - runtime.broadcast((redraw_event, core::event::Status::Ignored)); + runtime.broadcast(redraw_event, core::event::Status::Ignored); let _ = control_sender.start_send(match interface_state { user_interface::State::Updated { @@ -685,7 +687,7 @@ pub fn update( } let subscription = application.subscription(); - runtime.track(subscription); + runtime.track(subscription.into_recipes()); } /// Runs the actions of a [`Command`]. -- cgit From 8af69be47e88896b3c5f70174db609eee0c67971 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Mar 2023 06:23:40 +0100 Subject: Converge `Command` types from `iced_futures` and `iced_native` --- winit/src/application.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index c95dbf62..d863c846 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -818,7 +818,7 @@ pub fn run_command( }, command::Action::Widget(action) => { let mut current_cache = std::mem::take(cache); - let mut current_operation = Some(action.into_operation()); + let mut current_operation = Some(action); let mut user_interface = build_user_interface( application, -- cgit From 99e0a71504456976ba88040f5d1d3bbc347694ea Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Mar 2023 06:35:20 +0100 Subject: Rename `iced_native` to `iced_runtime` --- winit/src/application.rs | 14 +++---- winit/src/application/state.rs | 2 +- winit/src/clipboard.rs | 14 ------- winit/src/lib.rs | 7 ++-- winit/src/system.rs | 4 +- winit/src/window.rs | 92 ------------------------------------------ 6 files changed, 13 insertions(+), 120 deletions(-) delete mode 100644 winit/src/window.rs (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index d863c846..9666fcae 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -16,10 +16,10 @@ use crate::core::{Event, Size}; use crate::futures::futures; use crate::futures::{Executor, Runtime, Subscription}; use crate::graphics::compositor::{self, Compositor}; -use crate::native::clipboard; -use crate::native::program::Program; -use crate::native::user_interface::{self, UserInterface}; -use crate::native::{Command, Debug}; +use crate::runtime::clipboard; +use crate::runtime::program::Program; +use crate::runtime::user_interface::{self, UserInterface}; +use crate::runtime::{Command, Debug}; use crate::style::application::{Appearance, StyleSheet}; use crate::{Clipboard, Error, Proxy, Settings}; @@ -709,9 +709,9 @@ pub fn run_command( E: Executor, ::Theme: StyleSheet, { - use iced_native::command; - use iced_native::system; - use iced_native::window; + use crate::runtime::command; + use crate::runtime::system; + use crate::runtime::window; for action in command.actions() { match action { diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs index b727e03c..c37ccca6 100644 --- a/winit/src/application/state.rs +++ b/winit/src/application/state.rs @@ -3,7 +3,7 @@ use crate::conversion; use crate::core; use crate::core::{Color, Point, Size}; use crate::graphics::Viewport; -use crate::native::Debug; +use crate::runtime::Debug; use crate::Application; use std::marker::PhantomData; diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index 22509130..7271441d 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -1,6 +1,4 @@ //! Access the clipboard. -use crate::native::clipboard::Action; -use crate::native::command::{self, Command}; /// A buffer for short-term storage and transfer within and between /// applications. @@ -64,15 +62,3 @@ impl crate::core::Clipboard for Clipboard { self.write(contents) } } - -/// Read the current contents of the clipboard. -pub fn read( - f: impl Fn(Option) -> Message + 'static, -) -> Command { - Command::single(command::Action::Clipboard(Action::Read(Box::new(f)))) -} - -/// Write the given contents to the clipboard. -pub fn write(contents: String) -> Command { - Command::single(command::Action::Clipboard(Action::Write(contents))) -} diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 0d8c04d3..5cde510a 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -31,9 +31,9 @@ #![allow(clippy::inherent_to_string, clippy::type_complexity)] #![cfg_attr(docsrs, feature(doc_cfg))] pub use iced_graphics as graphics; -pub use iced_native as native; -pub use iced_native::core; -pub use iced_native::futures; +pub use iced_runtime as runtime; +pub use iced_runtime::core; +pub use iced_runtime::futures; pub use iced_style as style; pub use winit; @@ -42,7 +42,6 @@ pub mod application; pub mod clipboard; pub mod conversion; pub mod settings; -pub mod window; #[cfg(feature = "system")] pub mod system; diff --git a/winit/src/system.rs b/winit/src/system.rs index 3a6a8a8e..069efa29 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -1,7 +1,7 @@ //! Access the native system. use crate::graphics::compositor; -use crate::native::command::{self, Command}; -use crate::native::system::{Action, Information}; +use crate::runtime::command::{self, Command}; +use crate::runtime::system::{Action, Information}; /// Query for available system information. pub fn fetch_information( diff --git a/winit/src/window.rs b/winit/src/window.rs deleted file mode 100644 index 6ac58e20..00000000 --- a/winit/src/window.rs +++ /dev/null @@ -1,92 +0,0 @@ -//! Interact with the window of your application. -use crate::core::window::{Mode, UserAttention}; -use crate::native::command::{self, Command}; -use crate::native::window::Action; - -/// Closes the current window and exits the application. -pub fn close() -> Command { - Command::single(command::Action::Window(Action::Close)) -} - -/// Begins dragging the window while the left mouse button is held. -pub fn drag() -> Command { - Command::single(command::Action::Window(Action::Drag)) -} - -/// Resizes the window to the given logical dimensions. -pub fn resize(width: u32, height: u32) -> Command { - Command::single(command::Action::Window(Action::Resize { width, height })) -} - -/// Maximizes the window. -pub fn maximize(maximized: bool) -> Command { - Command::single(command::Action::Window(Action::Maximize(maximized))) -} - -/// Minimes the window. -pub fn minimize(minimized: bool) -> Command { - Command::single(command::Action::Window(Action::Minimize(minimized))) -} - -/// Moves a window to the given logical coordinates. -pub fn move_to(x: i32, y: i32) -> Command { - Command::single(command::Action::Window(Action::Move { x, y })) -} - -/// Sets the [`Mode`] of the window. -pub fn change_mode(mode: Mode) -> Command { - Command::single(command::Action::Window(Action::ChangeMode(mode))) -} - -/// Fetches the current [`Mode`] of the window. -pub fn fetch_mode( - f: impl FnOnce(Mode) -> Message + 'static, -) -> Command { - Command::single(command::Action::Window(Action::FetchMode(Box::new(f)))) -} - -/// Toggles the window to maximized or back. -pub fn toggle_maximize() -> Command { - Command::single(command::Action::Window(Action::ToggleMaximize)) -} - -/// Toggles the window decorations. -pub fn toggle_decorations() -> Command { - Command::single(command::Action::Window(Action::ToggleDecorations)) -} - -/// Request user attention to the window, this has no effect if the application -/// is already focused. How requesting for user attention manifests is platform dependent, -/// see [`UserAttention`] for details. -/// -/// Providing `None` will unset the request for user attention. Unsetting the request for -/// user attention might not be done automatically by the WM when the window receives input. -pub fn request_user_attention( - user_attention: Option, -) -> Command { - Command::single(command::Action::Window(Action::RequestUserAttention( - user_attention, - ))) -} - -/// Brings the window to the front and sets input focus. Has no effect if the window is -/// already in focus, minimized, or not visible. -/// -/// This [`Command`] steals input focus from other applications. Do not use this method unless -/// you are certain that's what the user wants. Focus stealing can cause an extremely disruptive -/// user experience. -pub fn gain_focus() -> Command { - Command::single(command::Action::Window(Action::GainFocus)) -} - -/// Changes whether or not the window will always be on top of other windows. -pub fn change_always_on_top(on_top: bool) -> Command { - Command::single(command::Action::Window(Action::ChangeAlwaysOnTop(on_top))) -} - -/// Fetches an identifier unique to the window. -pub fn fetch_id( - f: impl FnOnce(u64) -> Message + 'static, -) -> Command { - Command::single(command::Action::Window(Action::FetchId(Box::new(f)))) -} -- cgit From 0231ed6f1d5929d84bb81e6673d3319a24f08b16 Mon Sep 17 00:00:00 2001 From: traxys Date: Mon, 20 Mar 2023 00:18:41 +0100 Subject: winit: Fix replacement of node in wasm Replacing a node ends up with the following error: Node.replaceChild: Child to be replaced is not a child of this node It seems that Node.replaceChild is not recommended, and instead Element.replaceWith should be preferred. Using it avoids the panic. --- winit/src/application.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index b13b7214..31654f26 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -179,13 +179,17 @@ where .unwrap_or(None) }); - let _ = match target { - Some(node) => node - .replace_child(&canvas, &node) - .expect(&format!("Could not replace #{}", node.id())), - None => body - .append_child(&canvas) - .expect("Append canvas to HTML body"), + 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"); + } }; } -- cgit From 7e7e66586d990788ffd77b17e98357e74252f497 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 12 Apr 2023 04:37:39 +0200 Subject: Show `NotAllowed` as mouse icon when hovering a disabled `TextInput` --- winit/src/conversion.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'winit/src') diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 1b2ead36..d2dc9c06 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -236,6 +236,7 @@ pub fn mouse_interaction( winit::window::CursorIcon::EwResize } Interaction::ResizingVertically => winit::window::CursorIcon::NsResize, + Interaction::NotAllowed => winit::window::CursorIcon::NotAllowed, } } -- cgit From 5a056ce0510343621305474af74ade1db028c01a Mon Sep 17 00:00:00 2001 From: Night_Hunter Date: Wed, 12 Apr 2023 18:47:53 +1200 Subject: add action set icon while running (#1590) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * set windows icon live action * change get icon to insto raw * remove mobile docs * format * fix format * add file methods to Icon * Rename action to `ChangeIcon` and tidy up `Icon` modules * Fix documentation of `icon::Error` * Remove unnecessary `\` in `icon` documentation * Remove `etc.` from `Icon` documentation --------- Co-authored-by: Héctor Ramón Jiménez --- winit/src/application.rs | 3 +++ winit/src/conversion.rs | 9 +++++++++ winit/src/settings.rs | 7 ++++--- winit/src/window.rs | 9 ++++++++- 4 files changed, 24 insertions(+), 4 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 31654f26..dd345785 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -770,6 +770,9 @@ pub fn run_command( mode, )); } + window::Action::ChangeIcon(icon) => { + window.set_window_icon(conversion::icon(icon)) + } window::Action::FetchMode(tag) => { let mode = if window.is_visible().unwrap_or(true) { conversion::mode(window.fullscreen()) diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index d2dc9c06..cf066ef6 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -510,6 +510,15 @@ pub fn user_attention( } } +/// Converts some [`Icon`] into it's `winit` counterpart. +/// +/// Returns `None` if there is an error during the conversion. +pub fn icon(icon: window::Icon) -> Option { + let (pixels, size) = icon.into_raw(); + + winit::window::Icon::from_rgba(pixels, size.width, size.height).ok() +} + // As defined in: http://www.unicode.org/faq/private_use.html pub(crate) fn is_private_use_character(c: char) -> bool { matches!( diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 78d58000..6658773d 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -92,7 +92,7 @@ pub struct Window { pub always_on_top: bool, /// The window icon, which is also usually used in the taskbar - pub icon: Option, + pub icon: Option, /// Platform specific settings. pub platform_specific: platform::PlatformSpecific, @@ -134,8 +134,9 @@ impl Window { .with_resizable(self.resizable) .with_decorations(self.decorations) .with_transparent(self.transparent) - .with_window_icon(self.icon) - .with_always_on_top(self.always_on_top); + .with_window_icon(self.icon.and_then(conversion::icon)) + .with_always_on_top(self.always_on_top) + .with_visible(self.visible); if let Some(position) = conversion::position( primary_monitor.as_ref(), diff --git a/winit/src/window.rs b/winit/src/window.rs index 961562bd..ba0180c8 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -2,7 +2,9 @@ use crate::command::{self, Command}; use iced_native::window; -pub use window::{frames, Event, Mode, RedrawRequest, UserAttention}; +pub use window::{ + frames, icon, Event, Icon, Mode, RedrawRequest, UserAttention, +}; /// Closes the current window and exits the application. pub fn close() -> Command { @@ -104,3 +106,8 @@ pub fn fetch_id( f, )))) } + +/// Changes the [`Icon`] of the window. +pub fn change_icon(icon: Icon) -> Command { + Command::single(command::Action::Window(window::Action::ChangeIcon(icon))) +} -- cgit From c79cc2d2b3df99f69b048c68e503916c779a1102 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 13 Apr 2023 08:31:17 +0200 Subject: Bump versions :tada: --- winit/src/conversion.rs | 12 ++++++------ winit/src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'winit/src') diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index cf066ef6..e416c073 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -1,7 +1,7 @@ //! Convert [`winit`] types into [`iced_native`] types, and viceversa. //! //! [`winit`]: https://github.com/rust-windowing/winit -//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native +//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.9/native use crate::keyboard; use crate::mouse; use crate::touch; @@ -218,7 +218,7 @@ pub fn mode(mode: Option) -> window::Mode { /// Converts a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.9/native pub fn mouse_interaction( interaction: mouse::Interaction, ) -> winit::window::CursorIcon { @@ -243,7 +243,7 @@ pub fn mouse_interaction( /// Converts a `MouseButton` from [`winit`] to an [`iced_native`] mouse button. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.9/native pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button { match mouse_button { winit::event::MouseButton::Left => mouse::Button::Left, @@ -259,7 +259,7 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button { /// modifiers state. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.9/native pub fn modifiers( modifiers: winit::event::ModifiersState, ) -> keyboard::Modifiers { @@ -286,7 +286,7 @@ pub fn cursor_position( /// Converts a `Touch` from [`winit`] to an [`iced_native`] touch event. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.9/native pub fn touch_event( touch: winit::event::Touch, scale_factor: f64, @@ -317,7 +317,7 @@ pub fn touch_event( /// Converts a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.9/native pub fn key_code( virtual_keycode: winit::event::VirtualKeyCode, ) -> keyboard::KeyCode { diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 3a33e174..6b6c6045 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -11,7 +11,7 @@ //! Additionally, a [`conversion`] module is available for users that decide to //! implement a custom event loop. //! -//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native +//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.9/native //! [`winit`]: https://github.com/rust-windowing/winit //! [`conversion`]: crate::conversion #![doc( -- cgit From cf434236e7e15e0fa05e5915b8d4d78dcaf1b7e8 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 11 May 2023 17:28:51 +0200 Subject: Enable `doc_auto_cfg` when generating documentation --- winit/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit/src') diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 9f6bcebb..62d66d5e 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -29,7 +29,7 @@ )] #![forbid(rust_2018_idioms, unsafe_code)] #![allow(clippy::inherent_to_string, clippy::type_complexity)] -#![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] pub use iced_graphics as graphics; pub use iced_runtime as runtime; pub use iced_runtime::core; -- cgit From a5fbfe7ea5e73218af1befe02eb364afad2d6c55 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Mon, 27 Feb 2023 23:44:31 +0000 Subject: Update to winit 0.28 --- winit/src/application.rs | 7 ++++++- winit/src/settings.rs | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 3d7c6e5d..1141ba27 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -26,6 +26,7 @@ use crate::{Clipboard, Error, Proxy, Settings}; use futures::channel::mpsc; use std::mem::ManuallyDrop; +use winit::window::WindowLevel; #[cfg(feature = "trace")] pub use profiler::Profiler; @@ -795,7 +796,11 @@ pub fn run_command( window.focus_window(); } window::Action::ChangeAlwaysOnTop(on_top) => { - window.set_always_on_top(on_top); + let level = match on_top { + true => WindowLevel::AlwaysOnTop, + false => WindowLevel::Normal, + }; + window.set_window_level(level); } window::Action::FetchId(tag) => { proxy diff --git a/winit/src/settings.rs b/winit/src/settings.rs index be0ab329..413ae64a 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -26,7 +26,7 @@ use crate::core::window::Icon; use crate::Position; use winit::monitor::MonitorHandle; -use winit::window::WindowBuilder; +use winit::window::{WindowBuilder, WindowLevel}; use std::fmt; @@ -121,6 +121,10 @@ impl Window { let (width, height) = self.size; + let window_level = match self.always_on_top { + true => WindowLevel::AlwaysOnTop, + false => WindowLevel::Normal, + }; window_builder = window_builder .with_title(title) .with_inner_size(winit::dpi::LogicalSize { width, height }) @@ -128,7 +132,7 @@ impl Window { .with_decorations(self.decorations) .with_transparent(self.transparent) .with_window_icon(self.icon.and_then(conversion::icon)) - .with_always_on_top(self.always_on_top) + .with_window_level(window_level) .with_visible(self.visible); if let Some(position) = conversion::position( -- cgit From 42671e2855a7e54c1785f75833da062e07362b87 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Tue, 28 Feb 2023 12:11:04 +0000 Subject: Fix build on linux --- winit/src/settings.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'winit/src') diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 413ae64a..a807cdba 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -161,7 +161,9 @@ impl Window { target_os = "openbsd" ))] { - use ::winit::platform::unix::WindowBuilderExtUnix; + // `with_name` is available on both `WindowBuilderExtWayland` and `WindowBuilderExtX11` and they do + // exactly the same thing. We arbitrarily choose `WindowBuilderExtWayland` here. + use ::winit::platform::x11::WindowBuilderExtWayland; if let Some(id) = _id { window_builder = window_builder.with_name(id.clone(), id); -- cgit From 09a2a061303e954dbae7dab6f9bf092c121900f8 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Tue, 28 Feb 2023 12:15:04 +0000 Subject: Fix import path --- winit/src/settings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit/src') diff --git a/winit/src/settings.rs b/winit/src/settings.rs index a807cdba..22033113 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -163,7 +163,7 @@ impl Window { { // `with_name` is available on both `WindowBuilderExtWayland` and `WindowBuilderExtX11` and they do // exactly the same thing. We arbitrarily choose `WindowBuilderExtWayland` here. - use ::winit::platform::x11::WindowBuilderExtWayland; + use ::winit::platform::wayland::WindowBuilderExtWayland; if let Some(id) = _id { window_builder = window_builder.with_name(id.clone(), id); -- cgit From d6027d7da64c090e8735e755dc5095d77c38b721 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 11 May 2023 17:40:09 +0100 Subject: Use raw-window-handle instead of HWND --- winit/src/settings/windows.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'winit/src') diff --git a/winit/src/settings/windows.rs b/winit/src/settings/windows.rs index ff03a9c5..ce18da75 100644 --- a/winit/src/settings/windows.rs +++ b/winit/src/settings/windows.rs @@ -1,10 +1,12 @@ //! Platform specific settings for Windows. +use raw_window_handle::RawWindowHandle; + /// The platform specific window settings of an application. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct PlatformSpecific { /// Parent window - pub parent: Option, + pub parent: Option, /// Drag and drop support pub drag_and_drop: bool, -- cgit From 861a24745a9dfb99feaa3c5a4299af58a0054ed7 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 11 May 2023 17:51:03 +0100 Subject: Fixup option --- winit/src/settings.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'winit/src') diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 22033113..efee5c68 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -173,12 +173,8 @@ impl Window { #[cfg(target_os = "windows")] { use winit::platform::windows::WindowBuilderExtWindows; - - if let Some(parent) = self.platform_specific.parent { - window_builder = window_builder.with_parent_window(parent); - } - window_builder = window_builder + .with_parent_window(self.platform_specific.parent) .with_drag_and_drop(self.platform_specific.drag_and_drop); } -- cgit From e82ce8d93c2c36057b85b7cfe76c871e7c720f17 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 11 May 2023 19:27:27 +0100 Subject: Add unsafe block --- winit/src/settings.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'winit/src') diff --git a/winit/src/settings.rs b/winit/src/settings.rs index efee5c68..1f3389ef 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -173,8 +173,11 @@ impl Window { #[cfg(target_os = "windows")] { use winit::platform::windows::WindowBuilderExtWindows; + unsafe { + window_builder = window_builder + .with_parent_window(self.platform_specific.parent); + } window_builder = window_builder - .with_parent_window(self.platform_specific.parent) .with_drag_and_drop(self.platform_specific.drag_and_drop); } -- cgit From 096bcd898838a4980ebecbc658d7851af226eae6 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 11 May 2023 19:36:22 +0100 Subject: Allow unsafe code --- winit/src/lib.rs | 5 +++-- winit/src/settings.rs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'winit/src') diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 62d66d5e..4776ea2c 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -25,9 +25,10 @@ clippy::from_over_into, clippy::needless_borrow, clippy::new_without_default, - clippy::useless_conversion + clippy::useless_conversion, + unsafe_code )] -#![forbid(rust_2018_idioms, unsafe_code)] +#![forbid(rust_2018_idioms)] #![allow(clippy::inherent_to_string, clippy::type_complexity)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] pub use iced_graphics as graphics; diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 1f3389ef..13be3932 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -173,6 +173,7 @@ impl Window { #[cfg(target_os = "windows")] { use winit::platform::windows::WindowBuilderExtWindows; + #[allow(unsafe_code)] unsafe { window_builder = window_builder .with_parent_window(self.platform_specific.parent); -- cgit From 5802c957972ab972567d7f9a2f35a49bd9fb2cc3 Mon Sep 17 00:00:00 2001 From: bbb651 Date: Sat, 15 Apr 2023 00:45:30 +0300 Subject: Make mouse::Button::Other take u16 instead of u8 On wayland keys correspond to , and they are past the limit of u8, causing the back and forward buttons to be 20 and 19 which definitely isn't right (they should all be around 0x110..=0x117). --- winit/src/conversion.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'winit/src') diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index e416c073..22d8f223 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -249,9 +249,7 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button { winit::event::MouseButton::Left => mouse::Button::Left, winit::event::MouseButton::Right => mouse::Button::Right, winit::event::MouseButton::Middle => mouse::Button::Middle, - winit::event::MouseButton::Other(other) => { - mouse::Button::Other(other as u8) - } + winit::event::MouseButton::Other(other) => mouse::Button::Other(other), } } -- cgit From a7fa7e40058188c95a790712e11b863a9f84cecb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 25 May 2023 23:14:07 +0200 Subject: Introduce `window::Level` enum ... and add `level` field to `window::Settings` --- winit/src/conversion.rs | 13 +++++++++++++ winit/src/settings.rs | 18 +++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'winit/src') diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index a9262184..904aa184 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -140,6 +140,19 @@ pub fn window_event( } } +/// Converts a [`window::Level`] to a [`winit`] window level. +/// +/// [`winit`]: https://github.com/rust-windowing/winit +pub fn window_level(level: window::Level) -> winit::window::WindowLevel { + match level { + window::Level::Normal => winit::window::WindowLevel::Normal, + window::Level::AlwaysOnBottom => { + winit::window::WindowLevel::AlwaysOnBottom + } + window::Level::AlwaysOnTop => winit::window::WindowLevel::AlwaysOnTop, + } +} + /// Converts a [`Position`] to a [`winit`] logical position for a given monitor. /// /// [`winit`]: https://github.com/rust-windowing/winit diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 13be3932..40b3d487 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -22,11 +22,11 @@ mod platform; pub use platform::PlatformSpecific; use crate::conversion; -use crate::core::window::Icon; +use crate::core::window::{Icon, Level}; use crate::Position; use winit::monitor::MonitorHandle; -use winit::window::{WindowBuilder, WindowLevel}; +use winit::window::WindowBuilder; use std::fmt; @@ -81,8 +81,8 @@ pub struct Window { /// Whether the window should be transparent. pub transparent: bool, - /// Whether the window will always be on top of other windows. - pub always_on_top: bool, + /// The window [`Level`]. + pub level: Level, /// The window icon, which is also usually used in the taskbar pub icon: Option, @@ -102,7 +102,7 @@ impl fmt::Debug for Window { .field("resizable", &self.resizable) .field("decorations", &self.decorations) .field("transparent", &self.transparent) - .field("always_on_top", &self.always_on_top) + .field("level", &self.level) .field("icon", &self.icon.is_some()) .field("platform_specific", &self.platform_specific) .finish() @@ -121,10 +121,6 @@ impl Window { let (width, height) = self.size; - let window_level = match self.always_on_top { - true => WindowLevel::AlwaysOnTop, - false => WindowLevel::Normal, - }; window_builder = window_builder .with_title(title) .with_inner_size(winit::dpi::LogicalSize { width, height }) @@ -132,7 +128,7 @@ impl Window { .with_decorations(self.decorations) .with_transparent(self.transparent) .with_window_icon(self.icon.and_then(conversion::icon)) - .with_window_level(window_level) + .with_window_level(conversion::window_level(self.level)) .with_visible(self.visible); if let Some(position) = conversion::position( @@ -211,7 +207,7 @@ impl Default for Window { resizable: true, decorations: true, transparent: false, - always_on_top: false, + level: Level::default(), icon: None, platform_specific: Default::default(), } -- cgit From f0788b9f373f44248e55b068d9d0d494d628ba93 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 25 May 2023 23:18:50 +0200 Subject: Replace `change_always_on_top` action with `change_level` --- winit/src/application.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 1141ba27..4147be17 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -26,7 +26,6 @@ use crate::{Clipboard, Error, Proxy, Settings}; use futures::channel::mpsc; use std::mem::ManuallyDrop; -use winit::window::WindowLevel; #[cfg(feature = "trace")] pub use profiler::Profiler; @@ -795,12 +794,8 @@ pub fn run_command( window::Action::GainFocus => { window.focus_window(); } - window::Action::ChangeAlwaysOnTop(on_top) => { - let level = match on_top { - true => WindowLevel::AlwaysOnTop, - false => WindowLevel::Normal, - }; - window.set_window_level(level); + window::Action::ChangeLevel(level) => { + window.set_window_level(conversion::window_level(level)); } window::Action::FetchId(tag) => { proxy -- cgit From 70fd296ccc69ae135bfbe693b8404d5409ae4332 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 25 May 2023 23:20:26 +0200 Subject: Remove unnecessary newline --- winit/src/settings/windows.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'winit/src') diff --git a/winit/src/settings/windows.rs b/winit/src/settings/windows.rs index ce18da75..45d753bd 100644 --- a/winit/src/settings/windows.rs +++ b/winit/src/settings/windows.rs @@ -1,5 +1,4 @@ //! Platform specific settings for Windows. - use raw_window_handle::RawWindowHandle; /// The platform specific window settings of an application. -- cgit From 233196eb14b40f8bd5201ea0262571f82136ad53 Mon Sep 17 00:00:00 2001 From: Bingus Date: Sat, 25 Mar 2023 10:45:39 -0700 Subject: Added offscreen rendering support for wgpu & tiny-skia exposed with the window::screenshot command. --- winit/src/application.rs | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 4147be17..5176bec6 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -19,7 +19,7 @@ use crate::graphics::compositor::{self, Compositor}; use crate::runtime::clipboard; use crate::runtime::program::Program; use crate::runtime::user_interface::{self, UserInterface}; -use crate::runtime::{Command, Debug}; +use crate::runtime::{Command, Debug, Screenshot}; use crate::style::application::{Appearance, StyleSheet}; use crate::{Clipboard, Error, Proxy, Settings}; @@ -308,6 +308,8 @@ async fn run_instance( run_command( &application, + &mut compositor, + &mut surface, &mut cache, &state, &mut renderer, @@ -318,7 +320,6 @@ async fn run_instance( &mut proxy, &mut debug, &window, - || compositor.fetch_information(), ); runtime.track(application.subscription().into_recipes()); @@ -382,6 +383,8 @@ async fn run_instance( // Update application update( &mut application, + &mut compositor, + &mut surface, &mut cache, &state, &mut renderer, @@ -392,7 +395,6 @@ async fn run_instance( &mut debug, &mut messages, &window, - || compositor.fetch_information(), ); // Update window @@ -645,8 +647,10 @@ where /// Updates an [`Application`] by feeding it the provided messages, spawning any /// resulting [`Command`], and tracking its [`Subscription`]. -pub fn update( +pub fn update( application: &mut A, + compositor: &mut C, + surface: &mut C::Surface, cache: &mut user_interface::Cache, state: &State, renderer: &mut A::Renderer, @@ -657,8 +661,8 @@ pub fn update( debug: &mut Debug, messages: &mut Vec, window: &winit::window::Window, - graphics_info: impl FnOnce() -> compositor::Information + Copy, ) where + C: Compositor + 'static, ::Theme: StyleSheet, { for message in messages.drain(..) { @@ -676,6 +680,8 @@ pub fn update( run_command( application, + compositor, + surface, cache, state, renderer, @@ -686,7 +692,6 @@ pub fn update( proxy, debug, window, - graphics_info, ); } @@ -695,8 +700,10 @@ pub fn update( } /// Runs the actions of a [`Command`]. -pub fn run_command( +pub fn run_command( application: &A, + compositor: &mut C, + surface: &mut C::Surface, cache: &mut user_interface::Cache, state: &State, renderer: &mut A::Renderer, @@ -707,10 +714,10 @@ pub fn run_command( proxy: &mut winit::event_loop::EventLoopProxy, debug: &mut Debug, window: &winit::window::Window, - _graphics_info: impl FnOnce() -> compositor::Information + Copy, ) where A: Application, E: Executor, + C: Compositor + 'static, ::Theme: StyleSheet, { use crate::runtime::command; @@ -802,12 +809,28 @@ pub fn run_command( .send_event(tag(window.id().into())) .expect("Send message to event loop"); } + window::Action::Screenshot(tag) => { + let bytes = compositor.screenshot( + renderer, + surface, + state.viewport(), + state.background_color(), + &debug.overlay(), + ); + + proxy + .send_event(tag(Screenshot::new( + bytes, + state.physical_size(), + ))) + .expect("Send message to event loop.") + } }, command::Action::System(action) => match action { system::Action::QueryInformation(_tag) => { #[cfg(feature = "system")] { - let graphics_info = _graphics_info(); + let graphics_info = compositor.fetch_information(); let proxy = proxy.clone(); let _ = std::thread::spawn(move || { -- cgit From aba98e49654852281ed17bedd1becac6f9db8700 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 8 Jun 2023 20:35:40 +0200 Subject: Extend cursor availability to the shell level --- winit/src/application.rs | 8 ++++---- winit/src/application/state.rs | 29 ++++++++++++++++------------- 2 files changed, 20 insertions(+), 17 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 4147be17..be416ac8 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -356,7 +356,7 @@ async fn run_instance( let (interface_state, statuses) = user_interface.update( &events, - state.cursor_position(), + state.cursor(), &mut renderer, &mut clipboard, &mut messages, @@ -422,7 +422,7 @@ async fn run_instance( let (interface_state, _) = user_interface.update( &[redraw_event.clone()], - state.cursor_position(), + state.cursor(), &mut renderer, &mut clipboard, &mut messages, @@ -435,7 +435,7 @@ async fn run_instance( &renderer::Style { text_color: state.text_color(), }, - state.cursor_position(), + state.cursor(), ); debug.draw_finished(); @@ -508,7 +508,7 @@ async fn run_instance( &renderer::Style { text_color: state.text_color(), }, - state.cursor_position(), + state.cursor(), ); if new_mouse_interaction != mouse_interaction { diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs index c37ccca6..967f43f2 100644 --- a/winit/src/application/state.rs +++ b/winit/src/application/state.rs @@ -1,7 +1,8 @@ use crate::application::{self, StyleSheet as _}; use crate::conversion; use crate::core; -use crate::core::{Color, Point, Size}; +use crate::core::mouse; +use crate::core::{Color, Size}; use crate::graphics::Viewport; use crate::runtime::Debug; use crate::Application; @@ -20,7 +21,7 @@ where scale_factor: f64, viewport: Viewport, viewport_version: usize, - cursor_position: winit::dpi::PhysicalPosition, + cursor_position: Option>, modifiers: winit::event::ModifiersState, theme: ::Theme, appearance: application::Appearance, @@ -52,8 +53,7 @@ where scale_factor, viewport, viewport_version: 0, - // TODO: Encode cursor availability in the type-system - cursor_position: winit::dpi::PhysicalPosition::new(-1.0, -1.0), + cursor_position: None, modifiers: winit::event::ModifiersState::default(), theme, appearance, @@ -89,11 +89,16 @@ where } /// Returns the current cursor position of the [`State`]. - pub fn cursor_position(&self) -> Point { - conversion::cursor_position( - self.cursor_position, - self.viewport.scale_factor(), - ) + pub fn cursor(&self) -> mouse::Cursor { + self.cursor_position + .map(|cursor_position| { + conversion::cursor_position( + cursor_position, + self.viewport.scale_factor(), + ) + }) + .map(mouse::Cursor::Available) + .unwrap_or(mouse::Cursor::Unavailable) } /// Returns the current keyboard modifiers of the [`State`]. @@ -153,12 +158,10 @@ where | WindowEvent::Touch(Touch { location: position, .. }) => { - self.cursor_position = *position; + self.cursor_position = Some(*position); } WindowEvent::CursorLeft { .. } => { - // TODO: Encode cursor availability in the type-system - self.cursor_position = - winit::dpi::PhysicalPosition::new(-1.0, -1.0); + self.cursor_position = None; } WindowEvent::ModifiersChanged(new_modifiers) => { self.modifiers = *new_modifiers; -- cgit From 21a71b753d6da2233bce913f4e623ee14859ec23 Mon Sep 17 00:00:00 2001 From: Yiğit Özdemir Date: Wed, 21 Jun 2023 19:43:20 +0300 Subject: Add command to retrieve window size --- winit/src/application.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index be416ac8..ff5afa69 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -3,6 +3,7 @@ mod profiler; mod state; +use iced_graphics::core::window::SizeType; pub use state::State; use crate::conversion; @@ -747,6 +748,21 @@ pub fn run_command( height, }); } + window::Action::FetchSize { + size_type, + callback, + } => { + let width_height = match size_type { + SizeType::Inner => window.inner_size(), + SizeType::Outer => window.outer_size(), + }; + let width_height = + (width_height.width, width_height.height); + + proxy + .send_event(callback(width_height)) + .expect("Send message to event loop") + } window::Action::Maximize(maximized) => { window.set_maximized(maximized); } -- cgit From b394c84b37eacb266d45663d5d6626f1b616af7e Mon Sep 17 00:00:00 2001 From: Yiğit Özdemir Date: Thu, 22 Jun 2023 18:28:32 +0300 Subject: Add FetchSize command - apply the changes discussed at #water-cooler --- winit/src/application.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index ff5afa69..b0824e0e 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -3,7 +3,6 @@ mod profiler; mod state; -use iced_graphics::core::window::SizeType; pub use state::State; use crate::conversion; @@ -748,19 +747,11 @@ pub fn run_command( height, }); } - window::Action::FetchSize { - size_type, - callback, - } => { - let width_height = match size_type { - SizeType::Inner => window.inner_size(), - SizeType::Outer => window.outer_size(), - }; - let width_height = - (width_height.width, width_height.height); + window::Action::FetchSize(callback) => { + let size = window.inner_size(); proxy - .send_event(callback(width_height)) + .send_event(callback((size.width, size.height))) .expect("Send message to event loop") } window::Action::Maximize(maximized) => { -- cgit From 5ae726e02c4d6c9889ef7335d9bc80ef1992e34f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 27 Jun 2023 19:41:03 +0200 Subject: Move `Screenshot` inside `window` module --- winit/src/application.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 5176bec6..a4687375 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -19,7 +19,7 @@ use crate::graphics::compositor::{self, Compositor}; use crate::runtime::clipboard; use crate::runtime::program::Program; use crate::runtime::user_interface::{self, UserInterface}; -use crate::runtime::{Command, Debug, Screenshot}; +use crate::runtime::{Command, Debug}; use crate::style::application::{Appearance, StyleSheet}; use crate::{Clipboard, Error, Proxy, Settings}; @@ -819,7 +819,7 @@ pub fn run_command( ); proxy - .send_event(tag(Screenshot::new( + .send_event(tag(window::Screenshot::new( bytes, state.physical_size(), ))) -- cgit From cc32bd4de09ee58c15d1b3f2cec4a79dc65dd035 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Jul 2023 06:41:28 +0200 Subject: Use `Size` in both `Resize` and `FetchSize` window actions --- winit/src/application.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index b0824e0e..afc523b6 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -741,17 +741,20 @@ pub fn run_command( window::Action::Drag => { let _res = window.drag_window(); } - window::Action::Resize { width, height } => { + window::Action::Resize(size) => { window.set_inner_size(winit::dpi::LogicalSize { - width, - height, + width: size.width, + height: size.height, }); } window::Action::FetchSize(callback) => { let size = window.inner_size(); proxy - .send_event(callback((size.width, size.height))) + .send_event(callback(Size::new( + size.width, + size.height, + ))) .expect("Send message to event loop") } window::Action::Maximize(maximized) => { -- cgit