Replace iced_web with WebGL support in wgpu 🎉

This commit is contained in:
Héctor Ramón Jiménez 2022-01-28 16:47:50 +07:00
parent 1e3feee3a3
commit 825c7749ff
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
35 changed files with 68 additions and 3474 deletions

View file

@ -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()
};
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(())
}
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()
}
}

View file

@ -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;

View file

@ -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 {

View file

@ -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::*;

View file

@ -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 {

View file

@ -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;

View file

@ -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

View file

@ -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 {

View file

@ -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 {