summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-03 04:57:55 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-03 04:57:55 +0100
commit6cc48b5c62bac287b8f9f1c79c1fb7486c51b18f (patch)
tree7a9d57f52e3bee9f4d910c89178dc3e2917957a1 /graphics
parentd13d19ba3569560edd67f20b48f37548d10ceee9 (diff)
downloadiced-6cc48b5c62bac287b8f9f1c79c1fb7486c51b18f.tar.gz
iced-6cc48b5c62bac287b8f9f1c79c1fb7486c51b18f.tar.bz2
iced-6cc48b5c62bac287b8f9f1c79c1fb7486c51b18f.zip
Move `Canvas` and `QRCode` to `iced` crate
Rename `canvas` modules to `geometry` in graphics subcrates
Diffstat (limited to '')
-rw-r--r--graphics/Cargo.toml6
-rw-r--r--graphics/src/backend.rs2
-rw-r--r--graphics/src/geometry.rs36
-rw-r--r--graphics/src/geometry/fill.rs (renamed from native/src/widget/canvas/fill.rs)5
-rw-r--r--graphics/src/geometry/path.rs (renamed from native/src/widget/canvas/path.rs)0
-rw-r--r--graphics/src/geometry/path/arc.rs (renamed from native/src/widget/canvas/path/arc.rs)0
-rw-r--r--graphics/src/geometry/path/builder.rs (renamed from native/src/widget/canvas/path/builder.rs)2
-rw-r--r--graphics/src/geometry/stroke.rs (renamed from native/src/widget/canvas/stroke.rs)2
-rw-r--r--graphics/src/geometry/style.rs (renamed from native/src/widget/canvas/style.rs)3
-rw-r--r--graphics/src/geometry/text.rs (renamed from native/src/widget/canvas/text.rs)0
-rw-r--r--graphics/src/lib.rs6
-rw-r--r--graphics/src/renderer.rs8
12 files changed, 56 insertions, 14 deletions
diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml
index 62e67cf8..98e6f474 100644
--- a/graphics/Cargo.toml
+++ b/graphics/Cargo.toml
@@ -24,7 +24,7 @@ bmp = ["image_rs/bmp"]
hdr = ["image_rs/hdr"]
dds = ["image_rs/dds"]
farbfeld = ["image_rs/farbfeld"]
-canvas = ["iced_native/canvas"]
+geometry = ["lyon_path"]
opengl = []
image_rs = ["kamadak-exif"]
@@ -65,6 +65,10 @@ optional = true
version = "0.5"
optional = true
+[dependencies.lyon_path]
+version = "1"
+optional = true
+
[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
all-features = true
diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs
index c44372e8..8658cffe 100644
--- a/graphics/src/backend.rs
+++ b/graphics/src/backend.rs
@@ -10,8 +10,6 @@ use std::borrow::Cow;
///
/// [`Renderer`]: crate::Renderer
pub trait Backend {
- type Geometry: Into<crate::Primitive>;
-
/// Trims the measurements cache.
///
/// This method is currently necessary to properly trim the text cache in
diff --git a/graphics/src/geometry.rs b/graphics/src/geometry.rs
new file mode 100644
index 00000000..29ac84d6
--- /dev/null
+++ b/graphics/src/geometry.rs
@@ -0,0 +1,36 @@
+//! Draw 2D graphics for your users.
+//!
+//! A [`Canvas`] widget can be used to draw different kinds of 2D shapes in a
+//! [`Frame`]. It can be used for animation, data visualization, game graphics,
+//! and more!
+pub mod fill;
+pub mod path;
+pub mod stroke;
+
+mod style;
+mod text;
+
+pub use fill::Fill;
+pub use path::Path;
+pub use stroke::{LineCap, LineDash, LineJoin, Stroke};
+pub use style::Style;
+pub use text::Text;
+
+pub use iced_native::gradient::{self, Gradient};
+
+use crate::Primitive;
+
+#[derive(Debug, Clone)]
+pub struct Geometry(pub Primitive);
+
+impl From<Geometry> for Primitive {
+ fn from(geometry: Geometry) -> Self {
+ geometry.0
+ }
+}
+
+pub trait Renderer: iced_native::Renderer {
+ type Geometry;
+
+ fn draw(&mut self, geometry: Vec<Self::Geometry>);
+}
diff --git a/native/src/widget/canvas/fill.rs b/graphics/src/geometry/fill.rs
index 92b1e47e..109d5e99 100644
--- a/native/src/widget/canvas/fill.rs
+++ b/graphics/src/geometry/fill.rs
@@ -1,8 +1,7 @@
//! Fill [crate::widget::canvas::Geometry] with a certain style.
-use crate::widget::canvas::Gradient;
-use crate::Color;
+use crate::{Color, Gradient};
-pub use crate::widget::canvas::Style;
+pub use crate::geometry::Style;
/// The style used to fill geometry.
#[derive(Debug, Clone)]
diff --git a/native/src/widget/canvas/path.rs b/graphics/src/geometry/path.rs
index 30c387c5..30c387c5 100644
--- a/native/src/widget/canvas/path.rs
+++ b/graphics/src/geometry/path.rs
diff --git a/native/src/widget/canvas/path/arc.rs b/graphics/src/geometry/path/arc.rs
index e0747d3e..e0747d3e 100644
--- a/native/src/widget/canvas/path/arc.rs
+++ b/graphics/src/geometry/path/arc.rs
diff --git a/native/src/widget/canvas/path/builder.rs b/graphics/src/geometry/path/builder.rs
index 84fda052..4a9c5e36 100644
--- a/native/src/widget/canvas/path/builder.rs
+++ b/graphics/src/geometry/path/builder.rs
@@ -1,4 +1,4 @@
-use crate::widget::canvas::path::{arc, Arc, Path};
+use crate::geometry::path::{arc, Arc, Path};
use crate::{Point, Size};
use lyon_path::builder::{self, SvgPathBuilder};
diff --git a/native/src/widget/canvas/stroke.rs b/graphics/src/geometry/stroke.rs
index ab4727b2..b551a9c9 100644
--- a/native/src/widget/canvas/stroke.rs
+++ b/graphics/src/geometry/stroke.rs
@@ -1,5 +1,5 @@
//! Create lines from a [crate::widget::canvas::Path] and assigns them various attributes/styles.
-pub use crate::widget::canvas::Style;
+pub use crate::geometry::Style;
use crate::Color;
diff --git a/native/src/widget/canvas/style.rs b/graphics/src/geometry/style.rs
index 2642fdb8..6794f2e7 100644
--- a/native/src/widget/canvas/style.rs
+++ b/graphics/src/geometry/style.rs
@@ -1,5 +1,4 @@
-use crate::widget::canvas::Gradient;
-use crate::Color;
+use crate::{Color, Gradient};
/// The coloring style of some drawing.
#[derive(Debug, Clone, PartialEq)]
diff --git a/native/src/widget/canvas/text.rs b/graphics/src/geometry/text.rs
index 8c0b2dfb..8c0b2dfb 100644
--- a/native/src/widget/canvas/text.rs
+++ b/graphics/src/geometry/text.rs
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
index 576b2d78..e56f8ad8 100644
--- a/graphics/src/lib.rs
+++ b/graphics/src/lib.rs
@@ -33,6 +33,9 @@ pub mod primitive;
pub mod renderer;
pub mod window;
+#[cfg(feature = "geometry")]
+pub mod geometry;
+
pub use antialiasing::Antialiasing;
pub use backend::Backend;
pub use error::Error;
@@ -41,6 +44,9 @@ pub use renderer::Renderer;
pub use transformation::Transformation;
pub use viewport::Viewport;
+#[cfg(feature = "geometry")]
+pub use geometry::Geometry;
+
pub use iced_native::alignment;
pub use iced_native::text;
pub use iced_native::{
diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs
index 793ee7d7..cb57f429 100644
--- a/graphics/src/renderer.rs
+++ b/graphics/src/renderer.rs
@@ -215,15 +215,15 @@ where
}
}
-#[cfg(feature = "canvas")]
-impl<B, T> iced_native::widget::canvas::Renderer for Renderer<B, T>
+#[cfg(feature = "geometry")]
+impl<B, T> crate::geometry::Renderer for Renderer<B, T>
where
B: Backend,
{
- type Geometry = B::Geometry;
+ type Geometry = crate::Geometry;
fn draw(&mut self, layers: Vec<Self::Geometry>) {
self.primitives
- .extend(layers.into_iter().map(B::Geometry::into));
+ .extend(layers.into_iter().map(crate::Geometry::into));
}
}