Fix broken links in documentation
This commit is contained in:
parent
53a183fe0d
commit
85800c99ab
9 changed files with 73 additions and 54 deletions
33
graphics/src/cached.rs
Normal file
33
graphics/src/cached.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use crate::Primitive;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
/// A piece of data that can be cached.
|
||||
pub trait Cached: Sized {
|
||||
/// The type of cache produced.
|
||||
type Cache;
|
||||
|
||||
/// Loads the [`Cache`] into a proper instance.
|
||||
///
|
||||
/// [`Cache`]: Self::Cache
|
||||
fn load(cache: &Self::Cache) -> Self;
|
||||
|
||||
/// Caches this value, producing its corresponding [`Cache`].
|
||||
///
|
||||
/// [`Cache`]: Self::Cache
|
||||
fn cache(self) -> Self::Cache;
|
||||
}
|
||||
|
||||
impl<T> Cached for Primitive<T> {
|
||||
type Cache = Arc<Self>;
|
||||
|
||||
fn load(cache: &Arc<Self>) -> Self {
|
||||
Self::Cache {
|
||||
content: cache.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn cache(self) -> Arc<Self> {
|
||||
Arc::new(self)
|
||||
}
|
||||
}
|
||||
|
|
@ -19,32 +19,28 @@ pub use text::Text;
|
|||
pub use crate::gradient::{self, Gradient};
|
||||
|
||||
use crate::core::Size;
|
||||
use crate::Cached;
|
||||
|
||||
/// A renderer capable of drawing some [`Self::Geometry`].
|
||||
pub trait Renderer: crate::core::Renderer {
|
||||
/// The kind of geometry this renderer can draw.
|
||||
type Geometry: Geometry;
|
||||
type Geometry: Cached;
|
||||
|
||||
/// The kind of [`Frame`] this renderer supports.
|
||||
type Frame: frame::Backend<Geometry = Self::Geometry>;
|
||||
|
||||
/// Creates a new [`Self::Frame`].
|
||||
fn new_frame(&self, size: Size) -> Self::Frame;
|
||||
|
||||
/// Draws the given [`Self::Geometry`].
|
||||
fn draw_geometry(&mut self, geometry: Self::Geometry);
|
||||
}
|
||||
|
||||
/// The graphics backend of a geometry renderer.
|
||||
pub trait Backend {
|
||||
/// The kind of [`Frame`] this backend supports.
|
||||
type Frame: frame::Backend;
|
||||
|
||||
/// Creates a new [`Self::Frame`].
|
||||
fn new_frame(&self, size: Size) -> Self::Frame;
|
||||
}
|
||||
|
||||
pub trait Geometry: Sized {
|
||||
type Cache;
|
||||
|
||||
fn load(cache: &Self::Cache) -> Self;
|
||||
|
||||
fn cache(self) -> Self::Cache;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
use crate::core::Size;
|
||||
use crate::geometry::{self, Frame, Geometry};
|
||||
use crate::Primitive;
|
||||
use crate::geometry::{self, Frame};
|
||||
use crate::Cached;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// A simple cache that stores generated [`Geometry`] to avoid recomputation.
|
||||
/// A simple cache that stores generated geometry to avoid recomputation.
|
||||
///
|
||||
/// A [`Cache`] will not redraw its geometry unless the dimensions of its layer
|
||||
/// change or it is explicitly cleared.
|
||||
|
|
@ -32,16 +31,16 @@ where
|
|||
*self.state.borrow_mut() = State::Empty;
|
||||
}
|
||||
|
||||
/// Draws [`Geometry`] using the provided closure and stores it in the
|
||||
/// Draws geometry using the provided closure and stores it in the
|
||||
/// [`Cache`].
|
||||
///
|
||||
/// The closure will only be called when
|
||||
/// - the bounds have changed since the previous draw call.
|
||||
/// - the [`Cache`] is empty or has been explicitly cleared.
|
||||
///
|
||||
/// Otherwise, the previously stored [`Geometry`] will be returned. The
|
||||
/// Otherwise, the previously stored geometry will be returned. The
|
||||
/// [`Cache`] is not cleared in this case. In other words, it will keep
|
||||
/// returning the stored [`Geometry`] if needed.
|
||||
/// returning the stored geometry if needed.
|
||||
pub fn draw(
|
||||
&self,
|
||||
renderer: &Renderer,
|
||||
|
|
@ -56,7 +55,7 @@ where
|
|||
} = self.state.borrow().deref()
|
||||
{
|
||||
if *cached_bounds == bounds {
|
||||
return Geometry::load(geometry);
|
||||
return Cached::load(geometry);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +63,7 @@ where
|
|||
draw_fn(&mut frame);
|
||||
|
||||
let geometry = frame.into_geometry().cache();
|
||||
let result = Geometry::load(&geometry);
|
||||
let result = Cached::load(&geometry);
|
||||
|
||||
*self.state.borrow_mut() = State::Filled { bounds, geometry };
|
||||
|
||||
|
|
@ -99,7 +98,7 @@ where
|
|||
|
||||
enum State<Geometry>
|
||||
where
|
||||
Geometry: self::Geometry,
|
||||
Geometry: Cached,
|
||||
{
|
||||
Empty,
|
||||
Filled {
|
||||
|
|
@ -107,17 +106,3 @@ where
|
|||
geometry: Geometry::Cache,
|
||||
},
|
||||
}
|
||||
|
||||
impl<T> Geometry for Primitive<T> {
|
||||
type Cache = Arc<Self>;
|
||||
|
||||
fn load(cache: &Arc<Self>) -> Self {
|
||||
Self::Cache {
|
||||
content: cache.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn cache(self) -> Arc<Self> {
|
||||
Arc::new(self)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
//! Draw and generate geometry.
|
||||
use crate::core::{Point, Radians, Rectangle, Size, Vector};
|
||||
use crate::geometry::{self, Geometry};
|
||||
use crate::geometry::{Fill, Path, Stroke, Text};
|
||||
use crate::geometry::{self, Fill, Path, Stroke, Text};
|
||||
use crate::Cached;
|
||||
|
||||
/// The region of a surface that can be used to draw geometry.
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct Frame<Renderer>
|
||||
where
|
||||
Renderer: geometry::Renderer,
|
||||
|
|
@ -13,6 +16,7 @@ impl<Renderer> Frame<Renderer>
|
|||
where
|
||||
Renderer: geometry::Renderer,
|
||||
{
|
||||
/// Creates a new [`Frame`] with the given dimensions.
|
||||
pub fn new(renderer: &Renderer, size: Size) -> Self {
|
||||
Self {
|
||||
raw: renderer.new_frame(size),
|
||||
|
|
@ -164,6 +168,7 @@ where
|
|||
self.raw.scale_nonuniform(scale);
|
||||
}
|
||||
|
||||
/// Turns the [`Frame`] into its underlying geometry.
|
||||
pub fn into_geometry(self) -> Renderer::Geometry {
|
||||
self.raw.into_geometry()
|
||||
}
|
||||
|
|
@ -175,7 +180,7 @@ where
|
|||
/// of each method.
|
||||
#[allow(missing_docs)]
|
||||
pub trait Backend: Sized {
|
||||
type Geometry: Geometry;
|
||||
type Geometry: Cached;
|
||||
|
||||
fn width(&self) -> f32;
|
||||
fn height(&self) -> f32;
|
||||
|
|
|
|||
|
|
@ -9,14 +9,15 @@
|
|||
)]
|
||||
#![forbid(rust_2018_idioms)]
|
||||
#![deny(
|
||||
// missing_debug_implementations,
|
||||
// missing_docs,
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
unsafe_code,
|
||||
unused_results,
|
||||
rustdoc::broken_intra_doc_links
|
||||
)]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
mod antialiasing;
|
||||
mod cached;
|
||||
mod error;
|
||||
mod primitive;
|
||||
mod viewport;
|
||||
|
|
@ -38,6 +39,7 @@ pub mod image;
|
|||
|
||||
pub use antialiasing::Antialiasing;
|
||||
pub use backend::Backend;
|
||||
pub use cached::Cached;
|
||||
pub use compositor::Compositor;
|
||||
pub use damage::Damage;
|
||||
pub use error::Error;
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ pub struct GradientVertex2D {
|
|||
pub gradient: gradient::Packed,
|
||||
}
|
||||
|
||||
/// A renderer capable of drawing a [`Mesh`].
|
||||
pub trait Renderer: core::Renderer {
|
||||
/// Draws the given [`Mesh`].
|
||||
fn draw_mesh(&mut self, mesh: Mesh);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,18 +58,6 @@ impl<B: Backend> Renderer<B> {
|
|||
) -> O {
|
||||
f(&mut self.backend, &self.primitives)
|
||||
}
|
||||
|
||||
#[cfg(feature = "geometry")]
|
||||
pub fn draw_geometry<Geometry>(
|
||||
&mut self,
|
||||
layers: impl IntoIterator<Item = Geometry>,
|
||||
) where
|
||||
Geometry: Into<Primitive<B::Primitive>>,
|
||||
{
|
||||
for layer in layers {
|
||||
self.draw_primitive(layer.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> iced_core::Renderer for Renderer<B> {
|
||||
|
|
|
|||
|
|
@ -398,6 +398,7 @@ mod geometry {
|
|||
use super::Renderer;
|
||||
use crate::core::{Point, Radians, Size, Vector};
|
||||
use crate::graphics::geometry::{self, Fill, Path, Stroke, Text};
|
||||
use crate::graphics::Cached;
|
||||
|
||||
impl<L, R> geometry::Renderer for Renderer<L, R>
|
||||
where
|
||||
|
|
@ -432,10 +433,10 @@ mod geometry {
|
|||
Right(R),
|
||||
}
|
||||
|
||||
impl<L, R> geometry::Geometry for Geometry<L, R>
|
||||
impl<L, R> Cached for Geometry<L, R>
|
||||
where
|
||||
L: geometry::Geometry,
|
||||
R: geometry::Geometry,
|
||||
L: Cached,
|
||||
R: Cached,
|
||||
{
|
||||
type Cache = Geometry<L::Cache, R::Cache>;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,14 @@ where
|
|||
(event::Status::Ignored, None)
|
||||
}
|
||||
|
||||
/// Draws the state of the [`Program`] with the given [`Renderer`].
|
||||
/// Draws the state of the [`Program`], producing a bunch of [`Geometry`].
|
||||
///
|
||||
/// [`Geometry`] can be easily generated with a [`Frame`] or stored in a
|
||||
/// [`Cache`].
|
||||
///
|
||||
/// [`Geometry`]: crate::canvas::Geometry
|
||||
/// [`Frame`]: crate::canvas::Frame
|
||||
/// [`Cache`]: crate::canvas::Cache
|
||||
fn draw(
|
||||
&self,
|
||||
state: &Self::State,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue