summaryrefslogtreecommitdiffstats
path: root/graphics/src/widget/canvas
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/src/widget/canvas')
-rw-r--r--graphics/src/widget/canvas/cache.rs6
-rw-r--r--graphics/src/widget/canvas/frame.rs9
-rw-r--r--graphics/src/widget/canvas/path.rs2
-rw-r--r--graphics/src/widget/canvas/path/builder.rs2
-rw-r--r--graphics/src/widget/canvas/program.rs34
5 files changed, 30 insertions, 23 deletions
diff --git a/graphics/src/widget/canvas/cache.rs b/graphics/src/widget/canvas/cache.rs
index a469417d..5af694e9 100644
--- a/graphics/src/widget/canvas/cache.rs
+++ b/graphics/src/widget/canvas/cache.rs
@@ -1,7 +1,5 @@
-use crate::{
- canvas::{Frame, Geometry},
- Primitive,
-};
+use crate::widget::canvas::{Frame, Geometry};
+use crate::Primitive;
use iced_native::Size;
use std::{cell::RefCell, sync::Arc};
diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs
index 2f46079c..417412b2 100644
--- a/graphics/src/widget/canvas/frame.rs
+++ b/graphics/src/widget/canvas/frame.rs
@@ -2,11 +2,10 @@ use std::borrow::Cow;
use iced_native::{Point, Rectangle, Size, Vector};
-use crate::{
- canvas::path,
- canvas::{Fill, Geometry, Path, Stroke, Text},
- triangle, Primitive,
-};
+use crate::triangle;
+use crate::widget::canvas::path;
+use crate::widget::canvas::{Fill, Geometry, Path, Stroke, Text};
+use crate::Primitive;
use lyon::tessellation;
diff --git a/graphics/src/widget/canvas/path.rs b/graphics/src/widget/canvas/path.rs
index 608507ad..aeb2589e 100644
--- a/graphics/src/widget/canvas/path.rs
+++ b/graphics/src/widget/canvas/path.rs
@@ -7,7 +7,7 @@ mod builder;
pub use arc::Arc;
pub use builder::Builder;
-use crate::canvas::LineDash;
+use crate::widget::canvas::LineDash;
use iced_native::{Point, Size};
use lyon::algorithms::walk::{walk_along_path, RepeatedPattern, WalkerEvent};
diff --git a/graphics/src/widget/canvas/path/builder.rs b/graphics/src/widget/canvas/path/builder.rs
index c49ccdc3..5121aa68 100644
--- a/graphics/src/widget/canvas/path/builder.rs
+++ b/graphics/src/widget/canvas/path/builder.rs
@@ -1,4 +1,4 @@
-use crate::canvas::path::{arc, Arc, Path};
+use crate::widget::canvas::path::{arc, Arc, Path};
use iced_native::{Point, Size};
use lyon::path::builder::SvgPathBuilder;
diff --git a/graphics/src/widget/canvas/program.rs b/graphics/src/widget/canvas/program.rs
index dddc387d..656dbfa6 100644
--- a/graphics/src/widget/canvas/program.rs
+++ b/graphics/src/widget/canvas/program.rs
@@ -1,8 +1,7 @@
-use crate::canvas::event::{self, Event};
-use crate::canvas::{Cursor, Geometry};
-
-use iced_native::mouse;
-use iced_native::Rectangle;
+use crate::widget::canvas::event::{self, Event};
+use crate::widget::canvas::mouse;
+use crate::widget::canvas::{Cursor, Geometry};
+use crate::Rectangle;
/// The state and logic of a [`Canvas`].
///
@@ -11,7 +10,10 @@ use iced_native::Rectangle;
///
/// [`Canvas`]: crate::widget::Canvas
pub trait Program<Message, Theme = iced_native::Theme> {
- /// Updates the state of the [`Program`].
+ /// The internal state mutated by the [`Program`].
+ type State: Default + 'static;
+
+ /// Updates the [`State`](Self::State) of the [`Program`].
///
/// When a [`Program`] is used in a [`Canvas`], the runtime will call this
/// method for each [`Event`].
@@ -23,7 +25,8 @@ pub trait Program<Message, Theme = iced_native::Theme> {
///
/// [`Canvas`]: crate::widget::Canvas
fn update(
- &mut self,
+ &self,
+ _state: &mut Self::State,
_event: Event,
_bounds: Rectangle,
_cursor: Cursor,
@@ -40,6 +43,7 @@ pub trait Program<Message, Theme = iced_native::Theme> {
/// [`Cache`]: crate::widget::canvas::Cache
fn draw(
&self,
+ state: &Self::State,
theme: &Theme,
bounds: Rectangle,
cursor: Cursor,
@@ -53,6 +57,7 @@ pub trait Program<Message, Theme = iced_native::Theme> {
/// [`Canvas`]: crate::widget::Canvas
fn mouse_interaction(
&self,
+ _state: &Self::State,
_bounds: Rectangle,
_cursor: Cursor,
) -> mouse::Interaction {
@@ -60,33 +65,38 @@ pub trait Program<Message, Theme = iced_native::Theme> {
}
}
-impl<T, Message, Theme> Program<Message, Theme> for &mut T
+impl<Message, Theme, T> Program<Message, Theme> for &T
where
T: Program<Message, Theme>,
{
+ type State = T::State;
+
fn update(
- &mut self,
+ &self,
+ state: &mut Self::State,
event: Event,
bounds: Rectangle,
cursor: Cursor,
) -> (event::Status, Option<Message>) {
- T::update(self, event, bounds, cursor)
+ T::update(self, state, event, bounds, cursor)
}
fn draw(
&self,
+ state: &Self::State,
theme: &Theme,
bounds: Rectangle,
cursor: Cursor,
) -> Vec<Geometry> {
- T::draw(self, theme, bounds, cursor)
+ T::draw(self, state, theme, bounds, cursor)
}
fn mouse_interaction(
&self,
+ state: &Self::State,
bounds: Rectangle,
cursor: Cursor,
) -> mouse::Interaction {
- T::mouse_interaction(self, bounds, cursor)
+ T::mouse_interaction(self, state, bounds, cursor)
}
}