From 5fd5d1cdf8e5354788dc40729c4565ef377d3bba Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Mar 2023 21:34:26 +0100 Subject: Implement `Canvas` support for `iced_tiny_skia` --- graphics/src/primitive.rs | 128 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 94 insertions(+), 34 deletions(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 5a163a2f..e4826591 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -1,23 +1,15 @@ +use crate::alignment; + use iced_native::image; use iced_native::svg; -use iced_native::{Background, Color, Font, Rectangle, Size, Vector}; - -use crate::alignment; -use crate::gradient::Gradient; -use crate::triangle; +use iced_native::{Background, Color, Font, Gradient, Rectangle, Size, Vector}; +use bytemuck::{Pod, Zeroable}; use std::sync::Arc; /// A rendering primitive. #[derive(Debug, Clone)] pub enum Primitive { - /// An empty primitive - None, - /// A group of primitives - Group { - /// The primitives of the group - primitives: Vec, - }, /// A text primitive Text { /// The contents of the text @@ -66,27 +58,12 @@ pub enum Primitive { /// The bounds of the viewport bounds: Rectangle, }, - /// A clip primitive - Clip { - /// The bounds of the clip - bounds: Rectangle, - /// The content of the clip - content: Box, - }, - /// A primitive that applies a translation - Translate { - /// The translation vector - translation: Vector, - - /// The primitive to translate - content: Box, - }, /// 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: triangle::Mesh2D, + buffers: Mesh2D, /// The size of the drawable region of the mesh. /// @@ -98,7 +75,7 @@ pub enum Primitive { /// It can be used to render many kinds of geometry freely. GradientMesh { /// The vertices and indices of the mesh. - buffers: triangle::Mesh2D, + buffers: Mesh2D, /// The size of the drawable region of the mesh. /// @@ -108,18 +85,101 @@ pub enum Primitive { /// The [`Gradient`] to apply to the mesh. gradient: Gradient, }, + Fill { + path: tiny_skia::Path, + paint: tiny_skia::Paint<'static>, + rule: tiny_skia::FillRule, + transform: tiny_skia::Transform, + }, + Stroke { + path: tiny_skia::Path, + paint: tiny_skia::Paint<'static>, + stroke: tiny_skia::Stroke, + transform: tiny_skia::Transform, + }, + /// A group of primitives + Group { + /// The primitives of the group + primitives: Vec, + }, + /// A clip primitive + Clip { + /// The bounds of the clip + bounds: Rectangle, + /// The content of the clip + content: Box, + }, + /// A primitive that applies a translation + Translate { + /// The translation vector + translation: Vector, + + /// The primitive to translate + content: Box, + }, /// A cached primitive. /// /// This can be useful if you are implementing a widget where primitive /// generation is expensive. - Cached { + Cache { /// The cached primitive - cache: Arc, + content: Arc, }, } -impl Default for Primitive { - fn default() -> Primitive { - Primitive::None +impl Primitive { + pub fn group(primitives: Vec) -> Self { + Self::Group { primitives } + } + + pub fn clip(self, bounds: Rectangle) -> Self { + Self::Clip { + bounds, + content: Box::new(self), + } + } + + pub fn translate(self, translation: Vector) -> Self { + Self::Translate { + translation, + content: Box::new(self), + } + } +} + +/// A set of [`Vertex2D`] and indices representing a list of triangles. +#[derive(Clone, Debug)] +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. +#[derive(Copy, Clone, Debug, Zeroable, Pod)] +#[repr(C)] +pub struct Vertex2D { + /// The vertex position in 2D space. + pub position: [f32; 2], +} + +/// A two-dimensional vertex with a color. +#[derive(Copy, Clone, Debug, 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: [f32; 4], +} + +impl From<()> for Primitive { + fn from(_: ()) -> Self { + Self::Group { primitives: vec![] } } } -- cgit From bbeaf10c04a922af5c1c3b898f0c4301d23feab0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 3 Mar 2023 03:55:07 +0100 Subject: Mark `Primitive` as `non-exhaustive` in `iced_graphics` --- graphics/src/primitive.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index e4826591..5a48639d 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -9,6 +9,7 @@ use std::sync::Arc; /// A rendering primitive. #[derive(Debug, Clone)] +#[non_exhaustive] pub enum Primitive { /// A text primitive Text { @@ -85,12 +86,14 @@ pub enum Primitive { /// The [`Gradient`] to apply to the mesh. gradient: Gradient, }, + #[cfg(feature = "tiny_skia")] Fill { path: tiny_skia::Path, paint: tiny_skia::Paint<'static>, rule: tiny_skia::FillRule, transform: tiny_skia::Transform, }, + #[cfg(feature = "tiny_skia")] Stroke { path: tiny_skia::Path, paint: tiny_skia::Paint<'static>, -- cgit From d13d19ba3569560edd67f20b48f37548d10ceee9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 3 Mar 2023 04:00:44 +0100 Subject: Rename `canvas::frame` to `canvas` in `iced_wgpu` --- graphics/src/primitive.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 5a48639d..f900b3fd 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -86,14 +86,14 @@ pub enum Primitive { /// The [`Gradient`] to apply to the mesh. gradient: Gradient, }, - #[cfg(feature = "tiny_skia")] + #[cfg(feature = "tiny-skia")] Fill { path: tiny_skia::Path, paint: tiny_skia::Paint<'static>, rule: tiny_skia::FillRule, transform: tiny_skia::Transform, }, - #[cfg(feature = "tiny_skia")] + #[cfg(feature = "tiny-skia")] Stroke { path: tiny_skia::Path, paint: tiny_skia::Paint<'static>, -- cgit From 3a0d34c0240f4421737a6a08761f99d6f8140d02 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Mar 2023 05:37:11 +0100 Subject: Create `iced_widget` subcrate and re-organize the whole codebase --- graphics/src/primitive.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index f900b3fd..195b62da 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -1,8 +1,7 @@ -use crate::alignment; - -use iced_native::image; -use iced_native::svg; -use iced_native::{Background, Color, Font, Gradient, Rectangle, Size, Vector}; +use iced_core::alignment; +use iced_core::image; +use iced_core::svg; +use iced_core::{Background, Color, Font, Gradient, Rectangle, Size, Vector}; use bytemuck::{Pod, Zeroable}; use std::sync::Arc; -- cgit From 0f7abffc0e94b4bb9f8117db633bfd07d900eb93 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 22 Mar 2023 00:36:57 +0100 Subject: Draft (very) basic incremental rendering for `iced_tiny_skia` --- graphics/src/primitive.rs | 151 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 147 insertions(+), 4 deletions(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 195b62da..bbf300b0 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -7,7 +7,7 @@ use bytemuck::{Pod, Zeroable}; use std::sync::Arc; /// A rendering primitive. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[non_exhaustive] pub enum Primitive { /// A text primitive @@ -147,10 +147,153 @@ impl Primitive { content: Box::new(self), } } + + 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.0) + } + Self::Quad { bounds, .. } + | Self::Image { bounds, .. } + | Self::Svg { bounds, .. } + | 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(), + } + } + + pub fn damage(&self, other: &Self) -> Vec { + match (self, other) { + ( + Primitive::Group { + primitives: primitives_a, + }, + Primitive::Group { + primitives: primitives_b, + }, + ) => return Self::damage_list(primitives_a, primitives_b), + ( + Primitive::Clip { + bounds: bounds_a, + content: content_a, + }, + Primitive::Clip { + bounds: bounds_b, + content: content_b, + }, + ) => { + if bounds_a == bounds_b { + return content_a.damage(content_b); + } else { + return vec![*bounds_a, *bounds_b]; + } + } + ( + Primitive::Translate { + translation: translation_a, + content: content_a, + }, + Primitive::Translate { + translation: translation_b, + content: content_b, + }, + ) => { + if translation_a == translation_b { + return content_a.damage(content_b); + } + } + ( + Primitive::Cache { content: content_a }, + Primitive::Cache { content: content_b }, + ) => { + if Arc::ptr_eq(content_a, content_b) { + return vec![]; + } + } + _ if self == other => return vec![], + _ => {} + } + + let bounds_a = self.bounds(); + let bounds_b = other.bounds(); + + if bounds_a == bounds_b { + vec![bounds_a] + } else { + vec![bounds_a, bounds_b] + } + } + + pub fn damage_list(previous: &[Self], current: &[Self]) -> Vec { + let damage = + previous.iter().zip(current).flat_map(|(a, b)| a.damage(b)); + + if previous.len() == current.len() { + damage.collect() + } else { + let (smaller, bigger) = if previous.len() < current.len() { + (previous, current) + } else { + (current, previous) + }; + + // Extend damage by the added/removed primitives + damage + .chain(bigger[smaller.len()..].iter().map(Primitive::bounds)) + .collect() + } + } } /// A set of [`Vertex2D`] and indices representing a list of triangles. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Mesh2D { /// The vertices of the mesh pub vertices: Vec, @@ -162,7 +305,7 @@ pub struct Mesh2D { } /// A two-dimensional vertex. -#[derive(Copy, Clone, Debug, Zeroable, Pod)] +#[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)] #[repr(C)] pub struct Vertex2D { /// The vertex position in 2D space. @@ -170,7 +313,7 @@ pub struct Vertex2D { } /// A two-dimensional vertex with a color. -#[derive(Copy, Clone, Debug, Zeroable, Pod)] +#[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)] #[repr(C)] pub struct ColoredVertex2D { /// The vertex position in 2D space. -- cgit From 6270c33ed9823c67f6b6e6dac8fd32521e4ac5a9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 4 Apr 2023 20:47:53 +0200 Subject: Keep playing with incremental rendering (still very slow) --- graphics/src/primitive.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index bbf300b0..f079ff6f 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -230,7 +230,11 @@ impl Primitive { }, ) => { if bounds_a == bounds_b { - return content_a.damage(content_b); + return content_a + .damage(content_b) + .into_iter() + .filter_map(|r| r.intersection(bounds_a)) + .collect(); } else { return vec![*bounds_a, *bounds_b]; } @@ -246,7 +250,11 @@ impl Primitive { }, ) => { if translation_a == translation_b { - return content_a.damage(content_b); + return content_a + .damage(content_b) + .into_iter() + .map(|r| r + *translation_a) + .collect(); } } ( -- cgit From f8cd1faa286daaf34cc532bf6d34b932b32eb35a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 5 Apr 2023 04:10:00 +0200 Subject: Group damage regions by area increase --- graphics/src/primitive.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index f079ff6f..01546dcb 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -178,8 +178,8 @@ impl Primitive { } Self::Quad { bounds, .. } | Self::Image { bounds, .. } - | Self::Svg { bounds, .. } - | Self::Clip { bounds, .. } => bounds.expand(1.0), + | Self::Svg { bounds, .. } => bounds.expand(1.0), + Self::Clip { bounds, .. } => *bounds, Self::SolidMesh { size, .. } | Self::GradientMesh { size, .. } => { Rectangle::with_size(*size) } -- cgit From ba07abe5c8d3f6fb175e13f5cd10f74ee8ab460c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 8 Apr 2023 07:08:03 +0200 Subject: Expand bounds of `Text` primitives a bit further --- graphics/src/primitive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 01546dcb..7f2c8ae2 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -174,7 +174,7 @@ impl Primitive { alignment::Vertical::Bottom => bounds.y - bounds.height, }; - bounds.expand(1.0) + bounds.expand(1.5) } Self::Quad { bounds, .. } | Self::Image { bounds, .. } -- cgit From af0303f95e27737d9de8915f939b60a2bc3282ae Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 27 Apr 2023 15:10:41 +0200 Subject: Move damage tracking logic to `compositor` in `iced_tiny_skia` --- graphics/src/primitive.rs | 90 ----------------------------------------------- 1 file changed, 90 deletions(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 7f2c8ae2..1751d03a 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -208,96 +208,6 @@ impl Primitive { Self::Cache { content } => content.bounds(), } } - - pub fn damage(&self, other: &Self) -> Vec { - match (self, other) { - ( - Primitive::Group { - primitives: primitives_a, - }, - Primitive::Group { - primitives: primitives_b, - }, - ) => return Self::damage_list(primitives_a, primitives_b), - ( - Primitive::Clip { - bounds: bounds_a, - content: content_a, - }, - Primitive::Clip { - bounds: bounds_b, - content: content_b, - }, - ) => { - if bounds_a == bounds_b { - return content_a - .damage(content_b) - .into_iter() - .filter_map(|r| r.intersection(bounds_a)) - .collect(); - } else { - return vec![*bounds_a, *bounds_b]; - } - } - ( - Primitive::Translate { - translation: translation_a, - content: content_a, - }, - Primitive::Translate { - translation: translation_b, - content: content_b, - }, - ) => { - if translation_a == translation_b { - return content_a - .damage(content_b) - .into_iter() - .map(|r| r + *translation_a) - .collect(); - } - } - ( - Primitive::Cache { content: content_a }, - Primitive::Cache { content: content_b }, - ) => { - if Arc::ptr_eq(content_a, content_b) { - return vec![]; - } - } - _ if self == other => return vec![], - _ => {} - } - - let bounds_a = self.bounds(); - let bounds_b = other.bounds(); - - if bounds_a == bounds_b { - vec![bounds_a] - } else { - vec![bounds_a, bounds_b] - } - } - - pub fn damage_list(previous: &[Self], current: &[Self]) -> Vec { - let damage = - previous.iter().zip(current).flat_map(|(a, b)| a.damage(b)); - - if previous.len() == current.len() { - damage.collect() - } else { - let (smaller, bigger) = if previous.len() < current.len() { - (previous, current) - } else { - (current, previous) - }; - - // Extend damage by the added/removed primitives - damage - .chain(bigger[smaller.len()..].iter().map(Primitive::bounds)) - .collect() - } - } } /// A set of [`Vertex2D`] and indices representing a list of triangles. -- cgit From 38f82ab35fd24a1aaf96728148b2826211956a9f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 27 Apr 2023 15:25:59 +0200 Subject: Expand damage regions of `Clip` primitives a bit --- graphics/src/primitive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 1751d03a..d6a2c4c4 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -179,7 +179,7 @@ impl Primitive { Self::Quad { bounds, .. } | Self::Image { bounds, .. } | Self::Svg { bounds, .. } => bounds.expand(1.0), - Self::Clip { bounds, .. } => *bounds, + Self::Clip { bounds, .. } => bounds.expand(1.0), Self::SolidMesh { size, .. } | Self::GradientMesh { size, .. } => { Rectangle::with_size(*size) } -- cgit From 33b5a900197e2798a393d6d9a0834039666eddbb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 19 Apr 2023 01:19:56 +0200 Subject: Make basic text shaping the default shaping strategy --- graphics/src/primitive.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index d6a2c4c4..2d9c221b 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -26,6 +26,15 @@ pub enum Primitive { horizontal_alignment: alignment::Horizontal, /// The vertical alignment of the text vertical_alignment: alignment::Vertical, + /// Whether the text needs advanced shaping and font fallback. + /// + /// You will need to enable this flag if the text contains a complex + /// script, the font used needs it, and/or multiple fonts in your system + /// may be needed to display all of the glyphs. + /// + /// Advanced shaping is expensive! You should only enable it when + /// necessary. + advanced_shape: bool, }, /// A quad primitive Quad { -- cgit From 4bd290afe7d81d9aaf7467b3ce91491f6600261a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 19 Apr 2023 02:00:45 +0200 Subject: Introduce `text::Shaping` enum and replace magic boolean --- graphics/src/primitive.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 2d9c221b..db237035 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -1,7 +1,8 @@ -use iced_core::alignment; -use iced_core::image; -use iced_core::svg; -use iced_core::{Background, Color, Font, Gradient, Rectangle, Size, Vector}; +use crate::core::alignment; +use crate::core::image; +use crate::core::svg; +use crate::core::text; +use crate::core::{Background, Color, Font, Gradient, Rectangle, Size, Vector}; use bytemuck::{Pod, Zeroable}; use std::sync::Arc; @@ -26,15 +27,8 @@ pub enum Primitive { horizontal_alignment: alignment::Horizontal, /// The vertical alignment of the text vertical_alignment: alignment::Vertical, - /// Whether the text needs advanced shaping and font fallback. - /// - /// You will need to enable this flag if the text contains a complex - /// script, the font used needs it, and/or multiple fonts in your system - /// may be needed to display all of the glyphs. - /// - /// Advanced shaping is expensive! You should only enable it when - /// necessary. - advanced_shape: bool, + /// The shaping strategy of the text. + shaping: text::Shaping, }, /// A quad primitive Quad { -- cgit From 9499a8f9e6f9971dedfae563cb133232aa3cebc2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 4 May 2023 13:00:16 +0200 Subject: Support configurable `LineHeight` in text widgets --- graphics/src/primitive.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'graphics/src/primitive.rs') diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index db237035..d814c757 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -19,8 +19,10 @@ pub enum Primitive { bounds: Rectangle, /// The color of the text color: Color, - /// The size of the text + /// The size of the text in logical pixels size: f32, + /// The line height of the text + line_height: text::LineHeight, /// The font of the text font: Font, /// The horizontal alignment of the text -- cgit From 8622e998f2701e7f4ca8d2f71c85150f436a9945 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 11 May 2023 15:25:58 +0200 Subject: Write missing documentation in `iced_graphics` --- graphics/src/primitive.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'graphics/src/primitive.rs') 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::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 { -- cgit