Would be nice to allow svg to have on_press with Message to send (just like button).
Or maybe allow button to have svg/image, like image button in other framework?
A Button supports any kind of Element as its contents. You should be able to put an Svg widget inside a Button. Is there any reason why this may not work for your use case?
Oh i guess I did not know this, the examples I looked at did not seem to do this, ok will try, thank you!
I've tried adding an Svg to a button in the following way (just a snippet).
let add_svg_path = format!("{}/assets/icons/add_icon.svg", env!("CARGO_MANIFEST_DIR");
Button::new(&mut self.add_component_button, Svg::from_path(add_svg_path))
.on_press(Message::AddPressed)
However, I get the following error.
error[E0277]: the trait bound `iced_wgpu::backend::Backend: iced_graphics::backend::Svg` is not satisfied
--> src/controls.rs:91:17
|
91 | Button::new(&mut self.add_component_button, Svg::from_path(add_svg_path))
| ^^^^^^^^^^^ the trait `iced_graphics::backend::Svg` is not implemented for `iced_wgpu::backend::Backend`
|
= note: required because of the requirements on the impl of `iced_native::widget::svg::Renderer` for `iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>`
= note: required because of the requirements on the impl of `std::convert::From<iced_native::widget::svg::Svg>` for `iced_native::element::Element<'_, controls::Message, iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>>`
= note: required because of the requirements on the impl of `std::convert::Into<iced_native::element::Element<'_, controls::Message, iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>>>` for `iced_native::widget::svg::Svg`
= note: required by `iced_native::widget::button::Button::<'a, Message, Renderer>::new`
I'm pretty new to iced, so I may be missing something. What should I be doing differently?
@jmwright You may need to enable the svg feature.
@hecrj Thanks for the info, that works.