From 0ae1baa37bd7b6607f79b33b8a6d8c5daafde0b2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 22 Jun 2023 00:38:36 +0200 Subject: Introduce custom backend-specific primitives --- graphics/src/backend.rs | 7 +++ graphics/src/damage.rs | 68 +++++++++++++++++++++++++++-- graphics/src/geometry.rs | 16 ++----- graphics/src/lib.rs | 9 ++-- graphics/src/primitive.rs | 107 ++++------------------------------------------ graphics/src/renderer.rs | 70 ++++++++++++++++++------------ 6 files changed, 129 insertions(+), 148 deletions(-) (limited to 'graphics/src') diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs index 70ccc664..3ff24335 100644 --- a/graphics/src/backend.rs +++ b/graphics/src/backend.rs @@ -6,6 +6,13 @@ use iced_core::{Font, Point, Size}; use std::borrow::Cow; +/// The graphics backend of a [`Renderer`]. +/// +/// [`Renderer`]: crate::Renderer +pub trait Backend { + type Primitive; +} + /// A graphics backend that supports text rendering. pub trait Text { /// The icon font of the backend. diff --git a/graphics/src/damage.rs b/graphics/src/damage.rs index c6b0f759..1add6707 100644 --- a/graphics/src/damage.rs +++ b/graphics/src/damage.rs @@ -1,11 +1,68 @@ //! Track and compute the damage of graphical primitives. +use crate::core::alignment; use crate::core::{Rectangle, Size}; use crate::Primitive; use std::sync::Arc; -/// Computes the damage regions between the two given primitives. -pub fn regions(a: &Primitive, b: &Primitive) -> Vec { +pub trait Damage: PartialEq { + /// Returns the bounds of the [`Damage`]. + fn bounds(&self) -> Rectangle; +} + +impl Damage for Primitive { + fn bounds(&self) -> Rectangle { + match self { + Self::Text { + bounds, + horizontal_alignment, + vertical_alignment, + .. + } => { + let mut bounds = *bounds; + + bounds.x = match horizontal_alignment { + alignment::Horizontal::Left => bounds.x, + alignment::Horizontal::Center => { + bounds.x - bounds.width / 2.0 + } + alignment::Horizontal::Right => bounds.x - bounds.width, + }; + + bounds.y = match vertical_alignment { + alignment::Vertical::Top => bounds.y, + alignment::Vertical::Center => { + bounds.y - bounds.height / 2.0 + } + alignment::Vertical::Bottom => bounds.y - bounds.height, + }; + + bounds.expand(1.5) + } + Self::Quad { bounds, .. } + | Self::Image { bounds, .. } + | Self::Svg { bounds, .. } => bounds.expand(1.0), + Self::Clip { bounds, .. } => bounds.expand(1.0), + Self::SolidMesh { size, .. } | Self::GradientMesh { size, .. } => { + Rectangle::with_size(*size) + } + Self::Group { primitives } => primitives + .iter() + .map(Self::bounds) + .fold(Rectangle::with_size(Size::ZERO), |a, b| { + Rectangle::union(&a, &b) + }), + Self::Translate { + translation, + content, + } => content.bounds() + *translation, + Self::Cache { content } => content.bounds(), + Self::Custom(custom) => custom.bounds(), + } + } +} + +fn regions(a: &Primitive, b: &Primitive) -> Vec { match (a, b) { ( Primitive::Group { @@ -76,7 +133,10 @@ pub fn regions(a: &Primitive, b: &Primitive) -> Vec { } /// Computes the damage regions between the two given lists of primitives. -pub fn list(previous: &[Primitive], current: &[Primitive]) -> Vec { +pub fn list( + previous: &[Primitive], + current: &[Primitive], +) -> Vec { let damage = previous .iter() .zip(current) @@ -93,7 +153,7 @@ pub fn list(previous: &[Primitive], current: &[Primitive]) -> Vec { // Extend damage by the added/removed primitives damage - .chain(bigger[smaller.len()..].iter().map(Primitive::bounds)) + .chain(bigger[smaller.len()..].iter().map(Damage::bounds)) .collect() } } diff --git a/graphics/src/geometry.rs b/graphics/src/geometry.rs index 729c3d44..5e547bae 100644 --- a/graphics/src/geometry.rs +++ b/graphics/src/geometry.rs @@ -14,20 +14,10 @@ pub use text::Text; pub use crate::gradient::{self, Gradient}; -use crate::Primitive; - -/// A bunch of shapes that can be drawn. -#[derive(Debug, Clone)] -pub struct Geometry(pub Primitive); - -impl From for Primitive { - fn from(geometry: Geometry) -> Self { - geometry.0 - } -} - /// A renderer capable of drawing some [`Geometry`]. pub trait Renderer: crate::core::Renderer { + type Geometry; + /// Draws the given layers of [`Geometry`]. - fn draw(&mut self, layers: Vec); + fn draw(&mut self, layers: Vec); } diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index 226b245b..055a9216 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -8,8 +8,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, @@ -41,7 +41,9 @@ pub mod geometry; pub mod image; pub use antialiasing::Antialiasing; +pub use backend::Backend; pub use compositor::Compositor; +pub use damage::Damage; pub use error::Error; pub use gradient::Gradient; pub use primitive::Primitive; @@ -49,7 +51,4 @@ pub use renderer::Renderer; pub use transformation::Transformation; pub use viewport::Viewport; -#[cfg(feature = "geometry")] -pub use geometry::Geometry; - pub use iced_core as core; diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 187c6c6c..f8b005ad 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -12,8 +12,7 @@ use std::sync::Arc; /// A rendering primitive. #[derive(Debug, Clone, PartialEq)] -#[non_exhaustive] -pub enum Primitive { +pub enum Primitive { /// A text primitive Text { /// The contents of the text @@ -90,41 +89,17 @@ pub enum Primitive { /// Any geometry that falls out of this region will be clipped. size: Size, }, - /// A [`tiny_skia`] path filled with some paint. - #[cfg(feature = "tiny-skia")] - Fill { - /// The path to fill. - path: tiny_skia::Path, - /// The paint to use. - paint: tiny_skia::Paint<'static>, - /// The fill rule to follow. - rule: tiny_skia::FillRule, - /// The transform to apply to the path. - transform: tiny_skia::Transform, - }, - /// A [`tiny_skia`] path stroked with some paint. - #[cfg(feature = "tiny-skia")] - Stroke { - /// The path to stroke. - path: tiny_skia::Path, - /// The paint to use. - paint: tiny_skia::Paint<'static>, - /// The stroke settings. - stroke: tiny_skia::Stroke, - /// The transform to apply to the path. - transform: tiny_skia::Transform, - }, /// A group of primitives Group { /// The primitives of the group - primitives: Vec, + primitives: Vec>, }, /// A clip primitive Clip { /// The bounds of the clip bounds: Rectangle, /// The content of the clip - content: Box, + content: Box>, }, /// A primitive that applies a translation Translate { @@ -132,7 +107,7 @@ pub enum Primitive { translation: Vector, /// The primitive to translate - content: Box, + content: Box>, }, /// A cached primitive. /// @@ -140,11 +115,13 @@ pub enum Primitive { /// generation is expensive. Cache { /// The cached primitive - content: Arc, + content: Arc>, }, + /// A backend-specific primitive. + Custom(T), } -impl Primitive { +impl Primitive { /// Creates a [`Primitive::Group`]. pub fn group(primitives: Vec) -> Self { Self::Group { primitives } @@ -165,68 +142,6 @@ impl Primitive { content: Box::new(self), } } - - /// Returns the bounds of the [`Primitive`]. - pub fn bounds(&self) -> Rectangle { - match self { - Self::Text { - bounds, - horizontal_alignment, - vertical_alignment, - .. - } => { - let mut bounds = *bounds; - - bounds.x = match horizontal_alignment { - alignment::Horizontal::Left => bounds.x, - alignment::Horizontal::Center => { - bounds.x - bounds.width / 2.0 - } - alignment::Horizontal::Right => bounds.x - bounds.width, - }; - - bounds.y = match vertical_alignment { - alignment::Vertical::Top => bounds.y, - alignment::Vertical::Center => { - bounds.y - bounds.height / 2.0 - } - alignment::Vertical::Bottom => bounds.y - bounds.height, - }; - - bounds.expand(1.5) - } - Self::Quad { bounds, .. } - | Self::Image { bounds, .. } - | Self::Svg { bounds, .. } => bounds.expand(1.0), - Self::Clip { bounds, .. } => bounds.expand(1.0), - Self::SolidMesh { size, .. } | Self::GradientMesh { size, .. } => { - Rectangle::with_size(*size) - } - #[cfg(feature = "tiny-skia")] - Self::Fill { path, .. } | Self::Stroke { path, .. } => { - let bounds = path.bounds(); - - Rectangle { - x: bounds.x(), - y: bounds.y(), - width: bounds.width(), - height: bounds.height(), - } - .expand(1.0) - } - Self::Group { primitives } => primitives - .iter() - .map(Self::bounds) - .fold(Rectangle::with_size(Size::ZERO), |a, b| { - Rectangle::union(&a, &b) - }), - Self::Translate { - translation, - content, - } => content.bounds() + *translation, - Self::Cache { content } => content.bounds(), - } - } } /// A set of [`Vertex2D`] and indices representing a list of triangles. @@ -268,9 +183,3 @@ unsafe impl Zeroable for GradientVertex2D {} #[allow(unsafe_code)] unsafe impl Pod for GradientVertex2D {} - -impl From<()> for Primitive { - fn from(_: ()) -> Self { - Self::Group { primitives: vec![] } - } -} diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index 7e70a766..9acfc2b7 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -1,5 +1,5 @@ //! Create a renderer from a [`Backend`]. -use crate::backend; +use crate::backend::{self, Backend}; use crate::Primitive; use iced_core::image; @@ -16,13 +16,13 @@ use std::marker::PhantomData; /// A backend-agnostic renderer that supports all the built-in widgets. #[derive(Debug)] -pub struct Renderer { +pub struct Renderer { backend: B, - primitives: Vec, + primitives: Vec>, theme: PhantomData, } -impl Renderer { +impl Renderer { /// Creates a new [`Renderer`] from the given [`Backend`]. pub fn new(backend: B) -> Self { Self { @@ -38,7 +38,7 @@ impl Renderer { } /// Enqueues the given [`Primitive`] in the [`Renderer`] for drawing. - pub fn draw_primitive(&mut self, primitive: Primitive) { + pub fn draw_primitive(&mut self, primitive: Primitive) { self.primitives.push(primitive); } @@ -46,13 +46,42 @@ impl Renderer { /// of the [`Renderer`]. pub fn with_primitives( &mut self, - f: impl FnOnce(&mut B, &[Primitive]) -> O, + f: impl FnOnce(&mut B, &[Primitive]) -> O, ) -> O { f(&mut self.backend, &self.primitives) } + + pub fn start_layer(&mut self) -> Vec> { + std::mem::take(&mut self.primitives) + } + + pub fn end_layer( + &mut self, + primitives: Vec>, + bounds: Rectangle, + ) { + let layer = std::mem::replace(&mut self.primitives, primitives); + + self.primitives.push(Primitive::group(layer).clip(bounds)); + } + + pub fn start_translation(&mut self) -> Vec> { + std::mem::take(&mut self.primitives) + } + + pub fn end_translation( + &mut self, + primitives: Vec>, + translation: Vector, + ) { + let layer = std::mem::replace(&mut self.primitives, primitives); + + self.primitives + .push(Primitive::group(layer).translate(translation)); + } } -impl iced_core::Renderer for Renderer { +impl iced_core::Renderer for Renderer { type Theme = T; fn layout( @@ -64,13 +93,11 @@ impl iced_core::Renderer for Renderer { } fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) { - let current = std::mem::take(&mut self.primitives); + let current = self.start_layer(); f(self); - let layer = std::mem::replace(&mut self.primitives, current); - - self.primitives.push(Primitive::group(layer).clip(bounds)); + self.end_layer(current, bounds); } fn with_translation( @@ -78,14 +105,11 @@ impl iced_core::Renderer for Renderer { translation: Vector, f: impl FnOnce(&mut Self), ) { - let current = std::mem::take(&mut self.primitives); + let current = self.start_translation(); f(self); - let layer = std::mem::replace(&mut self.primitives, current); - - self.primitives - .push(Primitive::group(layer).translate(translation)); + self.end_translation(current, translation); } fn fill_quad( @@ -109,7 +133,7 @@ impl iced_core::Renderer for Renderer { impl text::Renderer for Renderer where - B: backend::Text, + B: Backend + backend::Text, { type Font = Font; @@ -188,7 +212,7 @@ where impl image::Renderer for Renderer where - B: backend::Image, + B: Backend + backend::Image, { type Handle = image::Handle; @@ -203,7 +227,7 @@ where impl svg::Renderer for Renderer where - B: backend::Svg, + B: Backend + backend::Svg, { fn dimensions(&self, handle: &svg::Handle) -> Size { self.backend().viewport_dimensions(handle) @@ -222,11 +246,3 @@ where }) } } - -#[cfg(feature = "geometry")] -impl crate::geometry::Renderer for Renderer { - fn draw(&mut self, layers: Vec) { - self.primitives - .extend(layers.into_iter().map(crate::Geometry::into)); - } -} -- cgit From 2128472c2a8afcb59927712497c4f613612e9dcc Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 22 Jun 2023 01:04:07 +0200 Subject: Remove `layout` method from `core::Renderer` trait --- graphics/src/renderer.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'graphics/src') diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index 9acfc2b7..459faf40 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -3,13 +3,10 @@ use crate::backend::{self, Backend}; use crate::Primitive; use iced_core::image; -use iced_core::layout; use iced_core::renderer; use iced_core::svg; use iced_core::text::{self, Text}; -use iced_core::{ - Background, Color, Element, Font, Point, Rectangle, Size, Vector, -}; +use iced_core::{Background, Color, Font, Point, Rectangle, Size, Vector}; use std::borrow::Cow; use std::marker::PhantomData; @@ -84,14 +81,6 @@ impl Renderer { impl iced_core::Renderer for Renderer { type Theme = T; - fn layout( - &mut self, - element: &Element<'_, Message, Self>, - limits: &layout::Limits, - ) -> layout::Node { - element.as_widget().layout(self, limits) - } - fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) { let current = self.start_layer(); -- cgit From fa5650cfd1115e6ccec2ad795cf58fd970d5b43c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 29 Jun 2023 07:48:03 +0200 Subject: Decouple `Mesh` primitives from main `Primitive` type --- graphics/src/damage.rs | 3 -- graphics/src/gradient.rs | 3 +- graphics/src/lib.rs | 2 ++ graphics/src/mesh.rs | 75 +++++++++++++++++++++++++++++++++++++++++++++++ graphics/src/primitive.rs | 69 +------------------------------------------ 5 files changed, 80 insertions(+), 72 deletions(-) create mode 100644 graphics/src/mesh.rs (limited to 'graphics/src') diff --git a/graphics/src/damage.rs b/graphics/src/damage.rs index 1add6707..be17b935 100644 --- a/graphics/src/damage.rs +++ b/graphics/src/damage.rs @@ -43,9 +43,6 @@ impl Damage for Primitive { | Self::Image { bounds, .. } | Self::Svg { bounds, .. } => bounds.expand(1.0), Self::Clip { bounds, .. } => bounds.expand(1.0), - Self::SolidMesh { size, .. } | Self::GradientMesh { size, .. } => { - Rectangle::with_size(*size) - } Self::Group { primitives } => primitives .iter() .map(Self::bounds) diff --git a/graphics/src/gradient.rs b/graphics/src/gradient.rs index 3f5d0509..4db565d8 100644 --- a/graphics/src/gradient.rs +++ b/graphics/src/gradient.rs @@ -7,6 +7,7 @@ use crate::color; use crate::core::gradient::ColorStop; use crate::core::{self, Color, Point, Rectangle}; +use bytemuck::{Pod, Zeroable}; use half::f16; use std::cmp::Ordering; @@ -135,7 +136,7 @@ impl Linear { } /// Packed [`Gradient`] data for use in shader code. -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Zeroable, Pod)] #[repr(C)] pub struct Packed { // 8 colors, each channel = 16 bit float, 2 colors packed into 1 u32 diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index 055a9216..cef36003 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -31,6 +31,7 @@ pub mod color; pub mod compositor; pub mod damage; pub mod gradient; +pub mod mesh; pub mod primitive; pub mod renderer; @@ -46,6 +47,7 @@ pub use compositor::Compositor; pub use damage::Damage; pub use error::Error; pub use gradient::Gradient; +pub use mesh::Mesh; pub use primitive::Primitive; pub use renderer::Renderer; pub use transformation::Transformation; diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs new file mode 100644 index 00000000..6ca7f79f --- /dev/null +++ b/graphics/src/mesh.rs @@ -0,0 +1,75 @@ +use crate::color; +use crate::core::{Rectangle, Size}; +use crate::gradient; +use crate::Damage; + +use bytemuck::{Pod, Zeroable}; + +/// A low-level primitive to render a mesh of triangles. +#[derive(Debug, Clone, PartialEq)] +pub enum Mesh { + /// A mesh with a solid color. + Solid { + /// The vertices and indices of the mesh. + buffers: Indexed, + + /// The size of the drawable region of the mesh. + /// + /// Any geometry that falls out of this region will be clipped. + size: Size, + }, + /// A mesh with a gradient. + Gradient { + /// The vertices and indices of the mesh. + buffers: Indexed, + + /// The size of the drawable region of the mesh. + /// + /// Any geometry that falls out of this region will be clipped. + size: Size, + }, +} + +impl Damage for Mesh { + fn bounds(&self) -> Rectangle { + match self { + Self::Solid { size, .. } | Self::Gradient { size, .. } => { + Rectangle::with_size(*size) + } + } + } +} + +/// A set of [`Vertex2D`] and indices representing a list of triangles. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Indexed { + /// The vertices of the mesh + pub vertices: Vec, + + /// The list of vertex indices that defines the triangles of the mesh. + /// + /// Therefore, this list should always have a length that is a multiple of 3. + pub indices: Vec, +} + +/// A two-dimensional vertex with a color. +#[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)] +#[repr(C)] +pub struct SolidVertex2D { + /// The vertex position in 2D space. + pub position: [f32; 2], + + /// The color of the vertex in __linear__ RGBA. + pub color: color::Packed, +} + +/// A vertex which contains 2D position & packed gradient data. +#[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)] +#[repr(C)] +pub struct GradientVertex2D { + /// The vertex position in 2D space. + pub position: [f32; 2], + + /// The packed vertex data of the gradient. + pub gradient: gradient::Packed, +} diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index f8b005ad..7592a410 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -1,13 +1,10 @@ //! Draw using different graphical primitives. -use crate::color; use crate::core::alignment; use crate::core::image; use crate::core::svg; use crate::core::text; -use crate::core::{Background, Color, Font, Rectangle, Size, Vector}; -use crate::gradient; +use crate::core::{Background, Color, Font, Rectangle, Vector}; -use bytemuck::{Pod, Zeroable}; use std::sync::Arc; /// A rendering primitive. @@ -65,30 +62,6 @@ pub enum Primitive { /// The bounds of the viewport bounds: Rectangle, }, - /// A low-level primitive to render a mesh of triangles with a solid color. - /// - /// It can be used to render many kinds of geometry freely. - SolidMesh { - /// The vertices and indices of the mesh. - buffers: Mesh2D, - - /// The size of the drawable region of the mesh. - /// - /// Any geometry that falls out of this region will be clipped. - size: Size, - }, - /// A low-level primitive to render a mesh of triangles with a gradient. - /// - /// It can be used to render many kinds of geometry freely. - GradientMesh { - /// The vertices and indices of the mesh. - buffers: Mesh2D, - - /// The size of the drawable region of the mesh. - /// - /// Any geometry that falls out of this region will be clipped. - size: Size, - }, /// A group of primitives Group { /// The primitives of the group @@ -143,43 +116,3 @@ impl Primitive { } } } - -/// A set of [`Vertex2D`] and indices representing a list of triangles. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct Mesh2D { - /// The vertices of the mesh - pub vertices: Vec, - - /// The list of vertex indices that defines the triangles of the mesh. - /// - /// Therefore, this list should always have a length that is a multiple of 3. - pub indices: Vec, -} - -/// A two-dimensional vertex with a color. -#[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)] -#[repr(C)] -pub struct ColoredVertex2D { - /// The vertex position in 2D space. - pub position: [f32; 2], - - /// The color of the vertex in __linear__ RGBA. - pub color: color::Packed, -} - -/// A vertex which contains 2D position & packed gradient data. -#[derive(Copy, Clone, Debug, PartialEq)] -#[repr(C)] -pub struct GradientVertex2D { - /// The vertex position in 2D space. - pub position: [f32; 2], - - /// The packed vertex data of the gradient. - pub gradient: gradient::Packed, -} - -#[allow(unsafe_code)] -unsafe impl Zeroable for GradientVertex2D {} - -#[allow(unsafe_code)] -unsafe impl Pod for GradientVertex2D {} -- cgit From 6921564c9f66e8103e19ec658099c5f5c32e8cc5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 29 Jun 2023 07:55:52 +0200 Subject: Write missing docs in `iced_graphics` and `iced_wgpu` --- graphics/src/backend.rs | 1 + graphics/src/damage.rs | 1 + graphics/src/geometry.rs | 1 + graphics/src/lib.rs | 6 +++--- graphics/src/mesh.rs | 1 + graphics/src/renderer.rs | 4 ++++ 6 files changed, 11 insertions(+), 3 deletions(-) (limited to 'graphics/src') diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs index 3ff24335..77bb650b 100644 --- a/graphics/src/backend.rs +++ b/graphics/src/backend.rs @@ -10,6 +10,7 @@ use std::borrow::Cow; /// /// [`Renderer`]: crate::Renderer pub trait Backend { + /// The custom kind of primitives this [`Backend`] supports. type Primitive; } diff --git a/graphics/src/damage.rs b/graphics/src/damage.rs index be17b935..2f29956e 100644 --- a/graphics/src/damage.rs +++ b/graphics/src/damage.rs @@ -5,6 +5,7 @@ use crate::Primitive; use std::sync::Arc; +/// A type that has some damage bounds. pub trait Damage: PartialEq { /// Returns the bounds of the [`Damage`]. fn bounds(&self) -> Rectangle; diff --git a/graphics/src/geometry.rs b/graphics/src/geometry.rs index 5e547bae..7cd3dd3a 100644 --- a/graphics/src/geometry.rs +++ b/graphics/src/geometry.rs @@ -16,6 +16,7 @@ pub use crate::gradient::{self, Gradient}; /// A renderer capable of drawing some [`Geometry`]. pub trait Renderer: crate::core::Renderer { + /// The kind of geometry this renderer can draw. type Geometry; /// Draws the given layers of [`Geometry`]. diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index cef36003..af374a2f 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -8,8 +8,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, @@ -23,6 +23,7 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] mod antialiasing; mod error; +mod primitive; mod transformation; mod viewport; @@ -32,7 +33,6 @@ pub mod compositor; pub mod damage; pub mod gradient; pub mod mesh; -pub mod primitive; pub mod renderer; #[cfg(feature = "geometry")] diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs index 6ca7f79f..cfb5a60f 100644 --- a/graphics/src/mesh.rs +++ b/graphics/src/mesh.rs @@ -1,3 +1,4 @@ +//! Draw triangles! use crate::color; use crate::core::{Rectangle, Size}; use crate::gradient; diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index 459faf40..d80dea34 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -48,10 +48,12 @@ impl Renderer { f(&mut self.backend, &self.primitives) } + /// Starts recording a new layer. pub fn start_layer(&mut self) -> Vec> { std::mem::take(&mut self.primitives) } + /// Ends the recording of a layer. pub fn end_layer( &mut self, primitives: Vec>, @@ -62,10 +64,12 @@ impl Renderer { self.primitives.push(Primitive::group(layer).clip(bounds)); } + /// Starts recording a translation. pub fn start_translation(&mut self) -> Vec> { std::mem::take(&mut self.primitives) } + /// Ends the recording of a translation. pub fn end_translation( &mut self, primitives: Vec>, -- cgit