icon.rs (758B)
1 use iced::{ 2 Color, Element, Length, Theme, 3 widget::{Svg, button, svg}, 4 }; 5 use rust_embed::Embed; 6 7 #[derive(Embed)] 8 #[folder = "icons/"] 9 #[prefix = "icons/"] 10 struct Icon; 11 12 pub fn icon<'a>(path: &str) -> Svg<'a, iced::Theme> { 13 let bytes = Icon::get(path).unwrap().data; 14 15 svg(svg::Handle::from_memory(bytes)) 16 .height(Length::Fixed(16.0)) 17 .width(Length::Fixed(16.0)) 18 .style(white) 19 } 20 21 pub fn icon_button<'a, Message: 'a + Clone>( 22 handle: &str, 23 on_press: Message, 24 ) -> Element<'a, Message> { 25 button(icon(handle)) 26 .style(button::text) 27 .on_press(on_press) 28 .into() 29 } 30 31 fn white(_theme: &Theme, _status: svg::Status) -> svg::Style { 32 svg::Style { 33 color: Some(Color::WHITE), 34 } 35 }