Re-organize custom module as pipeline module
... and move `Shader` widget to `iced_widget` crate
This commit is contained in:
parent
2dda9132cd
commit
9489e29e66
14 changed files with 246 additions and 197 deletions
|
|
@ -1,10 +1,12 @@
|
|||
//! Draw using different graphical primitives.
|
||||
pub mod pipeline;
|
||||
|
||||
pub use pipeline::Pipeline;
|
||||
|
||||
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>;
|
||||
|
|
@ -14,44 +16,15 @@ pub type Primitive = crate::graphics::Primitive<Custom>;
|
|||
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),
|
||||
})
|
||||
}
|
||||
/// A custom pipeline primitive.
|
||||
Pipeline(Pipeline),
|
||||
}
|
||||
|
||||
impl Damage for Custom {
|
||||
fn bounds(&self) -> Rectangle {
|
||||
match self {
|
||||
Self::Mesh(mesh) => mesh.bounds(),
|
||||
Self::Shader(shader) => shader.bounds,
|
||||
Self::Pipeline(pipeline) => pipeline.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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue