summaryrefslogtreecommitdiffstats
path: root/web/src/widget/image.rs
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/widget/image.rs')
-rw-r--r--web/src/widget/image.rs50
1 files changed, 49 insertions, 1 deletions
diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs
index bd3e5daf..ab510bdb 100644
--- a/web/src/widget/image.rs
+++ b/web/src/widget/image.rs
@@ -2,7 +2,55 @@ use crate::{Bus, Element, Length, Widget};
use dodrio::bumpalo;
-pub use iced_core::Image;
+/// A frame that displays an image while keeping aspect ratio.
+///
+/// # Example
+///
+/// ```
+/// # use iced_web::Image;
+///
+/// let image = Image::new("resources/ferris.png");
+/// ```
+#[derive(Debug)]
+pub struct Image {
+ /// The image path
+ pub path: String,
+
+ /// The width of the image
+ pub width: Length,
+
+ /// The height of the image
+ pub height: Length,
+}
+
+impl Image {
+ /// Creates a new [`Image`] with the given path.
+ ///
+ /// [`Image`]: struct.Image.html
+ pub fn new<T: Into<String>>(path: T) -> Self {
+ Image {
+ path: path.into(),
+ width: Length::Shrink,
+ height: Length::Shrink,
+ }
+ }
+
+ /// Sets the width of the [`Image`] boundaries.
+ ///
+ /// [`Image`]: struct.Image.html
+ pub fn width(mut self, width: Length) -> Self {
+ self.width = width;
+ self
+ }
+
+ /// Sets the height of the [`Image`] boundaries.
+ ///
+ /// [`Image`]: struct.Image.html
+ pub fn height(mut self, height: Length) -> Self {
+ self.height = height;
+ self
+ }
+}
impl<Message> Widget<Message> for Image {
fn node<'b>(