diff options
author | 2020-07-01 07:09:27 +0200 | |
---|---|---|
committer | 2020-07-01 07:09:27 +0200 | |
commit | 08e13e00f15fb54ced21c0375e7efba4bfbf89a0 (patch) | |
tree | 29d0b9d82307d98fdf7248a9ad59a824dda0c2d1 /web/src/widget/image.rs | |
parent | 1bc69e7a8a8ea59efc14fd765889895662c9ba46 (diff) | |
parent | ffd195cdb543dfbff42327c516d6082cb2df51ef (diff) | |
download | iced-08e13e00f15fb54ced21c0375e7efba4bfbf89a0.tar.gz iced-08e13e00f15fb54ced21c0375e7efba4bfbf89a0.tar.bz2 iced-08e13e00f15fb54ced21c0375e7efba4bfbf89a0.zip |
Merge pull request #292 from TomPridham/feature/accessibility-web
add some accessibility features to web widgets
Diffstat (limited to 'web/src/widget/image.rs')
-rw-r--r-- | web/src/widget/image.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs index 029ab352..a20bebea 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 { @@ -70,8 +82,10 @@ impl<Message> Widget<Message> for Image { let src = bumpalo::format!(in bump, "{}", match self.handle.data.as_ref() { Data::Path(path) => path.to_str().unwrap_or("") }); + let alt = bumpalo::format!(in bump, "{}", self.alt).into_bump_str(); - let mut image = img(bump).attr("src", src.into_bump_str()); + let mut image = + img(bump).attr("src", src.into_bump_str()).attr("alt", alt); match self.width { Length::Shrink => {} |