Iced: on touch/on press for svg or other widget

Created on 17 Mar 2020  路  5Comments  路  Source: hecrj/iced

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?

question

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michael-hart picture michael-hart  路  4Comments

Plecra picture Plecra  路  4Comments

Newbytee picture Newbytee  路  4Comments

jiminycrick picture jiminycrick  路  3Comments

casperstorm picture casperstorm  路  3Comments