diff options
| author | 2023-05-30 00:56:52 +0200 | |
|---|---|---|
| committer | 2023-05-30 01:08:34 +0200 | |
| commit | fe9da174cafffbd77eb351c51ba017cf039a4cf4 (patch) | |
| tree | 0921ada9a8907ddfd46a360c21b0fd224d81216c /wgpu/src/layer | |
| parent | eb6c663420a28e087c91c39e376db3c294b5aea1 (diff) | |
| download | iced-fe9da174cafffbd77eb351c51ba017cf039a4cf4.tar.gz iced-fe9da174cafffbd77eb351c51ba017cf039a4cf4.tar.bz2 iced-fe9da174cafffbd77eb351c51ba017cf039a4cf4.zip | |
Move `layer::quad` types to `quad` module
Not sure why I split these to begin with!
Diffstat (limited to '')
| -rw-r--r-- | wgpu/src/layer.rs | 7 | ||||
| -rw-r--r-- | wgpu/src/layer/quad.rs | 149 | 
2 files changed, 3 insertions, 153 deletions
| diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index 4e028eac..1a870c15 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -3,17 +3,16 @@ mod image;  mod text;  pub mod mesh; -pub mod quad;  pub use image::Image;  pub use mesh::Mesh; -pub use quad::Quad;  pub use text::Text;  use crate::core;  use crate::core::alignment;  use crate::core::{Color, Font, Point, Rectangle, Size, Vector};  use crate::graphics::{Primitive, Viewport}; +use crate::quad::{self, Quad};  /// A group of primitives that should be clipped together.  #[derive(Debug)] @@ -22,7 +21,7 @@ pub struct Layer<'a> {      pub bounds: Rectangle,      /// The quads of the [`Layer`]. -    pub quads: quad::Layer, +    pub quads: quad::Batch,      /// The triangle meshes of the [`Layer`].      pub meshes: Vec<Mesh<'a>>, @@ -39,7 +38,7 @@ impl<'a> Layer<'a> {      pub fn new(bounds: Rectangle) -> Self {          Self {              bounds, -            quads: quad::Layer::default(), +            quads: quad::Batch::default(),              meshes: Vec::new(),              text: Vec::new(),              images: Vec::new(), diff --git a/wgpu/src/layer/quad.rs b/wgpu/src/layer/quad.rs deleted file mode 100644 index 284a7618..00000000 --- a/wgpu/src/layer/quad.rs +++ /dev/null @@ -1,149 +0,0 @@ -//! A rectangle with certain styled properties. -use crate::core::{Background, Rectangle}; -use crate::graphics::gradient; -use bytemuck::{Pod, Zeroable}; - -/// The properties of a quad. -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -#[repr(C)] -pub struct Quad { -    /// The position of the [`Quad`]. -    pub position: [f32; 2], - -    /// The size of the [`Quad`]. -    pub size: [f32; 2], - -    /// The border color of the [`Quad`], in __linear RGB__. -    pub border_color: [f32; 4], - -    /// The border radii of the [`Quad`]. -    pub border_radius: [f32; 4], - -    /// The border width of the [`Quad`]. -    pub border_width: f32, -} - -/// A quad filled with a solid color. -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -#[repr(C)] -pub struct Solid { -    /// The background color data of the quad. -    pub color: [f32; 4], - -    /// The [`Quad`] data of the [`Solid`]. -    pub quad: Quad, -} - -/// A quad filled with interpolated colors. -#[derive(Clone, Copy, Debug)] -#[repr(C)] -pub struct Gradient { -    /// The background gradient data of the quad. -    pub gradient: gradient::Packed, - -    /// The [`Quad`] data of the [`Gradient`]. -    pub quad: Quad, -} - -#[allow(unsafe_code)] -unsafe impl Pod for Gradient {} - -#[allow(unsafe_code)] -unsafe impl Zeroable for Gradient {} - -#[derive(Debug, Copy, Clone)] -/// The identifier of a quad, used for ordering. -pub enum Order { -    /// A solid quad -    Solid, -    /// A gradient quad -    Gradient, -} - -/// A group of [`Quad`]s rendered together. -#[derive(Default, Debug)] -pub struct Layer { -    /// The solid quads of the [`Layer`]. -    solids: Vec<Solid>, - -    /// The gradient quads of the [`Layer`]. -    gradients: Vec<Gradient>, - -    /// The quad order of the [`Layer`]; stored as a tuple of the quad type & its count. -    order: Vec<(Order, usize)>, - -    /// The last index of quad ordering. -    index: usize, -} - -impl Layer { -    /// Returns true if there are no quads of any type in [`Quads`]. -    pub fn is_empty(&self) -> bool { -        self.solids.is_empty() && self.gradients.is_empty() -    } - -    /// The [`Solid`] quads of the [`Layer`]. -    pub fn solids(&self) -> &[Solid] { -        &self.solids -    } - -    /// The [`Gradient`] quads of the [`Layer`]. -    pub fn gradients(&self) -> &[Gradient] { -        &self.gradients -    } - -    /// The order of quads within the [`Layer`], grouped by (type, count) for rendering in batches. -    pub fn ordering(&self) -> &[(Order, usize)] { -        &self.order -    } - -    /// Adds a [`Quad`] with the provided `Background` type to the quad [`Layer`]. -    pub fn add(&mut self, quad: Quad, background: &Background) { -        let quad_order = match background { -            Background::Color(color) => { -                self.solids.push(Solid { -                    color: color.into_linear(), -                    quad, -                }); - -                Order::Solid -            } -            Background::Gradient(gradient) => { -                let quad = Gradient { -                    gradient: gradient::pack( -                        gradient, -                        Rectangle::new(quad.position.into(), quad.size.into()), -                    ), -                    quad, -                }; - -                self.gradients.push(quad); -                Order::Gradient -            } -        }; - -        match (self.order.get_mut(self.index), quad_order) { -            (Some((quad_order, count)), Order::Solid) => match quad_order { -                Order::Solid => { -                    *count += 1; -                } -                Order::Gradient => { -                    self.order.push((Order::Solid, 1)); -                    self.index += 1; -                } -            }, -            (Some((quad_order, count)), Order::Gradient) => match quad_order { -                Order::Solid => { -                    self.order.push((Order::Gradient, 1)); -                    self.index += 1; -                } -                Order::Gradient => { -                    *count += 1; -                } -            }, -            (None, _) => { -                self.order.push((quad_order, 1)); -            } -        } -    } -} | 
