diff options
author | 2023-03-01 21:34:26 +0100 | |
---|---|---|
committer | 2023-03-01 21:34:26 +0100 | |
commit | 5fd5d1cdf8e5354788dc40729c4565ef377d3bba (patch) | |
tree | 0921efc7dc13a3050e03482147a791f85515f1f2 /examples/bezier_tool | |
parent | 3f6e28fa9b1b8d911f765c9efb5249a9e0c942d5 (diff) | |
download | iced-5fd5d1cdf8e5354788dc40729c4565ef377d3bba.tar.gz iced-5fd5d1cdf8e5354788dc40729c4565ef377d3bba.tar.bz2 iced-5fd5d1cdf8e5354788dc40729c4565ef377d3bba.zip |
Implement `Canvas` support for `iced_tiny_skia`
Diffstat (limited to 'examples/bezier_tool')
-rw-r--r-- | examples/bezier_tool/src/main.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 7c3916d4..5bb463c3 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -64,7 +64,7 @@ mod bezier { use iced::widget::canvas::{ self, Canvas, Cursor, Frame, Geometry, Path, Stroke, }; - use iced::{Element, Length, Point, Rectangle, Theme}; + use iced::{Element, Length, Point, Rectangle, Renderer, Theme}; #[derive(Default)] pub struct State { @@ -92,7 +92,7 @@ mod bezier { curves: &'a [Curve], } - impl<'a> canvas::Program<Curve> for Bezier<'a> { + impl<'a> canvas::Program<Curve, Renderer> for Bezier<'a> { type State = Option<Pending>; fn update( @@ -152,22 +152,26 @@ mod bezier { fn draw( &self, state: &Self::State, + renderer: &Renderer, _theme: &Theme, bounds: Rectangle, cursor: Cursor, ) -> Vec<Geometry> { - let content = - self.state.cache.draw(bounds.size(), |frame: &mut Frame| { + let content = self.state.cache.draw( + renderer, + bounds.size(), + |frame: &mut Frame| { Curve::draw_all(self.curves, frame); frame.stroke( &Path::rectangle(Point::ORIGIN, frame.size()), Stroke::default().with_width(2.0), ); - }); + }, + ); if let Some(pending) = state { - let pending_curve = pending.draw(bounds, cursor); + let pending_curve = pending.draw(renderer, bounds, cursor); vec![content, pending_curve] } else { @@ -216,8 +220,13 @@ mod bezier { } impl Pending { - fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Geometry { - let mut frame = Frame::new(bounds.size()); + fn draw( + &self, + renderer: &Renderer, + bounds: Rectangle, + cursor: Cursor, + ) -> Geometry { + let mut frame = Frame::new(renderer, bounds.size()); if let Some(cursor_position) = cursor.position_in(&bounds) { match *self { |