summaryrefslogtreecommitdiffstats
path: root/web/src/widget/image.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-07-08 11:44:40 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-07-08 11:44:40 +0200
commitf3dfaa2c43bad16fc91660b2b73cb9173549e7ec (patch)
tree353365f4dd1e3136bc651ac8c1572f62fff1304b /web/src/widget/image.rs
parent072ec69d53d2708d8fd1693151bcec7305efccf8 (diff)
parent5c4f5ae5ecb36703a95cafb2cd58692529c9466d (diff)
downloadiced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.gz
iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.bz2
iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.zip
Merge branch 'master' into feature/pane-grid-titlebar
Diffstat (limited to 'web/src/widget/image.rs')
-rw-r--r--web/src/widget/image.rs27
1 files changed, 23 insertions, 4 deletions
diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs
index 029ab352..a595c29a 100644
--- a/web/src/widget/image.rs
+++ b/web/src/widget/image.rs
@@ -22,6 +22,9 @@ pub struct Image {
/// The image path
pub handle: Handle,
+ /// The alt text of the image
+ pub alt: String,
+
/// The width of the image
pub width: Length,
@@ -36,6 +39,7 @@ impl Image {
pub fn new<T: Into<Handle>>(handle: T) -> Self {
Image {
handle: handle.into(),
+ alt: Default::default(),
width: Length::Shrink,
height: Length::Shrink,
}
@@ -56,6 +60,14 @@ impl Image {
self.height = height;
self
}
+
+ /// Sets the alt text of the [`Image`].
+ ///
+ /// [`Image`]: struct.Image.html
+ pub fn alt(mut self, alt: impl Into<String>) -> Self {
+ self.alt = alt.into();
+ self
+ }
}
impl<Message> Widget<Message> for Image {
@@ -66,12 +78,19 @@ impl<Message> Widget<Message> for Image {
_style_sheet: &mut Css<'b>,
) -> dodrio::Node<'b> {
use dodrio::builder::*;
+ use dodrio::bumpalo::collections::String;
+
+ let src = String::from_str_in(
+ match self.handle.data.as_ref() {
+ Data::Path(path) => path.to_str().unwrap_or(""),
+ },
+ bump,
+ )
+ .into_bump_str();
- let src = bumpalo::format!(in bump, "{}", match self.handle.data.as_ref() {
- Data::Path(path) => path.to_str().unwrap_or("")
- });
+ let alt = String::from_str_in(&self.alt, bump).into_bump_str();
- let mut image = img(bump).attr("src", src.into_bump_str());
+ let mut image = img(bump).attr("src", src).attr("alt", alt);
match self.width {
Length::Shrink => {}