Write missing documentation in iced_graphics

This commit is contained in:
Héctor Ramón Jiménez 2023-05-11 15:25:58 +02:00
parent dd04c0b070
commit 8622e998f2
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
8 changed files with 34 additions and 12 deletions

View file

@ -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,

View file

@ -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>);
}

View file

@ -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 {

View file

@ -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) => {

View file

@ -9,7 +9,7 @@
)]
#![deny(
missing_debug_implementations,
//missing_docs,
missing_docs,
unsafe_code,
unused_results,
clippy::extra_unused_lifetimes,

View file

@ -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 {

View file

@ -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));
}