Make iced_tiny_skia optional with a tiny-skia feature
This commit is contained in:
parent
bbafeed13d
commit
1f13a91361
20 changed files with 157 additions and 91 deletions
|
|
@ -18,9 +18,11 @@ all-features = true
|
|||
maintenance = { status = "actively-developed" }
|
||||
|
||||
[features]
|
||||
default = ["wgpu", "fira-sans", "auto-detect-theme"]
|
||||
default = ["wgpu", "tiny-skia", "fira-sans", "auto-detect-theme"]
|
||||
# Enable the `wgpu` GPU-accelerated renderer backend
|
||||
wgpu = ["iced_renderer/wgpu", "iced_widget/wgpu"]
|
||||
# Enable the `tiny-skia` software renderer backend
|
||||
tiny-skia = ["iced_renderer/tiny-skia"]
|
||||
# Enables the `Image` widget
|
||||
image = ["iced_widget/image", "dep:image"]
|
||||
# Enables the `Svg` widget
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ impl<'a, Message, Theme, Renderer> Element<'a, Message, Theme, Renderer> {
|
|||
///
|
||||
/// ```no_run
|
||||
/// # mod iced {
|
||||
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, iced_core::renderer::Null>;
|
||||
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, ()>;
|
||||
/// #
|
||||
/// # pub mod widget {
|
||||
/// # pub fn row<'a, Message>(iter: impl IntoIterator<Item = super::Element<'a, Message>>) -> super::Element<'a, Message> {
|
||||
|
|
@ -109,7 +109,7 @@ impl<'a, Message, Theme, Renderer> Element<'a, Message, Theme, Renderer> {
|
|||
/// # pub enum Message {}
|
||||
/// # pub struct Counter;
|
||||
/// #
|
||||
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, iced_core::renderer::Null>;
|
||||
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, ()>;
|
||||
/// #
|
||||
/// # impl Counter {
|
||||
/// # pub fn view(&self) -> Element<Message> {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
//! Write your own renderer.
|
||||
#[cfg(debug_assertions)]
|
||||
mod null;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub use null::Null;
|
||||
|
||||
use crate::{
|
||||
Background, Border, Color, Rectangle, Shadow, Size, Transformation, Vector,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::alignment;
|
||||
use crate::image;
|
||||
use crate::renderer::{self, Renderer};
|
||||
use crate::text::{self, Text};
|
||||
use crate::{
|
||||
|
|
@ -7,20 +8,7 @@ use crate::{
|
|||
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// A renderer that does nothing.
|
||||
///
|
||||
/// It can be useful if you are writing tests!
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct Null;
|
||||
|
||||
impl Null {
|
||||
/// Creates a new [`Null`] renderer.
|
||||
pub fn new() -> Null {
|
||||
Null
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderer for Null {
|
||||
impl Renderer for () {
|
||||
fn start_layer(&mut self) {}
|
||||
|
||||
fn end_layer(&mut self, _bounds: Rectangle) {}
|
||||
|
|
@ -39,7 +27,7 @@ impl Renderer for Null {
|
|||
}
|
||||
}
|
||||
|
||||
impl text::Renderer for Null {
|
||||
impl text::Renderer for () {
|
||||
type Font = Font;
|
||||
type Paragraph = ();
|
||||
type Editor = ();
|
||||
|
|
@ -173,3 +161,19 @@ impl text::Editor for () {
|
|||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl image::Renderer for () {
|
||||
type Handle = ();
|
||||
|
||||
fn measure_image(&self, _handle: &Self::Handle) -> Size<u32> {
|
||||
Size::default()
|
||||
}
|
||||
|
||||
fn draw_image(
|
||||
&mut self,
|
||||
_handle: Self::Handle,
|
||||
_filter_method: image::FilterMethod,
|
||||
_bounds: Rectangle,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::Vector;
|
||||
|
||||
/// An amount of space in 2 dimensions.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
|
||||
pub struct Size<T = f32> {
|
||||
/// The width.
|
||||
pub width: T,
|
||||
|
|
|
|||
|
|
@ -356,7 +356,9 @@ where
|
|||
renderer.with_translation(
|
||||
Vector::new(bounds.x, bounds.y),
|
||||
|renderer| {
|
||||
renderer.draw_geometry([geometry]);
|
||||
use iced::advanced::graphics::geometry::Renderer as _;
|
||||
|
||||
renderer.draw_geometry(geometry);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ use std::borrow::Cow;
|
|||
///
|
||||
/// [`Renderer`]: crate::Renderer
|
||||
pub trait Backend {
|
||||
/// The compositor of this [`Backend`].
|
||||
type Compositor;
|
||||
|
||||
/// The custom kind of primitives this [`Backend`] supports.
|
||||
type Primitive: TryFrom<Mesh, Error = &'static str>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub trait Compositor: Sized {
|
|||
type Settings: Default;
|
||||
|
||||
/// The iced renderer of the backend.
|
||||
type Renderer: iced_core::Renderer;
|
||||
type Renderer;
|
||||
|
||||
/// The surface of the backend.
|
||||
type Surface;
|
||||
|
|
@ -122,3 +122,63 @@ pub struct Information {
|
|||
/// Contains the graphics backend.
|
||||
pub backend: String,
|
||||
}
|
||||
|
||||
impl Compositor for () {
|
||||
type Settings = ();
|
||||
type Renderer = ();
|
||||
type Surface = ();
|
||||
|
||||
async fn new<W: Window + Clone>(
|
||||
_settings: Self::Settings,
|
||||
_compatible_window: W,
|
||||
) -> Result<Self, Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_renderer(&self) -> Self::Renderer {}
|
||||
|
||||
fn create_surface<W: Window + Clone>(
|
||||
&mut self,
|
||||
_window: W,
|
||||
_width: u32,
|
||||
_height: u32,
|
||||
) -> Self::Surface {
|
||||
}
|
||||
|
||||
fn configure_surface(
|
||||
&mut self,
|
||||
_surface: &mut Self::Surface,
|
||||
_width: u32,
|
||||
_height: u32,
|
||||
) {
|
||||
}
|
||||
|
||||
fn fetch_information(&self) -> Information {
|
||||
Information {
|
||||
adapter: String::from("Null Renderer"),
|
||||
backend: String::from("Null"),
|
||||
}
|
||||
}
|
||||
|
||||
fn present<T: AsRef<str>>(
|
||||
&mut self,
|
||||
_renderer: &mut Self::Renderer,
|
||||
_surface: &mut Self::Surface,
|
||||
_viewport: &Viewport,
|
||||
_background_color: Color,
|
||||
_overlay: &[T],
|
||||
) -> Result<(), SurfaceError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn screenshot<T: AsRef<str>>(
|
||||
&mut self,
|
||||
_renderer: &mut Self::Renderer,
|
||||
_surface: &mut Self::Surface,
|
||||
_viewport: &Viewport,
|
||||
_background_color: Color,
|
||||
_overlay: &[T],
|
||||
) -> Vec<u8> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ pub use text::Text;
|
|||
|
||||
pub use crate::gradient::{self, Gradient};
|
||||
|
||||
use crate::core::Size;
|
||||
use crate::core::{self, Size};
|
||||
use crate::Cached;
|
||||
|
||||
/// A renderer capable of drawing some [`Self::Geometry`].
|
||||
pub trait Renderer: crate::core::Renderer {
|
||||
pub trait Renderer: core::Renderer {
|
||||
/// The kind of geometry this renderer can draw.
|
||||
type Geometry: Cached;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
//! Draw and generate geometry.
|
||||
use crate::core::{Point, Radians, Rectangle, Size, Vector};
|
||||
use crate::geometry::{self, Fill, Path, Stroke, Text};
|
||||
use crate::Cached;
|
||||
|
||||
/// The region of a surface that can be used to draw geometry.
|
||||
#[allow(missing_debug_implementations)]
|
||||
|
|
@ -173,7 +172,7 @@ where
|
|||
/// of each method.
|
||||
#[allow(missing_docs)]
|
||||
pub trait Backend: Sized {
|
||||
type Geometry: Cached;
|
||||
type Geometry;
|
||||
|
||||
fn width(&self) -> f32;
|
||||
fn height(&self) -> f32;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Draw triangles!
|
||||
use crate::color;
|
||||
use crate::core::{self, Rectangle, Size};
|
||||
use crate::core::{Rectangle, Size};
|
||||
use crate::gradient;
|
||||
use crate::Damage;
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ pub struct GradientVertex2D {
|
|||
}
|
||||
|
||||
/// A renderer capable of drawing a [`Mesh`].
|
||||
pub trait Renderer: core::Renderer {
|
||||
pub trait Renderer {
|
||||
/// Draws the given [`Mesh`].
|
||||
fn draw_mesh(&mut self, mesh: Mesh);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,18 +12,20 @@ keywords.workspace = true
|
|||
|
||||
[features]
|
||||
wgpu = ["iced_wgpu"]
|
||||
image = ["iced_tiny_skia/image", "iced_wgpu?/image"]
|
||||
svg = ["iced_tiny_skia/svg", "iced_wgpu?/svg"]
|
||||
geometry = ["iced_graphics/geometry", "iced_tiny_skia/geometry", "iced_wgpu?/geometry"]
|
||||
tiny-skia = ["iced_tiny_skia"]
|
||||
image = ["iced_tiny_skia?/image", "iced_wgpu?/image"]
|
||||
svg = ["iced_tiny_skia?/svg", "iced_wgpu?/svg"]
|
||||
geometry = ["iced_graphics/geometry", "iced_tiny_skia?/geometry", "iced_wgpu?/geometry"]
|
||||
tracing = ["iced_wgpu?/tracing"]
|
||||
web-colors = ["iced_wgpu?/web-colors"]
|
||||
webgl = ["iced_wgpu?/webgl"]
|
||||
fira-sans = ["iced_graphics/fira-sans"]
|
||||
custom = []
|
||||
|
||||
[dependencies]
|
||||
iced_graphics.workspace = true
|
||||
|
||||
iced_tiny_skia.workspace = true
|
||||
iced_tiny_skia.optional = true
|
||||
|
||||
iced_wgpu.workspace = true
|
||||
iced_wgpu.optional = true
|
||||
|
|
|
|||
|
|
@ -8,11 +8,7 @@ use crate::graphics;
|
|||
use crate::graphics::compositor;
|
||||
use crate::graphics::mesh;
|
||||
|
||||
pub enum Renderer<L, R>
|
||||
where
|
||||
L: core::Renderer,
|
||||
R: core::Renderer,
|
||||
{
|
||||
pub enum Renderer<L, R> {
|
||||
Left(L),
|
||||
Right(R),
|
||||
}
|
||||
|
|
@ -26,29 +22,6 @@ macro_rules! delegate {
|
|||
};
|
||||
}
|
||||
|
||||
impl<L, R> Renderer<L, R>
|
||||
where
|
||||
L: core::Renderer,
|
||||
R: core::Renderer,
|
||||
{
|
||||
#[cfg(feature = "geometry")]
|
||||
pub fn draw_geometry<Geometry>(
|
||||
&mut self,
|
||||
layers: impl IntoIterator<Item = Geometry>,
|
||||
) where
|
||||
L: graphics::geometry::Renderer,
|
||||
R: graphics::geometry::Renderer,
|
||||
|
||||
Geometry: Into<geometry::Geometry<L::Geometry, R::Geometry>>,
|
||||
{
|
||||
use graphics::geometry::Renderer;
|
||||
|
||||
for layer in layers {
|
||||
<Self as Renderer>::draw_geometry(self, layer.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<L, R> core::Renderer for Renderer<L, R>
|
||||
where
|
||||
L: core::Renderer,
|
||||
|
|
|
|||
|
|
@ -19,27 +19,40 @@ pub use settings::Settings;
|
|||
/// The default graphics renderer for [`iced`].
|
||||
///
|
||||
/// [`iced`]: https://github.com/iced-rs/iced
|
||||
#[cfg(not(feature = "wgpu"))]
|
||||
pub type Renderer = iced_tiny_skia::Renderer;
|
||||
|
||||
/// The default graphics renderer for [`iced`].
|
||||
///
|
||||
/// [`iced`]: https://github.com/iced-rs/iced
|
||||
#[cfg(feature = "wgpu")]
|
||||
pub type Renderer =
|
||||
fallback::Renderer<iced_wgpu::Renderer, iced_tiny_skia::Renderer>;
|
||||
pub type Renderer = renderer::Renderer;
|
||||
|
||||
/// The default graphics compositor for [`iced`].
|
||||
///
|
||||
/// [`iced`]: https://github.com/iced-rs/iced
|
||||
#[cfg(not(feature = "wgpu"))]
|
||||
pub type Compositor = iced_tiny_skia::window::Compositor;
|
||||
pub type Compositor = renderer::Compositor;
|
||||
|
||||
/// The default graphics renderer for [`iced`].
|
||||
///
|
||||
/// [`iced`]: https://github.com/iced-rs/iced
|
||||
#[cfg(feature = "wgpu")]
|
||||
pub type Compositor = fallback::Compositor<
|
||||
iced_wgpu::window::Compositor,
|
||||
iced_tiny_skia::window::Compositor,
|
||||
>;
|
||||
#[cfg(all(feature = "wgpu", feature = "tiny-skia"))]
|
||||
mod renderer {
|
||||
pub type Renderer = crate::fallback::Renderer<
|
||||
iced_wgpu::Renderer,
|
||||
iced_tiny_skia::Renderer,
|
||||
>;
|
||||
|
||||
pub type Compositor = crate::fallback::Compositor<
|
||||
iced_wgpu::window::Compositor,
|
||||
iced_tiny_skia::window::Compositor,
|
||||
>;
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "wgpu", not(feature = "tiny-skia")))]
|
||||
mod renderer {
|
||||
pub type Renderer = iced_wgpu::Renderer;
|
||||
pub type Compositor = iced_wgpu::window::Compositor;
|
||||
}
|
||||
|
||||
#[cfg(all(not(feature = "wgpu"), feature = "tiny-skia"))]
|
||||
mod renderer {
|
||||
pub type Renderer = iced_tiny_skia::Renderer;
|
||||
pub type Compositor = iced_tiny_skia::window::Compositor;
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "wgpu", feature = "tiny-skia")))]
|
||||
mod renderer {
|
||||
pub type Renderer = ();
|
||||
pub type Compositor = ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ impl Default for Settings {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tiny-skia")]
|
||||
impl From<Settings> for iced_tiny_skia::Settings {
|
||||
fn from(settings: Settings) -> Self {
|
||||
Self {
|
||||
|
|
@ -48,3 +49,7 @@ impl From<Settings> for iced_wgpu::Settings {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Settings> for () {
|
||||
fn from(_settings: Settings) -> Self {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ where
|
|||
///
|
||||
/// ```no_run
|
||||
/// # mod iced_wgpu {
|
||||
/// # pub use iced_runtime::core::renderer::Null as Renderer;
|
||||
/// # pub type Renderer = ();
|
||||
/// # }
|
||||
/// #
|
||||
/// # pub struct Counter;
|
||||
|
|
@ -62,7 +62,7 @@ where
|
|||
/// // Initialization
|
||||
/// let mut counter = Counter::new();
|
||||
/// let mut cache = user_interface::Cache::new();
|
||||
/// let mut renderer = Renderer::new();
|
||||
/// let mut renderer = Renderer::default();
|
||||
/// let mut window_size = Size::new(1024.0, 768.0);
|
||||
///
|
||||
/// // Application loop
|
||||
|
|
@ -121,7 +121,7 @@ where
|
|||
///
|
||||
/// ```no_run
|
||||
/// # mod iced_wgpu {
|
||||
/// # pub use iced_runtime::core::renderer::Null as Renderer;
|
||||
/// # pub type Renderer = ();
|
||||
/// # }
|
||||
/// #
|
||||
/// # pub struct Counter;
|
||||
|
|
@ -139,7 +139,7 @@ where
|
|||
///
|
||||
/// let mut counter = Counter::new();
|
||||
/// let mut cache = user_interface::Cache::new();
|
||||
/// let mut renderer = Renderer::new();
|
||||
/// let mut renderer = Renderer::default();
|
||||
/// let mut window_size = Size::new(1024.0, 768.0);
|
||||
/// let mut cursor = mouse::Cursor::default();
|
||||
/// let mut clipboard = clipboard::Null;
|
||||
|
|
@ -374,7 +374,7 @@ where
|
|||
///
|
||||
/// ```no_run
|
||||
/// # mod iced_wgpu {
|
||||
/// # pub use iced_runtime::core::renderer::Null as Renderer;
|
||||
/// # pub type Renderer = ();
|
||||
/// # pub type Theme = ();
|
||||
/// # }
|
||||
/// #
|
||||
|
|
@ -394,7 +394,7 @@ where
|
|||
///
|
||||
/// let mut counter = Counter::new();
|
||||
/// let mut cache = user_interface::Cache::new();
|
||||
/// let mut renderer = Renderer::new();
|
||||
/// let mut renderer = Renderer::default();
|
||||
/// let mut window_size = Size::new(1024.0, 768.0);
|
||||
/// let mut cursor = mouse::Cursor::default();
|
||||
/// let mut clipboard = clipboard::Null;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use crate::graphics::backend;
|
|||
use crate::graphics::text;
|
||||
use crate::graphics::{Damage, Viewport};
|
||||
use crate::primitive::{self, Primitive};
|
||||
use crate::window;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
|
@ -990,6 +991,8 @@ fn rounded_box_sdf(
|
|||
}
|
||||
|
||||
impl iced_graphics::Backend for Backend {
|
||||
type Compositor = window::Compositor;
|
||||
|
||||
type Primitive = primitive::Custom;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use crate::primitive::{self, Primitive};
|
|||
use crate::quad;
|
||||
use crate::text;
|
||||
use crate::triangle;
|
||||
use crate::window;
|
||||
use crate::{Layer, Settings};
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
|
|
@ -372,6 +373,7 @@ impl Backend {
|
|||
}
|
||||
|
||||
impl crate::graphics::Backend for Backend {
|
||||
type Compositor = window::Compositor;
|
||||
type Primitive = primitive::Custom;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//! Draw primitives using custom pipelines.
|
||||
use crate::core::{Rectangle, Size};
|
||||
use crate::core::{self, Rectangle, Size};
|
||||
|
||||
use std::any::{Any, TypeId};
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -58,7 +58,7 @@ pub trait Primitive: Debug + Send + Sync + 'static {
|
|||
}
|
||||
|
||||
/// A renderer than can draw custom pipeline primitives.
|
||||
pub trait Renderer: crate::core::Renderer {
|
||||
pub trait Renderer: core::Renderer {
|
||||
/// Draws a custom pipeline primitive.
|
||||
fn draw_pipeline_primitive(
|
||||
&mut self,
|
||||
|
|
|
|||
|
|
@ -141,7 +141,9 @@ impl<'a, Message, Theme> Widget<Message, Theme, Renderer>
|
|||
renderer.with_translation(
|
||||
bounds.position() - Point::ORIGIN,
|
||||
|renderer| {
|
||||
renderer.draw_geometry(vec![geometry]);
|
||||
use crate::graphics::geometry::Renderer as _;
|
||||
|
||||
renderer.draw_geometry(geometry);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue