2022-10-09 11:25:46 -07:00
|
|
|
use iced::{widget::svg, Length};
|
2022-09-30 09:35:55 -06:00
|
|
|
|
2022-11-01 13:06:00 +01:00
|
|
|
pub fn icon<Renderer>(name: &str, size: u16) -> svg::Svg<Renderer>
|
|
|
|
|
where
|
|
|
|
|
Renderer: iced_native::svg::Renderer,
|
|
|
|
|
Renderer::Theme: iced_native::svg::StyleSheet,
|
|
|
|
|
{
|
2022-09-30 09:35:55 -06:00
|
|
|
let handle = match freedesktop_icons::lookup(name)
|
|
|
|
|
.with_size(size)
|
|
|
|
|
.with_theme("Pop")
|
|
|
|
|
.with_cache()
|
|
|
|
|
.force_svg()
|
|
|
|
|
.find()
|
|
|
|
|
{
|
|
|
|
|
Some(path) => svg::Handle::from_path(path),
|
|
|
|
|
None => {
|
|
|
|
|
eprintln!("icon '{}' size {} not found", name, size);
|
|
|
|
|
svg::Handle::from_memory(Vec::new())
|
2022-10-09 11:25:46 -07:00
|
|
|
}
|
2022-09-30 09:35:55 -06:00
|
|
|
};
|
|
|
|
|
svg::Svg::new(handle)
|
2022-09-30 09:51:00 -06:00
|
|
|
.width(Length::Units(size))
|
|
|
|
|
.height(Length::Units(size))
|
2022-09-30 09:35:55 -06:00
|
|
|
}
|