diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/application.rs | 78 | ||||
-rw-r--r-- | src/element.rs | 4 | ||||
-rw-r--r-- | src/error.rs | 1 | ||||
-rw-r--r-- | src/executor.rs | 94 | ||||
-rw-r--r-- | src/lib.rs | 34 | ||||
-rw-r--r-- | src/sandbox.rs | 2 | ||||
-rw-r--r-- | src/settings.rs | 1 | ||||
-rw-r--r-- | src/time.rs | 12 | ||||
-rw-r--r-- | src/widget.rs | 96 | ||||
-rw-r--r-- | src/window/icon.rs | 19 | ||||
-rw-r--r-- | src/window/position.rs | 1 | ||||
-rw-r--r-- | src/window/settings.rs | 1 |
12 files changed, 79 insertions, 264 deletions
diff --git a/src/application.rs b/src/application.rs index b722c8a3..14a16d61 100644 --- a/src/application.rs +++ b/src/application.rs @@ -198,39 +198,28 @@ pub trait Application: Sized { where Self: 'static, { - #[cfg(not(target_arch = "wasm32"))] - { - let renderer_settings = crate::renderer::Settings { - default_font: settings.default_font, - default_text_size: settings.default_text_size, - text_multithreading: settings.text_multithreading, - antialiasing: if settings.antialiasing { - Some(crate::renderer::settings::Antialiasing::MSAAx4) - } else { - None - }, - ..crate::renderer::Settings::from_env() - }; - - Ok(crate::runtime::application::run::< - Instance<Self>, - Self::Executor, - crate::renderer::window::Compositor, - >(settings.into(), renderer_settings)?) - } - - #[cfg(target_arch = "wasm32")] - { - <Instance<Self> as iced_web::Application>::run(settings.flags); - - Ok(()) - } + let renderer_settings = crate::renderer::Settings { + default_font: settings.default_font, + default_text_size: settings.default_text_size, + text_multithreading: settings.text_multithreading, + antialiasing: if settings.antialiasing { + Some(crate::renderer::settings::Antialiasing::MSAAx4) + } else { + None + }, + ..crate::renderer::Settings::from_env() + }; + + Ok(crate::runtime::application::run::< + Instance<Self>, + Self::Executor, + crate::renderer::window::Compositor, + >(settings.into(), renderer_settings)?) } } struct Instance<A: Application>(A); -#[cfg(not(target_arch = "wasm32"))] impl<A> iced_winit::Program for Instance<A> where A: Application, @@ -247,7 +236,6 @@ where } } -#[cfg(not(target_arch = "wasm32"))] impl<A> crate::runtime::Application for Instance<A> where A: Application, @@ -288,35 +276,3 @@ where self.0.should_exit() } } - -#[cfg(target_arch = "wasm32")] -impl<A> iced_web::Application for Instance<A> -where - A: Application, -{ - type Executor = A::Executor; - type Message = A::Message; - type Flags = A::Flags; - - fn new(flags: Self::Flags) -> (Self, Command<A::Message>) { - let (app, command) = A::new(flags); - - (Instance(app), command) - } - - fn title(&self) -> String { - self.0.title() - } - - fn update(&mut self, message: Self::Message) -> Command<Self::Message> { - self.0.update(message) - } - - fn subscription(&self) -> Subscription<Self::Message> { - self.0.subscription() - } - - fn view(&mut self) -> Element<'_, Self::Message> { - self.0.view() - } -} diff --git a/src/element.rs b/src/element.rs index 6f47c701..8bad18c1 100644 --- a/src/element.rs +++ b/src/element.rs @@ -1,9 +1,5 @@ /// A generic widget. /// /// This is an alias of an `iced_native` element with a default `Renderer`. -#[cfg(not(target_arch = "wasm32"))] pub type Element<'a, Message> = crate::runtime::Element<'a, Message, crate::renderer::Renderer>; - -#[cfg(target_arch = "wasm32")] -pub use iced_web::Element; diff --git a/src/error.rs b/src/error.rs index c8fa6636..17479c60 100644 --- a/src/error.rs +++ b/src/error.rs @@ -16,7 +16,6 @@ pub enum Error { GraphicsAdapterNotFound, } -#[cfg(not(target_arch = "wasm32"))] impl From<iced_winit::Error> for Error { fn from(error: iced_winit::Error) -> Error { match error { diff --git a/src/executor.rs b/src/executor.rs index c7166c68..36ae274e 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -1,86 +1,14 @@ //! Choose your preferred executor to power your application. pub use crate::runtime::Executor; -pub use platform::Default; - -#[cfg(not(target_arch = "wasm32"))] -mod platform { - use iced_futures::{executor, futures}; - - #[cfg(feature = "tokio")] - type Executor = executor::Tokio; - - #[cfg(all(feature = "async-std", not(feature = "tokio"),))] - type Executor = executor::AsyncStd; - - #[cfg(all( - feature = "smol", - not(any(feature = "tokio", feature = "async-std")), - ))] - type Executor = executor::Smol; - - #[cfg(not(any( - feature = "tokio", - feature = "async-std", - feature = "smol", - )))] - type Executor = executor::ThreadPool; - - /// A default cross-platform executor. - /// - /// - On native platforms, it will use: - /// - `iced_futures::executor::Tokio` when the `tokio` feature is enabled. - /// - `iced_futures::executor::AsyncStd` when the `async-std` feature is - /// enabled. - /// - `iced_futures::executor::ThreadPool` otherwise. - /// - On the Web, it will use `iced_futures::executor::WasmBindgen`. - #[derive(Debug)] - pub struct Default(Executor); - - impl super::Executor for Default { - fn new() -> Result<Self, futures::io::Error> { - Ok(Default(Executor::new()?)) - } - - fn spawn( - &self, - future: impl futures::Future<Output = ()> + Send + 'static, - ) { - let _ = self.0.spawn(future); - } - - fn enter<R>(&self, f: impl FnOnce() -> R) -> R { - super::Executor::enter(&self.0, f) - } - } -} - -#[cfg(target_arch = "wasm32")] -mod platform { - use iced_futures::{executor::WasmBindgen, futures, Executor}; - - /// A default cross-platform executor. - /// - /// - On native platforms, it will use: - /// - `iced_futures::executor::Tokio` when the `tokio` feature is enabled. - /// - `iced_futures::executor::AsyncStd` when the `async-std` feature is - /// enabled. - /// - `iced_futures::executor::ThreadPool` otherwise. - /// - On the Web, it will use `iced_futures::executor::WasmBindgen`. - #[derive(Debug)] - pub struct Default(WasmBindgen); - - impl Executor for Default { - fn new() -> Result<Self, futures::io::Error> { - Ok(Default(WasmBindgen::new()?)) - } - - fn spawn(&self, future: impl futures::Future<Output = ()> + 'static) { - self.0.spawn(future); - } - - fn enter<R>(&self, f: impl FnOnce() -> R) -> R { - self.0.enter(f) - } - } -} +/// A default cross-platform executor. +/// +/// - On native platforms, it will use: +/// - `iced_futures::backend::native::tokio` when the `tokio` feature is enabled. +/// - `iced_futures::backend::native::async-std` when the `async-std` feature is +/// enabled. +/// - `iced_futures::backend::native::smol` when the `smol` feature is enabled. +/// - `iced_futures::backend::native::thread_pool` otherwise. +/// +/// - On Wasm, it will use `iced_futures::backend::wasm::wasm_bindgen`. +pub type Default = iced_futures::backend::default::Executor; @@ -191,46 +191,22 @@ pub mod executor; pub mod keyboard; pub mod mouse; pub mod settings; +pub mod time; pub mod widget; pub mod window; -#[cfg(all( - any(feature = "tokio", feature = "async-std", feature = "smol"), - not(target_arch = "wasm32") -))] -#[cfg_attr( - docsrs, - doc(cfg(any( - feature = "tokio", - feature = "async-std" - feature = "smol" - ))) -)] -pub mod time; - -#[cfg(all( - not(target_arch = "wasm32"), - not(feature = "glow"), - feature = "wgpu" -))] +#[cfg(all(not(feature = "glow"), feature = "wgpu"))] use iced_winit as runtime; -#[cfg(all(not(target_arch = "wasm32"), feature = "glow"))] +#[cfg(feature = "glow")] use iced_glutin as runtime; -#[cfg(all( - not(target_arch = "wasm32"), - not(feature = "glow"), - feature = "wgpu" -))] +#[cfg(all(not(feature = "glow"), feature = "wgpu"))] use iced_wgpu as renderer; -#[cfg(all(not(target_arch = "wasm32"), feature = "glow"))] +#[cfg(feature = "glow")] use iced_glow as renderer; -#[cfg(target_arch = "wasm32")] -use iced_web as runtime; - #[doc(no_inline)] pub use widget::*; diff --git a/src/sandbox.rs b/src/sandbox.rs index aabfb9c7..2306c650 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -156,7 +156,7 @@ impl<T> Application for T where T: Sandbox, { - type Executor = crate::runtime::executor::Null; + type Executor = iced_futures::backend::null::Executor; type Flags = (); type Message = T::Message; diff --git a/src/settings.rs b/src/settings.rs index c521a62a..d31448fb 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -106,7 +106,6 @@ where } } -#[cfg(not(target_arch = "wasm32"))] impl<Flags> From<Settings<Flags>> for iced_winit::Settings<Flags> { fn from(settings: Settings<Flags>) -> iced_winit::Settings<Flags> { iced_winit::Settings { diff --git a/src/time.rs b/src/time.rs index b8432895..37d454ed 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,12 +1,4 @@ //! Listen and react to time. -use crate::Subscription; +pub use iced_core::time::{Duration, Instant}; -/// Returns a [`Subscription`] that produces messages at a set interval. -/// -/// The first message is produced after a `duration`, and then continues to -/// produce more messages every `duration` after that. -pub fn every( - duration: std::time::Duration, -) -> Subscription<std::time::Instant> { - iced_futures::time::every(duration) -} +pub use iced_futures::backend::default::time::*; diff --git a/src/widget.rs b/src/widget.rs index 0f0b0325..c619bcfa 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -13,63 +13,53 @@ //! //! These widgets have their own module with a `State` type. For instance, a //! [`TextInput`] has some [`text_input::State`]. -#[cfg(not(target_arch = "wasm32"))] -mod platform { - pub use crate::renderer::widget::{ - button, checkbox, container, pane_grid, pick_list, progress_bar, radio, - rule, scrollable, slider, text_input, toggler, tooltip, Column, Row, - Space, Text, - }; +pub use crate::renderer::widget::{ + button, checkbox, container, pane_grid, pick_list, progress_bar, radio, + rule, scrollable, slider, text_input, toggler, tooltip, Column, Row, Space, + Text, +}; - #[cfg(any(feature = "canvas", feature = "glow_canvas"))] - #[cfg_attr( - docsrs, - doc(cfg(any(feature = "canvas", feature = "glow_canvas"))) - )] - pub use crate::renderer::widget::canvas; +#[cfg(any(feature = "canvas", feature = "glow_canvas"))] +#[cfg_attr( + docsrs, + doc(cfg(any(feature = "canvas", feature = "glow_canvas"))) +)] +pub use crate::renderer::widget::canvas; - #[cfg(any(feature = "qr_code", feature = "glow_qr_code"))] - #[cfg_attr( - docsrs, - doc(cfg(any(feature = "qr_code", feature = "glow_qr_code"))) - )] - pub use crate::renderer::widget::qr_code; +#[cfg(any(feature = "qr_code", feature = "glow_qr_code"))] +#[cfg_attr( + docsrs, + doc(cfg(any(feature = "qr_code", feature = "glow_qr_code"))) +)] +pub use crate::renderer::widget::qr_code; - #[cfg_attr(docsrs, doc(cfg(feature = "image")))] - pub mod image { - //! Display images in your user interface. - pub use crate::runtime::image::Handle; - pub use crate::runtime::widget::image::viewer; - pub use crate::runtime::widget::image::{Image, Viewer}; - } - - #[cfg_attr(docsrs, doc(cfg(feature = "svg")))] - pub mod svg { - //! Display vector graphics in your user interface. - pub use crate::runtime::svg::Handle; - pub use crate::runtime::widget::svg::Svg; - } - - #[doc(no_inline)] - pub use { - button::Button, checkbox::Checkbox, container::Container, image::Image, - pane_grid::PaneGrid, pick_list::PickList, progress_bar::ProgressBar, - radio::Radio, rule::Rule, scrollable::Scrollable, slider::Slider, - svg::Svg, text_input::TextInput, toggler::Toggler, tooltip::Tooltip, - }; - - #[cfg(any(feature = "canvas", feature = "glow_canvas"))] - #[doc(no_inline)] - pub use canvas::Canvas; - - #[cfg(any(feature = "qr_code", feature = "glow_qr_code"))] - #[doc(no_inline)] - pub use qr_code::QRCode; +#[cfg_attr(docsrs, doc(cfg(feature = "image")))] +pub mod image { + //! Display images in your user interface. + pub use crate::runtime::image::Handle; + pub use crate::runtime::widget::image::viewer; + pub use crate::runtime::widget::image::{Image, Viewer}; } -#[cfg(target_arch = "wasm32")] -mod platform { - pub use iced_web::widget::*; +#[cfg_attr(docsrs, doc(cfg(feature = "svg")))] +pub mod svg { + //! Display vector graphics in your user interface. + pub use crate::runtime::svg::Handle; + pub use crate::runtime::widget::svg::Svg; } -pub use platform::*; +#[doc(no_inline)] +pub use { + button::Button, checkbox::Checkbox, container::Container, image::Image, + pane_grid::PaneGrid, pick_list::PickList, progress_bar::ProgressBar, + radio::Radio, rule::Rule, scrollable::Scrollable, slider::Slider, svg::Svg, + text_input::TextInput, toggler::Toggler, tooltip::Tooltip, +}; + +#[cfg(any(feature = "canvas", feature = "glow_canvas"))] +#[doc(no_inline)] +pub use canvas::Canvas; + +#[cfg(any(feature = "qr_code", feature = "glow_qr_code"))] +#[doc(no_inline)] +pub use qr_code::QRCode; diff --git a/src/window/icon.rs b/src/window/icon.rs index 287538b1..aacadfca 100644 --- a/src/window/icon.rs +++ b/src/window/icon.rs @@ -3,18 +3,11 @@ use std::fmt; use std::io; /// The icon of a window. -#[cfg(not(target_arch = "wasm32"))] #[derive(Debug, Clone)] pub struct Icon(iced_winit::winit::window::Icon); -/// The icon of a window. -#[cfg(target_arch = "wasm32")] -#[derive(Debug, Clone)] -pub struct Icon; - impl Icon { /// Creates an icon from 32bpp RGBA data. - #[cfg(not(target_arch = "wasm32"))] pub fn from_rgba( rgba: Vec<u8>, width: u32, @@ -25,16 +18,6 @@ impl Icon { Ok(Icon(raw)) } - - /// Creates an icon from 32bpp RGBA data. - #[cfg(target_arch = "wasm32")] - pub fn from_rgba( - _rgba: Vec<u8>, - _width: u32, - _height: u32, - ) -> Result<Self, Error> { - Ok(Icon) - } } /// An error produced when using `Icon::from_rgba` with invalid arguments. @@ -62,7 +45,6 @@ pub enum Error { OsError(io::Error), } -#[cfg(not(target_arch = "wasm32"))] impl From<iced_winit::winit::window::BadIcon> for Error { fn from(error: iced_winit::winit::window::BadIcon) -> Self { use iced_winit::winit::window::BadIcon; @@ -86,7 +68,6 @@ impl From<iced_winit::winit::window::BadIcon> for Error { } } -#[cfg(not(target_arch = "wasm32"))] impl From<Icon> for iced_winit::winit::window::Icon { fn from(icon: Icon) -> Self { icon.0 diff --git a/src/window/position.rs b/src/window/position.rs index 8535ef6a..6b9fac41 100644 --- a/src/window/position.rs +++ b/src/window/position.rs @@ -21,7 +21,6 @@ impl Default for Position { } } -#[cfg(not(target_arch = "wasm32"))] impl From<Position> for iced_winit::Position { fn from(position: Position) -> Self { match position { diff --git a/src/window/settings.rs b/src/window/settings.rs index ec6c3071..8e32f4fb 100644 --- a/src/window/settings.rs +++ b/src/window/settings.rs @@ -47,7 +47,6 @@ impl Default for Settings { } } -#[cfg(not(target_arch = "wasm32"))] impl From<Settings> for iced_winit::settings::Window { fn from(settings: Settings) -> Self { Self { |