Readjusted namespaces, removed Geometry example as it's no longer relevant.
This commit is contained in:
parent
6e7b3ced0b
commit
30432cbade
27 changed files with 394 additions and 625 deletions
|
|
@ -9,17 +9,17 @@ pub mod path;
|
|||
|
||||
mod cache;
|
||||
mod cursor;
|
||||
mod fill;
|
||||
mod frame;
|
||||
mod geometry;
|
||||
mod program;
|
||||
mod stroke;
|
||||
mod text;
|
||||
pub mod fill;
|
||||
pub mod stroke;
|
||||
|
||||
pub use cache::Cache;
|
||||
pub use cursor::Cursor;
|
||||
pub use event::Event;
|
||||
pub use fill::{Fill, FillRule, Style};
|
||||
pub use fill::{Fill, FillRule};
|
||||
pub use frame::Frame;
|
||||
pub use geometry::Geometry;
|
||||
pub use path::Path;
|
||||
|
|
@ -37,6 +37,8 @@ use iced_native::{
|
|||
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Vector, Widget,
|
||||
};
|
||||
|
||||
pub use crate::gradient::Gradient;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// A widget capable of drawing 2D graphics.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
use iced_native::Color;
|
||||
//! Fill [crate::widget::canvas::Geometry] with a certain style.
|
||||
|
||||
use crate::gradient::Gradient;
|
||||
use crate::shader::Shader;
|
||||
use crate::layer::mesh;
|
||||
use iced_native::Color;
|
||||
|
||||
/// The style used to fill geometry.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -21,7 +23,7 @@ pub struct Fill<'a> {
|
|||
pub rule: FillRule,
|
||||
}
|
||||
|
||||
impl <'a> Default for Fill<'a> {
|
||||
impl<'a> Default for Fill<'a> {
|
||||
fn default() -> Fill<'a> {
|
||||
Fill {
|
||||
style: Style::Solid(Color::BLACK),
|
||||
|
|
@ -48,11 +50,11 @@ pub enum Style<'a> {
|
|||
Gradient(&'a Gradient),
|
||||
}
|
||||
|
||||
impl <'a> Into<Shader> for Style<'a> {
|
||||
fn into(self) -> Shader {
|
||||
impl<'a> Into<mesh::Style> for Style<'a> {
|
||||
fn into(self) -> mesh::Style {
|
||||
match self {
|
||||
Style::Solid(color) => Shader::Solid(color),
|
||||
Style::Gradient(gradient) => gradient.clone().into()
|
||||
Style::Solid(color) => mesh::Style::Solid(color),
|
||||
Style::Gradient(gradient) => gradient.clone().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::triangle;
|
|||
use crate::widget::canvas::{path, Fill, Geometry, Path, Stroke, Text};
|
||||
use crate::Primitive;
|
||||
|
||||
use crate::shader::Shader;
|
||||
use crate::layer::mesh;
|
||||
use crate::triangle::Vertex2D;
|
||||
use lyon::tessellation;
|
||||
use lyon::tessellation::geometry_builder::Positions;
|
||||
|
|
@ -17,7 +17,10 @@ use lyon::tessellation::geometry_builder::Positions;
|
|||
#[allow(missing_debug_implementations)]
|
||||
pub struct Frame {
|
||||
size: Size,
|
||||
buffers: Vec<(tessellation::VertexBuffers<lyon::math::Point, u32>, Shader)>,
|
||||
buffers: Vec<(
|
||||
tessellation::VertexBuffers<lyon::math::Point, u32>,
|
||||
mesh::Style,
|
||||
)>,
|
||||
primitives: Vec<Primitive>,
|
||||
transforms: Transforms,
|
||||
fill_tessellator: tessellation::FillTessellator,
|
||||
|
|
@ -109,7 +112,8 @@ impl Frame {
|
|||
&options,
|
||||
&mut buffers,
|
||||
)
|
||||
}.expect("Tessellate path.");
|
||||
}
|
||||
.expect("Tessellate path.");
|
||||
|
||||
self.buffers.push((buf, style.into()))
|
||||
}
|
||||
|
|
@ -126,7 +130,8 @@ impl Frame {
|
|||
|
||||
let mut buf = tessellation::VertexBuffers::new();
|
||||
|
||||
let mut buffers = tessellation::BuffersBuilder::new(&mut buf, Positions);
|
||||
let mut buffers =
|
||||
tessellation::BuffersBuilder::new(&mut buf, Positions);
|
||||
|
||||
let top_left =
|
||||
self.transforms.current.raw.transform_point(
|
||||
|
|
@ -159,7 +164,8 @@ impl Frame {
|
|||
|
||||
let mut buf = tessellation::VertexBuffers::new();
|
||||
|
||||
let mut buffers = tessellation::BuffersBuilder::new(&mut buf, Positions);
|
||||
let mut buffers =
|
||||
tessellation::BuffersBuilder::new(&mut buf, Positions);
|
||||
|
||||
let mut options = tessellation::StrokeOptions::default();
|
||||
options.line_width = stroke.width;
|
||||
|
|
@ -187,7 +193,8 @@ impl Frame {
|
|||
&options,
|
||||
&mut buffers,
|
||||
)
|
||||
}.expect("Stroke path");
|
||||
}
|
||||
.expect("Stroke path");
|
||||
|
||||
self.buffers.push((buf, stroke.style.into()))
|
||||
}
|
||||
|
|
@ -331,7 +338,7 @@ impl Frame {
|
|||
}
|
||||
|
||||
fn into_primitives(mut self) -> Vec<Primitive> {
|
||||
for (buffer, shader) in self.buffers {
|
||||
for (buffer, style) in self.buffers {
|
||||
if !buffer.indices.is_empty() {
|
||||
self.primitives.push(Primitive::Mesh2D {
|
||||
buffers: triangle::Mesh2D {
|
||||
|
|
@ -339,7 +346,7 @@ impl Frame {
|
|||
indices: buffer.indices,
|
||||
},
|
||||
size: self.size,
|
||||
shader,
|
||||
style,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -350,5 +357,10 @@ impl Frame {
|
|||
|
||||
/// Converts from [`lyon::math::Point`] to [`Vertex2D`]. Used for generating primitives.
|
||||
fn vertices_from(points: Vec<lyon::math::Point>) -> Vec<Vertex2D> {
|
||||
points.iter().map(|p| Vertex2D { position: [p.x, p.y]}).collect()
|
||||
}
|
||||
points
|
||||
.iter()
|
||||
.map(|p| Vertex2D {
|
||||
position: [p.x, p.y],
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
//! Create lines from a [crate::widget::canvas::Path] and render with various attributes/styles.
|
||||
|
||||
use iced_native::Color;
|
||||
use crate::gradient::Gradient;
|
||||
use crate::shader::Shader;
|
||||
use crate::layer::mesh;
|
||||
|
||||
/// The style of a stroke.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -66,10 +68,10 @@ pub enum Style<'a> {
|
|||
Gradient(&'a Gradient),
|
||||
}
|
||||
|
||||
impl <'a> Into<Shader> for Style<'a> {
|
||||
fn into(self) -> Shader {
|
||||
impl <'a> Into<mesh::Style> for Style<'a> {
|
||||
fn into(self) -> mesh::Style {
|
||||
match self {
|
||||
Style::Solid(color) => Shader::Solid(color),
|
||||
Style::Solid(color) => mesh::Style::Solid(color),
|
||||
Style::Gradient(gradient) => gradient.clone().into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue