diff options
author | 2023-05-11 15:25:58 +0200 | |
---|---|---|
committer | 2023-05-11 15:25:58 +0200 | |
commit | 8622e998f2701e7f4ca8d2f71c85150f436a9945 (patch) | |
tree | de62eead3db44002997b83849711533b214aae31 /graphics | |
parent | dd04c0b070b60b15293892e2a7c284787d3d63b1 (diff) | |
download | iced-8622e998f2701e7f4ca8d2f71c85150f436a9945.tar.gz iced-8622e998f2701e7f4ca8d2f71c85150f436a9945.tar.bz2 iced-8622e998f2701e7f4ca8d2f71c85150f436a9945.zip |
Write missing documentation in `iced_graphics`
Diffstat (limited to '')
-rw-r--r-- | graphics/src/damage.rs | 5 | ||||
-rw-r--r-- | graphics/src/geometry.rs | 11 | ||||
-rw-r--r-- | graphics/src/geometry/path.rs | 2 | ||||
-rw-r--r-- | graphics/src/image.rs | 1 | ||||
-rw-r--r-- | graphics/src/lib.rs | 2 | ||||
-rw-r--r-- | graphics/src/primitive.rs | 15 | ||||
-rw-r--r-- | graphics/src/renderer.rs | 4 |
7 files changed, 31 insertions, 9 deletions
diff --git a/graphics/src/damage.rs b/graphics/src/damage.rs index 5aab06b1..c6b0f759 100644 --- a/graphics/src/damage.rs +++ b/graphics/src/damage.rs @@ -1,8 +1,10 @@ +//! Track and compute the damage of graphical primitives. 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<Rectangle> { match (a, b) { ( @@ -73,6 +75,7 @@ pub fn regions(a: &Primitive, b: &Primitive) -> Vec<Rectangle> { } } +/// Computes the damage regions between the two given lists of primitives. pub fn list(previous: &[Primitive], current: &[Primitive]) -> Vec<Rectangle> { let damage = previous .iter() @@ -95,6 +98,8 @@ pub fn list(previous: &[Primitive], current: &[Primitive]) -> Vec<Rectangle> { } } +/// Groups the given damage regions that are close together inside the given +/// bounds. pub fn group( mut damage: Vec<Rectangle>, scale_factor: f32, diff --git a/graphics/src/geometry.rs b/graphics/src/geometry.rs index 8db1594a..1f3d2c01 100644 --- a/graphics/src/geometry.rs +++ b/graphics/src/geometry.rs @@ -16,10 +16,11 @@ pub use stroke::{LineCap, LineDash, LineJoin, Stroke}; pub use style::Style; pub use text::Text; -pub use iced_core::gradient::{self, Gradient}; +pub use crate::core::gradient::{self, Gradient}; use crate::Primitive; +/// A bunch of shapes that can be drawn. #[derive(Debug, Clone)] pub struct Geometry(pub Primitive); @@ -29,8 +30,8 @@ impl From<Geometry> for Primitive { } } -pub trait Renderer: iced_core::Renderer { - type Geometry; - - fn draw(&mut self, geometry: Vec<Self::Geometry>); +/// A renderer capable of drawing some [`Geometry`]. +pub trait Renderer: crate::core::Renderer { + /// Draws the given layers of [`Geometry`]. + fn draw(&mut self, layers: Vec<Geometry>); } diff --git a/graphics/src/geometry/path.rs b/graphics/src/geometry/path.rs index c3127bdf..3d8fc6fa 100644 --- a/graphics/src/geometry/path.rs +++ b/graphics/src/geometry/path.rs @@ -53,11 +53,13 @@ impl Path { Self::new(|p| p.circle(center, radius)) } + /// Returns the internal [`lyon_path::Path`]. #[inline] pub fn raw(&self) -> &lyon_path::Path { &self.raw } + /// Returns the current [`Path`] with the given transform applied to it. #[inline] pub fn transform(&self, transform: &lyon_path::math::Transform) -> Path { Path { diff --git a/graphics/src/image.rs b/graphics/src/image.rs index 2f634252..6b43f4a8 100644 --- a/graphics/src/image.rs +++ b/graphics/src/image.rs @@ -5,6 +5,7 @@ use bitflags::bitflags; pub use ::image as image_rs; +/// Tries to load an image by its [`Handle`]. pub fn load(handle: &Handle) -> image_rs::ImageResult<image_rs::DynamicImage> { match handle.data() { Data::Path(path) => { diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index e3de4025..91f50282 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -9,7 +9,7 @@ )] #![deny( missing_debug_implementations, - //missing_docs, + missing_docs, unsafe_code, unused_results, clippy::extra_unused_lifetimes, diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index d814c757..d4446c87 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -1,3 +1,4 @@ +//! Draw using different graphical primitives. use crate::core::alignment; use crate::core::image; use crate::core::svg; @@ -90,18 +91,28 @@ pub enum Primitive { /// The [`Gradient`] to apply to the mesh. gradient: Gradient, }, + /// 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 @@ -135,10 +146,12 @@ pub enum Primitive { } impl Primitive { + /// Creates a [`Primitive::Group`]. pub fn group(primitives: Vec<Self>) -> Self { Self::Group { primitives } } + /// Creates a [`Primitive::Clip`]. pub fn clip(self, bounds: Rectangle) -> Self { Self::Clip { bounds, @@ -146,6 +159,7 @@ impl Primitive { } } + /// Creates a [`Primitive::Translate`]. pub fn translate(self, translation: Vector) -> Self { Self::Translate { translation, @@ -153,6 +167,7 @@ impl Primitive { } } + /// Returns the bounds of the [`Primitive`]. pub fn bounds(&self) -> Rectangle { match self { Self::Text { diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index aaf1737a..de905503 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -235,9 +235,7 @@ impl<B, T> crate::geometry::Renderer for Renderer<B, T> where B: Backend, { - type Geometry = crate::Geometry; - - fn draw(&mut self, layers: Vec<Self::Geometry>) { + fn draw(&mut self, layers: Vec<crate::Geometry>) { self.primitives .extend(layers.into_iter().map(crate::Geometry::into)); } |