summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/gradient.rs2
-rw-r--r--graphics/src/layer.rs32
-rw-r--r--graphics/src/widget/canvas.rs4
-rw-r--r--graphics/src/widget/canvas/fill.rs14
-rw-r--r--graphics/src/widget/canvas/stroke.rs14
5 files changed, 30 insertions, 36 deletions
diff --git a/graphics/src/gradient.rs b/graphics/src/gradient.rs
index fa57842b..0c394e8b 100644
--- a/graphics/src/gradient.rs
+++ b/graphics/src/gradient.rs
@@ -1,6 +1,6 @@
//! For creating a Gradient.
use iced_native::Color;
-use crate::gradient::linear::Linear;
+pub use crate::gradient::linear::Linear;
use crate::Point;
#[derive(Debug, Clone, PartialEq)]
diff --git a/graphics/src/layer.rs b/graphics/src/layer.rs
index b7731922..096c50dc 100644
--- a/graphics/src/layer.rs
+++ b/graphics/src/layer.rs
@@ -19,7 +19,7 @@ pub struct Layer<'a> {
pub quads: Vec<Quad>,
/// The triangle meshes of the [`Layer`].
- pub meshes: Meshes<'a>,
+ pub meshes: Vec<Mesh<'a>>,
/// The text of the [`Layer`].
pub text: Vec<Text<'a>>,
@@ -34,7 +34,7 @@ impl<'a> Layer<'a> {
Self {
bounds,
quads: Vec::new(),
- meshes: Meshes(Vec::new()),
+ meshes: Vec::new(),
text: Vec::new(),
images: Vec::new(),
}
@@ -174,7 +174,7 @@ impl<'a> Layer<'a> {
// Only draw visible content
if let Some(clip_bounds) = layer.bounds.intersection(&bounds) {
- layer.meshes.0.push(
+ layer.meshes.push(
Mesh {
origin: Point::new(translation.x, translation.y),
buffers,
@@ -335,20 +335,14 @@ unsafe impl bytemuck::Zeroable for Quad {}
#[allow(unsafe_code)]
unsafe impl bytemuck::Pod for Quad {}
-#[derive(Debug)]
-/// A collection of meshes.
-pub struct Meshes<'a>(pub Vec<Mesh<'a>>);
-
-impl<'a> Meshes<'a> {
- /// Returns the number of total vertices & total indices of all [`Mesh`]es.
- pub fn attribute_count(&self) -> (usize, usize) {
- self.0
- .iter()
- .map(|Mesh { buffers, .. }| {
- (buffers.vertices.len(), buffers.indices.len())
- })
- .fold((0, 0), |(total_v, total_i), (v, i)| {
- (total_v + v, total_i + i)
- })
- }
+/// Returns the number of total vertices & total indices of all [`Mesh`]es.
+pub fn attribute_count_of<'a>(meshes: &'a [Mesh<'a>]) -> (usize, usize) {
+ meshes
+ .iter()
+ .map(|Mesh { buffers, .. }| {
+ (buffers.vertices.len(), buffers.indices.len())
+ })
+ .fold((0, 0), |(total_v, total_i), (v, i)| {
+ (total_v + v, total_i + i)
+ })
} \ No newline at end of file
diff --git a/graphics/src/widget/canvas.rs b/graphics/src/widget/canvas.rs
index 95c962af..f6929e97 100644
--- a/graphics/src/widget/canvas.rs
+++ b/graphics/src/widget/canvas.rs
@@ -19,12 +19,12 @@ mod text;
pub use cache::Cache;
pub use cursor::Cursor;
pub use event::Event;
-pub use fill::{Fill, FillRule, FillStyle};
+pub use fill::{Fill, FillRule, Style};
pub use frame::Frame;
pub use geometry::Geometry;
pub use path::Path;
pub use program::Program;
-pub use stroke::{LineCap, LineDash, LineJoin, Stroke, StrokeStyle};
+pub use stroke::{LineCap, LineDash, LineJoin, Stroke};
pub use text::Text;
use crate::{Backend, Primitive, Renderer};
diff --git a/graphics/src/widget/canvas/fill.rs b/graphics/src/widget/canvas/fill.rs
index 60029e03..6f10505c 100644
--- a/graphics/src/widget/canvas/fill.rs
+++ b/graphics/src/widget/canvas/fill.rs
@@ -8,7 +8,7 @@ pub struct Fill<'a> {
/// The color or gradient of the fill.
///
/// By default, it is set to [`FillStyle::Solid`] `BLACK`.
- pub style: FillStyle<'a>,
+ pub style: Style<'a>,
/// The fill rule defines how to determine what is inside and what is
/// outside of a shape.
@@ -24,7 +24,7 @@ pub struct Fill<'a> {
impl <'a> Default for Fill<'a> {
fn default() -> Fill<'a> {
Fill {
- style: FillStyle::Solid(Color::BLACK),
+ style: Style::Solid(Color::BLACK),
rule: FillRule::NonZero,
}
}
@@ -33,7 +33,7 @@ impl <'a> Default for Fill<'a> {
impl<'a> From<Color> for Fill<'a> {
fn from(color: Color) -> Fill<'a> {
Fill {
- style: FillStyle::Solid(color),
+ style: Style::Solid(color),
..Fill::default()
}
}
@@ -41,18 +41,18 @@ impl<'a> From<Color> for Fill<'a> {
/// The color or gradient of a [`Fill`].
#[derive(Debug, Clone)]
-pub enum FillStyle<'a> {
+pub enum Style<'a> {
/// A solid color
Solid(Color),
/// A color gradient
Gradient(&'a Gradient),
}
-impl <'a> Into<Shader> for FillStyle<'a> {
+impl <'a> Into<Shader> for Style<'a> {
fn into(self) -> Shader {
match self {
- FillStyle::Solid(color) => Shader::Solid(color),
- FillStyle::Gradient(gradient) => gradient.clone().into()
+ Style::Solid(color) => Shader::Solid(color),
+ Style::Gradient(gradient) => gradient.clone().into()
}
}
}
diff --git a/graphics/src/widget/canvas/stroke.rs b/graphics/src/widget/canvas/stroke.rs
index ed82f189..7ce5ff1d 100644
--- a/graphics/src/widget/canvas/stroke.rs
+++ b/graphics/src/widget/canvas/stroke.rs
@@ -8,7 +8,7 @@ pub struct Stroke<'a> {
/// The color or gradient of the stroke.
///
/// By default, it is set to [`StrokeStyle::Solid`] `BLACK`.
- pub style: StrokeStyle<'a>,
+ pub style: Style<'a>,
/// The distance between the two edges of the stroke.
pub width: f32,
/// The shape to be used at the end of open subpaths when they are stroked.
@@ -24,7 +24,7 @@ impl<'a> Stroke<'a> {
/// Sets the color of the [`Stroke`].
pub fn with_color(self, color: Color) -> Self {
Stroke {
- style: StrokeStyle::Solid(color),
+ style: Style::Solid(color),
..self
}
}
@@ -48,7 +48,7 @@ impl<'a> Stroke<'a> {
impl<'a> Default for Stroke<'a> {
fn default() -> Self {
Stroke {
- style: StrokeStyle::Solid(Color::BLACK),
+ style: Style::Solid(Color::BLACK),
width: 1.0,
line_cap: LineCap::default(),
line_join: LineJoin::default(),
@@ -59,18 +59,18 @@ impl<'a> Default for Stroke<'a> {
/// The color or gradient of a [`Stroke`].
#[derive(Debug, Clone, Copy)]
-pub enum StrokeStyle<'a> {
+pub enum Style<'a> {
/// A solid color
Solid(Color),
/// A color gradient
Gradient(&'a Gradient),
}
-impl <'a> Into<Shader> for StrokeStyle<'a> {
+impl <'a> Into<Shader> for Style<'a> {
fn into(self) -> Shader {
match self {
- StrokeStyle::Solid(color) => Shader::Solid(color),
- StrokeStyle::Gradient(gradient) => gradient.clone().into()
+ Style::Solid(color) => Shader::Solid(color),
+ Style::Gradient(gradient) => gradient.clone().into()
}
}
}