feat(button): add ImageButton widget variant

This commit is contained in:
Michael Aaron Murphy 2023-10-30 16:32:10 +01:00 committed by Michael Murphy
parent 470b966e8d
commit 34386561b3
6 changed files with 191 additions and 20 deletions

View file

@ -50,6 +50,24 @@ pub struct Icon {
}
impl Icon {
#[must_use]
pub fn into_svg_handle(self) -> Option<crate::widget::svg::Handle> {
match self.handle.data {
Data::Name(named) => {
if let Some(path) = named.path() {
if path.extension().is_some_and(|ext| ext == OsStr::new("svg")) {
return Some(iced_core::svg::Handle::from_path(path));
}
}
}
Data::Image(_) => (),
Data::Svg(handle) => return Some(handle),
}
None
}
#[must_use]
fn into_element<Message: 'static>(self) -> Element<'static, Message> {
let from_image = |handle| {