use crate::icon::{BadIcon, RgbaIcon};
#[derive(Debug, Clone)]
pub struct PlatformIcon(gtk::gdk_pixbuf::Pixbuf);
unsafe impl Send for PlatformIcon {}
unsafe impl Sync for PlatformIcon {}
impl PlatformIcon {
pub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Result<Self, BadIcon> {
let RgbaIcon {
rgba,
width,
height,
} = RgbaIcon::from_rgba(rgba, width, height)?;
let bytes = gtk::glib::Bytes::from_owned(rgba);
let pixbuf = gtk::gdk_pixbuf::Pixbuf::from_bytes(
&bytes,
gtk::gdk_pixbuf::Colorspace::Rgb,
true,
8,
width as i32,
height as i32,
(width * 4) as i32,
);
Ok(Self(pixbuf))
}
pub fn texture(&self) -> gtk::gdk::Texture {
gtk::gdk::Texture::for_pixbuf(&self.0)
}
}