summaryrefslogtreecommitdiffstats
path: root/examples/tour/renderer/image.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-09-19 15:01:12 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-09-19 15:01:12 +0200
commitf9de39ddaa3020a9585b1648afb0ead45dfd7aa9 (patch)
tree04289787e353b4b059354d22ce53f2b79464431c /examples/tour/renderer/image.rs
parentdd093c79d7da84675be648c7df2ebfc85b5039f2 (diff)
downloadiced-f9de39ddaa3020a9585b1648afb0ead45dfd7aa9.tar.gz
iced-f9de39ddaa3020a9585b1648afb0ead45dfd7aa9.tar.bz2
iced-f9de39ddaa3020a9585b1648afb0ead45dfd7aa9.zip
Unify `web` and `ggez` tour examples :tada:
Diffstat (limited to 'examples/tour/renderer/image.rs')
-rw-r--r--examples/tour/renderer/image.rs51
1 files changed, 0 insertions, 51 deletions
diff --git a/examples/tour/renderer/image.rs b/examples/tour/renderer/image.rs
deleted file mode 100644
index c3ead5c9..00000000
--- a/examples/tour/renderer/image.rs
+++ /dev/null
@@ -1,51 +0,0 @@
-use super::Renderer;
-
-use ggez::{graphics, nalgebra};
-use iced::image;
-
-impl image::Renderer<graphics::Image> for Renderer<'_> {
- fn node(
- &self,
- style: iced::Style,
- image: &graphics::Image,
- width: Option<u16>,
- height: Option<u16>,
- _source: Option<iced::Rectangle<u16>>,
- ) -> iced::Node {
- let aspect_ratio = image.width() as f32 / image.height() as f32;
-
- let style = match (width, height) {
- (Some(width), Some(height)) => style.width(width).height(height),
- (Some(width), None) => style
- .width(width)
- .height((width as f32 / aspect_ratio).round() as u16),
- (None, Some(height)) => style
- .height(height)
- .width((height as f32 * aspect_ratio).round() as u16),
- (None, None) => style.width(image.width()).height(image.height()),
- };
-
- iced::Node::new(style)
- }
-
- fn draw(
- &mut self,
- image: &graphics::Image,
- bounds: iced::Rectangle,
- _source: Option<iced::Rectangle<u16>>,
- ) {
- // We should probably use batches to draw images efficiently and keep
- // draw side-effect free, but this is good enough for the example.
- graphics::draw(
- self.context,
- image,
- graphics::DrawParam::new()
- .dest(nalgebra::Point2::new(bounds.x, bounds.y))
- .scale(nalgebra::Vector2::new(
- bounds.width / image.width() as f32,
- bounds.height / image.height() as f32,
- )),
- )
- .expect("Draw image");
- }
-}