summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-29 16:45:47 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-29 16:45:47 +0700
commitde728737fd69265f812f717ca70d3e0bd40838e5 (patch)
tree88b09740b76524559bff9f0e9eb0c3e018f27e0e /graphics
parent0df5b5bb7b098f480af85273eb7734e0074b26bc (diff)
downloadiced-de728737fd69265f812f717ca70d3e0bd40838e5.tar.gz
iced-de728737fd69265f812f717ca70d3e0bd40838e5.tar.bz2
iced-de728737fd69265f812f717ca70d3e0bd40838e5.zip
Implement `Widget::draw` for `Canvas` in `iced_graphics`
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/widget/canvas.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/graphics/src/widget/canvas.rs b/graphics/src/widget/canvas.rs
index 3990c2b9..1b0d49d8 100644
--- a/graphics/src/widget/canvas.rs
+++ b/graphics/src/widget/canvas.rs
@@ -4,11 +4,12 @@
//! [`Frame`]. It can be used for animation, data visualization, game graphics,
//! and more!
use crate::renderer::{self, Renderer};
-use crate::Backend;
+use crate::{Backend, Primitive};
use iced_native::layout;
use iced_native::{
- Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
+ Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Vector,
+ Widget,
};
use std::hash::Hash;
use std::marker::PhantomData;
@@ -188,31 +189,28 @@ where
fn draw(
&self,
- _renderer: &mut Renderer<B>,
+ renderer: &mut Renderer<B>,
_style: &renderer::Style,
- _layout: Layout<'_>,
- _cursor_position: Point,
+ layout: Layout<'_>,
+ cursor_position: Point,
_viewport: &Rectangle,
) {
- // let bounds = layout.bounds();
- // let translation = Vector::new(bounds.x, bounds.y);
- // let cursor = Cursor::from_window_position(cursor_position);
-
- // (
- // Primitive::Translate {
- // translation,
- // content: Box::new(Primitive::Group {
- // primitives: self
- // .program
- // .draw(bounds, cursor)
- // .into_iter()
- // .map(Geometry::into_primitive)
- // .collect(),
- // }),
- // },
- // self.program.mouse_interaction(bounds, cursor),
- // )
- // TODO
+ use iced_native::Renderer as _;
+
+ let bounds = layout.bounds();
+ let translation = Vector::new(bounds.x, bounds.y);
+ let cursor = Cursor::from_window_position(cursor_position);
+
+ renderer.with_translation(translation, |renderer| {
+ renderer.draw_primitive(Primitive::Group {
+ primitives: self
+ .program
+ .draw(bounds, cursor)
+ .into_iter()
+ .map(Geometry::into_primitive)
+ .collect(),
+ });
+ });
}
fn hash_layout(&self, state: &mut Hasher) {