diff options
Diffstat (limited to '')
-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-- | native/Cargo.toml | 5 | ||||
-rw-r--r-- | src/widget/canvas.rs (renamed from native/src/widget/canvas.rs) | 83 | ||||
-rw-r--r-- | src/widget/canvas/cursor.rs (renamed from native/src/widget/canvas/cursor.rs) | 0 | ||||
-rw-r--r-- | src/widget/canvas/event.rs (renamed from native/src/widget/canvas/event.rs) | 8 | ||||
-rw-r--r-- | src/widget/canvas/program.rs (renamed from native/src/widget/canvas/program.rs) | 8 |
12 files changed, 44 insertions, 72 deletions
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/native/Cargo.toml b/native/Cargo.toml index 23533e33..1eedf0da 100644 --- a/native/Cargo.toml +++ b/native/Cargo.toml @@ -8,7 +8,6 @@ license = "MIT" repository = "https://github.com/iced-rs/iced" [features] -canvas = ["lyon_path"] debug = [] [dependencies] @@ -29,7 +28,3 @@ features = ["thread-pool"] [dependencies.iced_style] version = "0.7" path = "../style" - -[dependencies.lyon_path] -version = "1" -optional = true diff --git a/native/src/widget/canvas.rs b/src/widget/canvas.rs index 8a9addd2..bc5995c6 100644 --- a/native/src/widget/canvas.rs +++ b/src/widget/canvas.rs @@ -1,35 +1,22 @@ //! 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 event; -pub mod fill; -pub mod path; -pub mod stroke; mod cursor; mod program; -mod style; -mod text; -pub use crate::gradient::{self, Gradient}; pub use cursor::Cursor; pub use event::Event; -pub use fill::Fill; -pub use path::Path; pub use program::Program; -pub use stroke::{LineCap, LineDash, LineJoin, Stroke}; -pub use style::Style; -pub use text::Text; - -use crate::layout::{self, Layout}; -use crate::mouse; -use crate::renderer; -use crate::widget::tree::{self, Tree}; -use crate::{ - Clipboard, Element, Length, Point, Rectangle, Shell, Size, Vector, Widget, -}; + +pub use iced_renderer::geometry::*; + +use crate::{Length, Point, Rectangle, Size, Vector}; + +use iced_native::layout::{self, Layout}; +use iced_native::mouse; +use iced_native::renderer; +use iced_native::widget::tree::{self, Tree}; +use iced_native::{Clipboard, Element, Shell, Widget}; use std::marker::PhantomData; @@ -39,14 +26,8 @@ use std::marker::PhantomData; /// If you want to get a quick overview, here's how we can draw a simple circle: /// /// ```no_run -/// # mod iced { -/// # pub mod widget { -/// # pub use iced_graphics::widget::canvas; -/// # } -/// # pub use iced_native::{Color, Rectangle, Theme}; -/// # } /// use iced::widget::canvas::{self, Canvas, Cursor, Fill, Frame, Geometry, Path, Program}; -/// use iced::{Color, Rectangle, Theme}; +/// use iced::{Color, Rectangle, Theme, Renderer}; /// /// // First, we define the data we need for drawing /// #[derive(Debug)] @@ -58,9 +39,9 @@ use std::marker::PhantomData; /// impl Program<()> for Circle { /// type State = (); /// -/// fn draw(&self, _state: &(), _theme: &Theme, bounds: Rectangle, _cursor: Cursor) -> Vec<Geometry>{ +/// fn draw(&self, _state: &(), renderer: &Renderer, _theme: &Theme, bounds: Rectangle, _cursor: Cursor) -> Vec<Geometry>{ /// // We prepare a new `Frame` -/// let mut frame = Frame::new(bounds.size()); +/// let mut frame = Frame::new(renderer, bounds.size()); /// /// // We create a `Path` representing a simple circle /// let circle = Path::circle(frame.center(), self.radius); @@ -77,9 +58,9 @@ use std::marker::PhantomData; /// let canvas = Canvas::new(Circle { radius: 50.0 }); /// ``` #[derive(Debug)] -pub struct Canvas<Message, Renderer, P> +pub struct Canvas<P, Message, Renderer = crate::Renderer> where - Renderer: self::Renderer, + Renderer: iced_renderer::geometry::Renderer, P: Program<Message, Renderer>, { width: Length, @@ -89,9 +70,9 @@ where theme_: PhantomData<Renderer>, } -impl<Message, Renderer, P> Canvas<Message, Renderer, P> +impl<P, Message, Renderer> Canvas<P, Message, Renderer> where - Renderer: self::Renderer, + Renderer: iced_renderer::geometry::Renderer, P: Program<Message, Renderer>, { const DEFAULT_SIZE: f32 = 100.0; @@ -120,10 +101,10 @@ where } } -impl<Message, Renderer, P> Widget<Message, Renderer> - for Canvas<Message, Renderer, P> +impl<P, Message, Renderer> Widget<Message, Renderer> + for Canvas<P, Message, Renderer> where - Renderer: self::Renderer, + Renderer: iced_renderer::geometry::Renderer, P: Program<Message, Renderer>, { fn tag(&self) -> tree::Tag { @@ -157,7 +138,7 @@ where fn on_event( &mut self, tree: &mut Tree, - event: crate::Event, + event: iced_native::Event, layout: Layout<'_>, cursor_position: Point, _renderer: &Renderer, @@ -167,9 +148,13 @@ where let bounds = layout.bounds(); let canvas_event = match event { - crate::Event::Mouse(mouse_event) => Some(Event::Mouse(mouse_event)), - crate::Event::Touch(touch_event) => Some(Event::Touch(touch_event)), - crate::Event::Keyboard(keyboard_event) => { + iced_native::Event::Mouse(mouse_event) => { + Some(Event::Mouse(mouse_event)) + } + iced_native::Event::Touch(touch_event) => { + Some(Event::Touch(touch_event)) + } + iced_native::Event::Keyboard(keyboard_event) => { Some(Event::Keyboard(keyboard_event)) } _ => None, @@ -238,22 +223,16 @@ where } } -impl<'a, Message, Renderer, P> From<Canvas<Message, Renderer, P>> +impl<'a, P, Message, Renderer> From<Canvas<P, Message, Renderer>> for Element<'a, Message, Renderer> where Message: 'a, - Renderer: 'a + self::Renderer, + Renderer: 'a + iced_renderer::geometry::Renderer, P: Program<Message, Renderer> + 'a, { fn from( - canvas: Canvas<Message, Renderer, P>, + canvas: Canvas<P, Message, Renderer>, ) -> Element<'a, Message, Renderer> { Element::new(canvas) } } - -pub trait Renderer: crate::Renderer { - type Geometry; - - fn draw(&mut self, geometry: Vec<Self::Geometry>); -} diff --git a/native/src/widget/canvas/cursor.rs b/src/widget/canvas/cursor.rs index ef6a7771..ef6a7771 100644 --- a/native/src/widget/canvas/cursor.rs +++ b/src/widget/canvas/cursor.rs diff --git a/native/src/widget/canvas/event.rs b/src/widget/canvas/event.rs index 1d726577..7c733a4d 100644 --- a/native/src/widget/canvas/event.rs +++ b/src/widget/canvas/event.rs @@ -1,9 +1,9 @@ //! Handle events of a canvas. -use crate::keyboard; -use crate::mouse; -use crate::touch; +use iced_native::keyboard; +use iced_native::mouse; +use iced_native::touch; -pub use crate::event::Status; +pub use iced_native::event::Status; /// A [`Canvas`] event. /// diff --git a/native/src/widget/canvas/program.rs b/src/widget/canvas/program.rs index 17a5a137..fd15663a 100644 --- a/native/src/widget/canvas/program.rs +++ b/src/widget/canvas/program.rs @@ -1,6 +1,6 @@ use crate::widget::canvas::event::{self, Event}; use crate::widget::canvas::mouse; -use crate::widget::canvas::{Cursor, Renderer}; +use crate::widget::canvas::Cursor; use crate::Rectangle; /// The state and logic of a [`Canvas`]. @@ -9,9 +9,9 @@ use crate::Rectangle; /// application. /// /// [`Canvas`]: crate::widget::Canvas -pub trait Program<Message, Renderer> +pub trait Program<Message, Renderer = crate::Renderer> where - Renderer: self::Renderer, + Renderer: iced_renderer::geometry::Renderer, { /// The internal state mutated by the [`Program`]. type State: Default + 'static; @@ -71,7 +71,7 @@ where impl<Message, Renderer, T> Program<Message, Renderer> for &T where - Renderer: self::Renderer, + Renderer: iced_renderer::geometry::Renderer, T: Program<Message, Renderer>, { type State = T::State; |