Rename and add to iced image module
This commit is contained in:
parent
6bf459e068
commit
431171f975
7 changed files with 58 additions and 56 deletions
|
|
@ -25,7 +25,7 @@ pub mod checkbox;
|
||||||
pub mod column;
|
pub mod column;
|
||||||
pub mod container;
|
pub mod container;
|
||||||
pub mod image;
|
pub mod image;
|
||||||
pub mod image_pane;
|
pub mod image_viewer;
|
||||||
pub mod pane_grid;
|
pub mod pane_grid;
|
||||||
pub mod progress_bar;
|
pub mod progress_bar;
|
||||||
pub mod radio;
|
pub mod radio;
|
||||||
|
|
@ -48,7 +48,7 @@ pub use container::Container;
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use image::Image;
|
pub use image::Image;
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use image_pane::ImagePane;
|
pub use image_viewer::ImageViewer;
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use pane_grid::PaneGrid;
|
pub use pane_grid::PaneGrid;
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
|
|
|
||||||
|
|
@ -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.
|
/// A widget that can display an image with the ability to zoom in/out and pan.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct ImagePane<'a> {
|
pub struct ImageViewer<'a> {
|
||||||
state: &'a mut State,
|
state: &'a mut State,
|
||||||
padding: u16,
|
padding: u16,
|
||||||
width: Length,
|
width: Length,
|
||||||
|
|
@ -18,14 +18,14 @@ pub struct ImagePane<'a> {
|
||||||
handle: image::Handle,
|
handle: image::Handle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ImagePane<'a> {
|
impl<'a> ImageViewer<'a> {
|
||||||
/// Creates a new [`ImagePane`] with the given [`State`] and [`Handle`].
|
/// Creates a new [`ImageViewer`] with the given [`State`] and [`Handle`].
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
/// [`State`]: struct.State.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 {
|
pub fn new(state: &'a mut State, handle: image::Handle) -> Self {
|
||||||
ImagePane {
|
ImageViewer {
|
||||||
state,
|
state,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
|
|
@ -36,48 +36,48 @@ impl<'a> ImagePane<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the padding of the [`ImagePane`].
|
/// Sets the padding of the [`ImageViewer`].
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
pub fn padding(mut self, units: u16) -> Self {
|
pub fn padding(mut self, units: u16) -> Self {
|
||||||
self.padding = units;
|
self.padding = units;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the width of the [`ImagePane`].
|
/// Sets the width of the [`ImageViewer`].
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
pub fn width(mut self, width: Length) -> Self {
|
pub fn width(mut self, width: Length) -> Self {
|
||||||
self.width = width;
|
self.width = width;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the [`ImagePane`].
|
/// Sets the height of the [`ImageViewer`].
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
pub fn height(mut self, height: Length) -> Self {
|
pub fn height(mut self, height: Length) -> Self {
|
||||||
self.height = height;
|
self.height = height;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the max width of the [`ImagePane`].
|
/// Sets the max width of the [`ImageViewer`].
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||||
self.max_width = max_width;
|
self.max_width = max_width;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the max height of the [`ImagePane`].
|
/// Sets the max height of the [`ImageViewer`].
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
pub fn max_height(mut self, max_height: u32) -> Self {
|
||||||
self.max_height = max_height;
|
self.max_height = max_height;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer> Widget<Message, Renderer> for ImagePane<'a>
|
impl<'a, Message, Renderer> Widget<Message, Renderer> for ImageViewer<'a>
|
||||||
where
|
where
|
||||||
Renderer: self::Renderer + image::Renderer,
|
Renderer: self::Renderer + image::Renderer,
|
||||||
{
|
{
|
||||||
|
|
@ -263,9 +263,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The local state of an [`ImagePane`].
|
/// The local state of an [`ImageViewer`].
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Debug, Clone, Copy, Default)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
scale: Option<f32>,
|
scale: Option<f32>,
|
||||||
|
|
@ -275,7 +275,7 @@ pub struct State {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
/// Creates a new [`State`] with the scrollbar located at the top.
|
/// Creates a new [`State`].
|
||||||
///
|
///
|
||||||
/// [`State`]: struct.State.html
|
/// [`State`]: struct.State.html
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
|
@ -283,9 +283,9 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a panning offset to the current [`State`], given the bounds of
|
/// Apply a panning offset to the current [`State`], given the bounds of
|
||||||
/// the [`ImagePane`] and its image.
|
/// the [`ImageViewer`] and its image.
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
/// [`State`]: struct.State.html
|
/// [`State`]: struct.State.html
|
||||||
fn pan(
|
fn pan(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
@ -311,9 +311,9 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current clipping offset of the [`State`], given the bounds
|
/// Returns the current clipping offset of the [`State`], given the bounds
|
||||||
/// of the [`ImagePane`] and its contents.
|
/// of the [`ImageViewer`] and its contents.
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
/// [`State`]: struct.State.html
|
/// [`State`]: struct.State.html
|
||||||
fn offset(&self, bounds: Rectangle, image_bounds: Rectangle) -> (u32, u32) {
|
fn offset(&self, bounds: Rectangle, image_bounds: Rectangle) -> (u32, u32) {
|
||||||
let hidden_width = ((image_bounds.width - bounds.width) as f32)
|
let hidden_width = ((image_bounds.width - bounds.width) as f32)
|
||||||
|
|
@ -331,34 +331,34 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns if the left mouse button is still held down since clicking inside
|
/// Returns if the left mouse button is still held down since clicking inside
|
||||||
/// the [`ImagePane`].
|
/// the [`ImageViewer`].
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
/// [`State`]: struct.State.html
|
/// [`State`]: struct.State.html
|
||||||
pub fn is_cursor_clicked(&self) -> bool {
|
pub fn is_cursor_clicked(&self) -> bool {
|
||||||
self.starting_cursor_pos.is_some()
|
self.starting_cursor_pos.is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The renderer of an [`ImagePane`].
|
/// The renderer of an [`ImageViewer`].
|
||||||
///
|
///
|
||||||
/// Your [renderer] will need to implement this trait before being
|
/// Your [renderer] will need to implement this trait before being
|
||||||
/// able to use a [`ImagePane`] in your user interface.
|
/// able to use a [`ImageViewer`] in your user interface.
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
/// [renderer]: ../../renderer/index.html
|
/// [renderer]: ../../renderer/index.html
|
||||||
pub trait Renderer: crate::Renderer + Sized {
|
pub trait Renderer: crate::Renderer + Sized {
|
||||||
/// Draws the [`ImagePane`].
|
/// Draws the [`ImageViewer`].
|
||||||
///
|
///
|
||||||
/// It receives:
|
/// It receives:
|
||||||
/// - the [`State`] of the [`ImagePane`]
|
/// - the [`State`] of the [`ImageViewer`]
|
||||||
/// - the bounds of the [`ImagePane`] widget
|
/// - the bounds of the [`ImageViewer`] widget
|
||||||
/// - the bounds of the scaled [`ImagePane`] image
|
/// - the bounds of the scaled [`ImageViewer`] image
|
||||||
/// - the clipping x,y offset
|
/// - the clipping x,y offset
|
||||||
/// - the [`Handle`] to the underlying image
|
/// - the [`Handle`] to the underlying image
|
||||||
/// - whether the mouse is over the [`ImagePane`] or not
|
/// - whether the mouse is over the [`ImageViewer`] or not
|
||||||
///
|
///
|
||||||
/// [`ImagePane`]: struct.ImagePane.html
|
/// [`ImageViewer`]: struct.ImageViewer.html
|
||||||
/// [`State`]: struct.State.html
|
/// [`State`]: struct.State.html
|
||||||
/// [`Handle`]: ../image/struct.Handle.html
|
/// [`Handle`]: ../image/struct.Handle.html
|
||||||
fn draw(
|
fn draw(
|
||||||
|
|
@ -372,13 +372,13 @@ pub trait Renderer: crate::Renderer + Sized {
|
||||||
) -> Self::Output;
|
) -> Self::Output;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer> From<ImagePane<'a>>
|
impl<'a, Message, Renderer> From<ImageViewer<'a>>
|
||||||
for Element<'a, Message, Renderer>
|
for Element<'a, Message, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: 'a + self::Renderer + image::Renderer,
|
Renderer: 'a + self::Renderer + image::Renderer,
|
||||||
Message: 'a,
|
Message: 'a,
|
||||||
{
|
{
|
||||||
fn from(image_pane: ImagePane<'a>) -> Element<'a, Message, Renderer> {
|
fn from(viewer: ImageViewer<'a>) -> Element<'a, Message, Renderer> {
|
||||||
Element::new(image_pane)
|
Element::new(viewer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -31,12 +31,7 @@ mod platform {
|
||||||
pub mod image {
|
pub mod image {
|
||||||
//! Display images in your user interface.
|
//! Display images in your user interface.
|
||||||
pub use iced_winit::image::{Handle, Image};
|
pub use iced_winit::image::{Handle, Image};
|
||||||
}
|
pub use iced_winit::image_viewer::{ImageViewer, State};
|
||||||
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "image")))]
|
|
||||||
pub mod image_pane {
|
|
||||||
//! Zoom and pan on an image.
|
|
||||||
pub use iced_wgpu::image_pane::{ImagePane, State};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "svg")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "svg")))]
|
||||||
|
|
@ -49,9 +44,16 @@ mod platform {
|
||||||
|
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use {
|
pub use {
|
||||||
button::Button, checkbox::Checkbox, container::Container, image::Image,
|
button::Button,
|
||||||
image_pane::ImagePane, pane_grid::PaneGrid, progress_bar::ProgressBar,
|
checkbox::Checkbox,
|
||||||
radio::Radio, scrollable::Scrollable, slider::Slider, svg::Svg,
|
container::Container,
|
||||||
|
image::{Image, ImageViewer},
|
||||||
|
pane_grid::PaneGrid,
|
||||||
|
progress_bar::ProgressBar,
|
||||||
|
radio::Radio,
|
||||||
|
scrollable::Scrollable,
|
||||||
|
slider::Slider,
|
||||||
|
svg::Svg,
|
||||||
text_input::TextInput,
|
text_input::TextInput,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,4 @@ mod svg;
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
mod image;
|
mod image;
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
mod image_pane;
|
mod image_viewer;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::{Primitive, Renderer};
|
use crate::{Primitive, Renderer};
|
||||||
use iced_native::{image, image_pane, mouse, Rectangle, Vector};
|
use iced_native::{image, image_viewer, mouse, Rectangle, Vector};
|
||||||
|
|
||||||
impl image_pane::Renderer for Renderer {
|
impl image_viewer::Renderer for Renderer {
|
||||||
fn draw(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &image_pane::State,
|
state: &image_viewer::State,
|
||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
image_bounds: Rectangle,
|
image_bounds: Rectangle,
|
||||||
offset: (u32, u32),
|
offset: (u32, u32),
|
||||||
|
|
@ -50,8 +50,8 @@ pub use canvas::Canvas;
|
||||||
|
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub mod image_pane;
|
pub mod image_viewer;
|
||||||
|
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use image_pane::ImagePane;
|
pub use image_viewer::ImageViewer;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
//! Zoom and pan on an image.
|
//! Zoom and pan on an image.
|
||||||
|
|
||||||
pub use iced_native::image_pane::State;
|
pub use iced_native::image_viewer::State;
|
||||||
|
|
||||||
/// A widget that can display an image with the ability to zoom in/out and pan.
|
/// A widget that can display an image with the ability to zoom in/out and pan.
|
||||||
pub type ImagePane<'a> = iced_native::ImagePane<'a>;
|
pub type ImageViewer<'a> = iced_native::ImageViewer<'a>;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue