Introduce custom backend-specific primitives

This commit is contained in:
Héctor Ramón Jiménez 2023-06-22 00:38:36 +02:00
parent 8d65e40a11
commit 0ae1baa37b
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
28 changed files with 618 additions and 263 deletions

View file

@ -2,7 +2,8 @@ use crate::core;
use crate::core::{Color, Font, Point, Size};
use crate::graphics::backend;
use crate::graphics::color;
use crate::graphics::{Primitive, Transformation, Viewport};
use crate::graphics::{Transformation, Viewport};
use crate::primitive::{self, Primitive};
use crate::quad;
use crate::text;
use crate::triangle;
@ -334,6 +335,10 @@ impl Backend {
}
}
impl crate::graphics::Backend for Backend {
type Primitive = primitive::Custom;
}
impl backend::Text for Backend {
const ICON_FONT: Font = Font::with_name("Iced-Icons");
const CHECKMARK_ICON: char = '\u{f00c}';

View file

@ -5,10 +5,10 @@ use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::{
LineCap, LineDash, LineJoin, Path, Stroke, Style, Text,
};
use crate::graphics::primitive::{self, Primitive};
use crate::graphics::Gradient;
use crate::graphics::gradient::{self, Gradient};
use crate::graphics::primitive;
use crate::Primitive;
use iced_graphics::gradient;
use lyon::geom::euclid;
use lyon::tessellation;
use std::borrow::Cow;

View file

@ -12,8 +12,9 @@ use crate::core;
use crate::core::alignment;
use crate::core::{Color, Font, Point, Rectangle, Size, Vector};
use crate::graphics::color;
use crate::graphics::{Primitive, Viewport};
use crate::graphics::Viewport;
use crate::quad::{self, Quad};
use crate::Primitive;
/// A group of primitives that should be clipped together.
#[derive(Debug)]
@ -262,13 +263,7 @@ impl<'a> Layer<'a> {
current_layer,
);
}
_ => {
// Not supported!
log::warn!(
"Unsupported primitive in `iced_wgpu`: {:?}",
primitive
);
}
Primitive::Custom(()) => {}
}
}
}

View file

@ -24,8 +24,8 @@
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
)]
#![deny(
missing_debug_implementations,
missing_docs,
//missing_debug_implementations,
//missing_docs,
unsafe_code,
unused_results,
clippy::extra_unused_lifetimes,
@ -47,6 +47,7 @@ pub mod geometry;
mod backend;
mod buffer;
mod color;
mod primitive;
mod quad;
mod text;
mod triangle;
@ -60,6 +61,7 @@ pub use wgpu;
pub use backend::Backend;
pub use layer::Layer;
pub use primitive::Primitive;
pub use settings::Settings;
#[cfg(any(feature = "image", feature = "svg"))]

3
wgpu/src/primitive.rs Normal file
View file

@ -0,0 +1,3 @@
pub type Primitive = crate::graphics::Primitive<Custom>;
pub type Custom = ();

View file

@ -3,8 +3,8 @@ use crate::core::{Color, Size};
use crate::graphics;
use crate::graphics::color;
use crate::graphics::compositor;
use crate::graphics::{Error, Primitive, Viewport};
use crate::{Backend, Renderer, Settings};
use crate::graphics::{Error, Viewport};
use crate::{Backend, Primitive, Renderer, Settings};
use futures::stream::{self, StreamExt};