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::core::{Rectangle, Size};
use crate::Primitive; use crate::Primitive;
use std::sync::Arc; use std::sync::Arc;
/// Computes the damage regions between the two given primitives.
pub fn regions(a: &Primitive, b: &Primitive) -> Vec<Rectangle> { pub fn regions(a: &Primitive, b: &Primitive) -> Vec<Rectangle> {
match (a, b) { 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> { pub fn list(previous: &[Primitive], current: &[Primitive]) -> Vec<Rectangle> {
let damage = previous let damage = previous
.iter() .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( pub fn group(
mut damage: Vec<Rectangle>, mut damage: Vec<Rectangle>,
scale_factor: f32, scale_factor: f32,

View file

@ -16,10 +16,11 @@ pub use stroke::{LineCap, LineDash, LineJoin, Stroke};
pub use style::Style; pub use style::Style;
pub use text::Text; pub use text::Text;
pub use iced_core::gradient::{self, Gradient}; pub use crate::core::gradient::{self, Gradient};
use crate::Primitive; use crate::Primitive;
/// A bunch of shapes that can be drawn.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Geometry(pub Primitive); pub struct Geometry(pub Primitive);
@ -29,8 +30,8 @@ impl From<Geometry> for Primitive {
} }
} }
pub trait Renderer: iced_core::Renderer { /// A renderer capable of drawing some [`Geometry`].
type Geometry; pub trait Renderer: crate::core::Renderer {
/// Draws the given layers of [`Geometry`].
fn draw(&mut self, geometry: Vec<Self::Geometry>); fn draw(&mut self, layers: Vec<Geometry>);
} }

View file

@ -53,11 +53,13 @@ impl Path {
Self::new(|p| p.circle(center, radius)) Self::new(|p| p.circle(center, radius))
} }
/// Returns the internal [`lyon_path::Path`].
#[inline] #[inline]
pub fn raw(&self) -> &lyon_path::Path { pub fn raw(&self) -> &lyon_path::Path {
&self.raw &self.raw
} }
/// Returns the current [`Path`] with the given transform applied to it.
#[inline] #[inline]
pub fn transform(&self, transform: &lyon_path::math::Transform) -> Path { pub fn transform(&self, transform: &lyon_path::math::Transform) -> Path {
Path { Path {

View file

@ -5,6 +5,7 @@ use bitflags::bitflags;
pub use ::image as image_rs; 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> { pub fn load(handle: &Handle) -> image_rs::ImageResult<image_rs::DynamicImage> {
match handle.data() { match handle.data() {
Data::Path(path) => { Data::Path(path) => {

View file

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

View file

@ -1,3 +1,4 @@
//! Draw using different graphical primitives.
use crate::core::alignment; use crate::core::alignment;
use crate::core::image; use crate::core::image;
use crate::core::svg; use crate::core::svg;
@ -90,18 +91,28 @@ pub enum Primitive {
/// The [`Gradient`] to apply to the mesh. /// The [`Gradient`] to apply to the mesh.
gradient: Gradient, gradient: Gradient,
}, },
/// A [`tiny_skia`] path filled with some paint.
#[cfg(feature = "tiny-skia")] #[cfg(feature = "tiny-skia")]
Fill { Fill {
/// The path to fill.
path: tiny_skia::Path, path: tiny_skia::Path,
/// The paint to use.
paint: tiny_skia::Paint<'static>, paint: tiny_skia::Paint<'static>,
/// The fill rule to follow.
rule: tiny_skia::FillRule, rule: tiny_skia::FillRule,
/// The transform to apply to the path.
transform: tiny_skia::Transform, transform: tiny_skia::Transform,
}, },
/// A [`tiny_skia`] path stroked with some paint.
#[cfg(feature = "tiny-skia")] #[cfg(feature = "tiny-skia")]
Stroke { Stroke {
/// The path to stroke.
path: tiny_skia::Path, path: tiny_skia::Path,
/// The paint to use.
paint: tiny_skia::Paint<'static>, paint: tiny_skia::Paint<'static>,
/// The stroke settings.
stroke: tiny_skia::Stroke, stroke: tiny_skia::Stroke,
/// The transform to apply to the path.
transform: tiny_skia::Transform, transform: tiny_skia::Transform,
}, },
/// A group of primitives /// A group of primitives
@ -135,10 +146,12 @@ pub enum Primitive {
} }
impl Primitive { impl Primitive {
/// Creates a [`Primitive::Group`].
pub fn group(primitives: Vec<Self>) -> Self { pub fn group(primitives: Vec<Self>) -> Self {
Self::Group { primitives } Self::Group { primitives }
} }
/// Creates a [`Primitive::Clip`].
pub fn clip(self, bounds: Rectangle) -> Self { pub fn clip(self, bounds: Rectangle) -> Self {
Self::Clip { Self::Clip {
bounds, bounds,
@ -146,6 +159,7 @@ impl Primitive {
} }
} }
/// Creates a [`Primitive::Translate`].
pub fn translate(self, translation: Vector) -> Self { pub fn translate(self, translation: Vector) -> Self {
Self::Translate { Self::Translate {
translation, translation,
@ -153,6 +167,7 @@ impl Primitive {
} }
} }
/// Returns the bounds of the [`Primitive`].
pub fn bounds(&self) -> Rectangle { pub fn bounds(&self) -> Rectangle {
match self { match self {
Self::Text { Self::Text {

View file

@ -235,9 +235,7 @@ impl<B, T> crate::geometry::Renderer for Renderer<B, T>
where where
B: Backend, B: Backend,
{ {
type Geometry = crate::Geometry; fn draw(&mut self, layers: Vec<crate::Geometry>) {
fn draw(&mut self, layers: Vec<Self::Geometry>) {
self.primitives self.primitives
.extend(layers.into_iter().map(crate::Geometry::into)); .extend(layers.into_iter().map(crate::Geometry::into));
} }

View file

@ -2,7 +2,7 @@ use crate::canvas::event::{self, Event};
use crate::canvas::mouse; use crate::canvas::mouse;
use crate::canvas::Cursor; use crate::canvas::Cursor;
use crate::core::Rectangle; use crate::core::Rectangle;
use crate::graphics::geometry; use crate::graphics::geometry::{self, Geometry};
/// The state and logic of a [`Canvas`]. /// The state and logic of a [`Canvas`].
/// ///
@ -52,7 +52,7 @@ where
theme: &Renderer::Theme, theme: &Renderer::Theme,
bounds: Rectangle, bounds: Rectangle,
cursor: Cursor, cursor: Cursor,
) -> Vec<Renderer::Geometry>; ) -> Vec<Geometry>;
/// Returns the current mouse interaction of the [`Program`]. /// Returns the current mouse interaction of the [`Program`].
/// ///
@ -94,7 +94,7 @@ where
theme: &Renderer::Theme, theme: &Renderer::Theme,
bounds: Rectangle, bounds: Rectangle,
cursor: Cursor, cursor: Cursor,
) -> Vec<Renderer::Geometry> { ) -> Vec<Geometry> {
T::draw(self, state, renderer, theme, bounds, cursor) T::draw(self, state, renderer, theme, bounds, cursor)
} }