diff options
author | 2022-01-28 16:47:50 +0700 | |
---|---|---|
committer | 2022-01-28 21:37:16 +0700 | |
commit | 825c7749ff364cf1f7ae5cab0c25f27ed85c7d82 (patch) | |
tree | fdd7e499c343a7e3cf690d4b5aa40ba568674a3c /src | |
parent | 1e3feee3a36f25d7e2eda231c3e6b895858952c5 (diff) | |
download | iced-825c7749ff364cf1f7ae5cab0c25f27ed85c7d82.tar.gz iced-825c7749ff364cf1f7ae5cab0c25f27ed85c7d82.tar.bz2 iced-825c7749ff364cf1f7ae5cab0c25f27ed85c7d82.zip |
Replace `iced_web` with WebGL support in `wgpu` :tada:
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/lib.rs | 19 | ||||
-rw-r--r-- | src/settings.rs | 1 | ||||
-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 |
9 files changed, 64 insertions, 156 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 { @@ -208,29 +208,18 @@ pub mod window; )] 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/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/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 { |