From 5d045c2e9a639f8bbf43e68fde9091be702b3ab8 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 26 May 2020 17:15:55 -0700 Subject: [PATCH] rename to image::Viewer --- native/src/widget.rs | 3 - native/src/widget/image.rs | 3 + .../{image_viewer.rs => image/viewer.rs} | 77 +++++++++---------- src/widget.rs | 16 +--- wgpu/src/renderer/widget.rs | 2 - wgpu/src/renderer/widget/image.rs | 2 + .../{image_viewer.rs => image/viewer.rs} | 6 +- wgpu/src/widget.rs | 8 -- wgpu/src/widget/image_viewer.rs | 6 -- 9 files changed, 50 insertions(+), 73 deletions(-) rename native/src/widget/{image_viewer.rs => image/viewer.rs} (83%) rename wgpu/src/renderer/widget/{image_viewer.rs => image/viewer.rs} (87%) delete mode 100644 wgpu/src/widget/image_viewer.rs diff --git a/native/src/widget.rs b/native/src/widget.rs index 46d41367ac..4453145bca 100644 --- a/native/src/widget.rs +++ b/native/src/widget.rs @@ -25,7 +25,6 @@ pub mod checkbox; pub mod column; pub mod container; pub mod image; -pub mod image_viewer; pub mod pane_grid; pub mod progress_bar; pub mod radio; @@ -48,8 +47,6 @@ pub use container::Container; #[doc(no_inline)] pub use image::Image; #[doc(no_inline)] -pub use image_viewer::ImageViewer; -#[doc(no_inline)] pub use pane_grid::PaneGrid; #[doc(no_inline)] pub use progress_bar::ProgressBar; diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 132f249d86..685cb81ae0 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -1,4 +1,7 @@ //! Display images in your user interface. +pub mod viewer; +pub use viewer::{State, Viewer}; + use crate::{layout, Element, Hasher, Layout, Length, Point, Size, Widget}; use std::{ diff --git a/native/src/widget/image_viewer.rs b/native/src/widget/image/viewer.rs similarity index 83% rename from native/src/widget/image_viewer.rs rename to native/src/widget/image/viewer.rs index d0f31cb49e..c33f3a5e90 100644 --- a/native/src/widget/image_viewer.rs +++ b/native/src/widget/image/viewer.rs @@ -8,7 +8,7 @@ use std::{f32, hash::Hash, u32}; /// A widget that can display an image with the ability to zoom in/out and pan. #[allow(missing_debug_implementations)] -pub struct ImageViewer<'a> { +pub struct Viewer<'a> { state: &'a mut State, padding: u16, width: Length, @@ -18,14 +18,14 @@ pub struct ImageViewer<'a> { handle: image::Handle, } -impl<'a> ImageViewer<'a> { - /// Creates a new [`ImageViewer`] with the given [`State`] and [`Handle`]. +impl<'a> Viewer<'a> { + /// Creates a new [`Viewer`] with the given [`State`] and [`Handle`]. /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html /// [`State`]: struct.State.html - /// [`Handle`]: ../image/struct.Handle.html + /// [`Handle`]: ../../image/struct.Handle.html pub fn new(state: &'a mut State, handle: image::Handle) -> Self { - ImageViewer { + Viewer { state, padding: 0, width: Length::Shrink, @@ -36,48 +36,48 @@ impl<'a> ImageViewer<'a> { } } - /// Sets the padding of the [`ImageViewer`]. + /// Sets the padding of the [`Viewer`]. /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html pub fn padding(mut self, units: u16) -> Self { self.padding = units; self } - /// Sets the width of the [`ImageViewer`]. + /// Sets the width of the [`Viewer`]. /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html pub fn width(mut self, width: Length) -> Self { self.width = width; self } - /// Sets the height of the [`ImageViewer`]. + /// Sets the height of the [`Viewer`]. /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html pub fn height(mut self, height: Length) -> Self { self.height = height; self } - /// Sets the max width of the [`ImageViewer`]. + /// Sets the max width of the [`Viewer`]. /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html pub fn max_width(mut self, max_width: u32) -> Self { self.max_width = max_width; self } - /// Sets the max height of the [`ImageViewer`]. + /// Sets the max height of the [`Viewer`]. /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html pub fn max_height(mut self, max_height: u32) -> Self { self.max_height = max_height; self } } -impl<'a, Message, Renderer> Widget for ImageViewer<'a> +impl<'a, Message, Renderer> Widget for Viewer<'a> where Renderer: self::Renderer + image::Renderer, { @@ -263,9 +263,9 @@ where } } -/// The local state of an [`ImageViewer`]. +/// The local state of a [`Viewer`]. /// -/// [`ImageViewer`]: struct.ImageViewer.html +/// [`Viewer`]: struct.Viewer.html #[derive(Debug, Clone, Copy, Default)] pub struct State { scale: Option, @@ -283,9 +283,9 @@ impl State { } /// Apply a panning offset to the current [`State`], given the bounds of - /// the [`ImageViewer`] and its image. + /// the [`Viewer`] and its image. /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html /// [`State`]: struct.State.html fn pan( &mut self, @@ -311,9 +311,9 @@ impl State { } /// Returns the current clipping offset of the [`State`], given the bounds - /// of the [`ImageViewer`] and its contents. + /// of the [`Viewer`] and its contents. /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html /// [`State`]: struct.State.html fn offset(&self, bounds: Rectangle, image_bounds: Rectangle) -> (u32, u32) { let hidden_width = ((image_bounds.width - bounds.width) as f32) @@ -331,36 +331,36 @@ impl State { } /// Returns if the left mouse button is still held down since clicking inside - /// the [`ImageViewer`]. + /// the [`Viewer`]. /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html /// [`State`]: struct.State.html pub fn is_cursor_clicked(&self) -> bool { self.starting_cursor_pos.is_some() } } -/// The renderer of an [`ImageViewer`]. +/// The renderer of an [`Viewer`]. /// /// Your [renderer] will need to implement this trait before being -/// able to use a [`ImageViewer`] in your user interface. +/// able to use a [`Viewer`] in your user interface. /// -/// [`ImageViewer`]: struct.ImageViewer.html -/// [renderer]: ../../renderer/index.html +/// [`Viewer`]: struct.Viewer.html +/// [renderer]: ../../../renderer/index.html pub trait Renderer: crate::Renderer + Sized { - /// Draws the [`ImageViewer`]. + /// Draws the [`Viewer`]. /// /// It receives: - /// - the [`State`] of the [`ImageViewer`] - /// - the bounds of the [`ImageViewer`] widget - /// - the bounds of the scaled [`ImageViewer`] image + /// - the [`State`] of the [`Viewer`] + /// - the bounds of the [`Viewer`] widget + /// - the bounds of the scaled [`Viewer`] image /// - the clipping x,y offset /// - the [`Handle`] to the underlying image - /// - whether the mouse is over the [`ImageViewer`] or not + /// - whether the mouse is over the [`Viewer`] or not /// - /// [`ImageViewer`]: struct.ImageViewer.html + /// [`Viewer`]: struct.Viewer.html /// [`State`]: struct.State.html - /// [`Handle`]: ../image/struct.Handle.html + /// [`Handle`]: ../../image/struct.Handle.html fn draw( &mut self, state: &State, @@ -372,13 +372,12 @@ pub trait Renderer: crate::Renderer + Sized { ) -> Self::Output; } -impl<'a, Message, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'a + self::Renderer + image::Renderer, Message: 'a, { - fn from(viewer: ImageViewer<'a>) -> Element<'a, Message, Renderer> { + fn from(viewer: Viewer<'a>) -> Element<'a, Message, Renderer> { Element::new(viewer) } } diff --git a/src/widget.rs b/src/widget.rs index 92303277c3..0b0b25db39 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -30,8 +30,7 @@ mod platform { #[cfg_attr(docsrs, doc(cfg(feature = "image")))] pub mod image { //! Display images in your user interface. - pub use iced_winit::image::{Handle, Image}; - pub use iced_winit::image_viewer::{ImageViewer, State}; + pub use iced_winit::image::{Handle, Image, State, Viewer}; } #[cfg_attr(docsrs, doc(cfg(feature = "svg")))] @@ -44,16 +43,9 @@ mod platform { #[doc(no_inline)] pub use { - button::Button, - checkbox::Checkbox, - container::Container, - image::{Image, ImageViewer}, - pane_grid::PaneGrid, - progress_bar::ProgressBar, - radio::Radio, - scrollable::Scrollable, - slider::Slider, - svg::Svg, + button::Button, checkbox::Checkbox, container::Container, image::Image, + pane_grid::PaneGrid, progress_bar::ProgressBar, radio::Radio, + scrollable::Scrollable, slider::Slider, svg::Svg, text_input::TextInput, }; diff --git a/wgpu/src/renderer/widget.rs b/wgpu/src/renderer/widget.rs index c9f288c71a..37421fbef9 100644 --- a/wgpu/src/renderer/widget.rs +++ b/wgpu/src/renderer/widget.rs @@ -17,5 +17,3 @@ mod svg; #[cfg(feature = "image")] mod image; -#[cfg(feature = "image")] -mod image_viewer; diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs index c4c0498497..d32c078a53 100644 --- a/wgpu/src/renderer/widget/image.rs +++ b/wgpu/src/renderer/widget/image.rs @@ -1,3 +1,5 @@ +mod viewer; + use crate::{Primitive, Renderer}; use iced_native::{image, mouse, Layout}; diff --git a/wgpu/src/renderer/widget/image_viewer.rs b/wgpu/src/renderer/widget/image/viewer.rs similarity index 87% rename from wgpu/src/renderer/widget/image_viewer.rs rename to wgpu/src/renderer/widget/image/viewer.rs index b8546d4344..72e5d93bcb 100644 --- a/wgpu/src/renderer/widget/image_viewer.rs +++ b/wgpu/src/renderer/widget/image/viewer.rs @@ -1,10 +1,10 @@ use crate::{Primitive, Renderer}; -use iced_native::{image, image_viewer, mouse, Rectangle, Vector}; +use iced_native::{image, mouse, Rectangle, Vector}; -impl image_viewer::Renderer for Renderer { +impl image::viewer::Renderer for Renderer { fn draw( &mut self, - state: &image_viewer::State, + state: &image::State, bounds: Rectangle, image_bounds: Rectangle, offset: (u32, u32), diff --git a/wgpu/src/widget.rs b/wgpu/src/widget.rs index e968c366ef..32ccad1772 100644 --- a/wgpu/src/widget.rs +++ b/wgpu/src/widget.rs @@ -47,11 +47,3 @@ pub mod canvas; #[cfg(feature = "canvas")] #[doc(no_inline)] pub use canvas::Canvas; - -#[cfg(feature = "image")] -#[doc(no_inline)] -pub mod image_viewer; - -#[cfg(feature = "image")] -#[doc(no_inline)] -pub use image_viewer::ImageViewer; diff --git a/wgpu/src/widget/image_viewer.rs b/wgpu/src/widget/image_viewer.rs deleted file mode 100644 index ec44e30ac7..0000000000 --- a/wgpu/src/widget/image_viewer.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! Zoom and pan on an image. - -pub use iced_native::image_viewer::State; - -/// A widget that can display an image with the ability to zoom in/out and pan. -pub type ImageViewer<'a> = iced_native::ImageViewer<'a>;