1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
//! Draw using different graphical primitives.
use crate::core::Rectangle;
use crate::custom;
use crate::graphics::{Damage, Mesh};
use std::any::Any;
use std::fmt::Debug;
use std::sync::Arc;
/// The graphical primitives supported by `iced_wgpu`.
pub type Primitive = crate::graphics::Primitive<Custom>;
/// The custom primitives supported by `iced_wgpu`.
#[derive(Debug, Clone, PartialEq)]
pub enum Custom {
/// A mesh primitive.
Mesh(Mesh),
/// A custom shader primitive
Shader(Shader),
}
impl Custom {
/// Create a custom [`Shader`] primitive.
pub fn shader<P: custom::Primitive>(
bounds: Rectangle,
primitive: P,
) -> Self {
Self::Shader(Shader {
bounds,
primitive: Arc::new(primitive),
})
}
}
impl Damage for Custom {
fn bounds(&self) -> Rectangle {
match self {
Self::Mesh(mesh) => mesh.bounds(),
Self::Shader(shader) => shader.bounds,
}
}
}
#[derive(Clone, Debug)]
/// A custom primitive which can be used to render primitives associated with a custom pipeline.
pub struct Shader {
/// The bounds of the [`Shader`].
pub bounds: Rectangle,
/// The [`custom::Primitive`] to render.
pub primitive: Arc<dyn custom::Primitive>,
}
impl PartialEq for Shader {
fn eq(&self, other: &Self) -> bool {
self.primitive.type_id() == other.primitive.type_id()
}
}
|