Implement drag source on images

Using a 128x128 thumbnail.
This commit is contained in:
Maximiliano Sandoval R 2022-01-08 16:21:27 +01:00 • committed by Christopher Davis
parent fc6d3668c0
commit 13d7a21501
5 changed files with 135 additions and 0 deletions

View file

@ -210,4 +210,22 @@ impl LpImage {
let imp = self.imp();
imp.texture.borrow().clone()
}
pub fn content_provider(&self) -> anyhow::Result<gdk::ContentProvider> {
let imp = self.imp();
let mut contents = vec![];
if let Some(file) = imp.file.borrow().as_ref() {
let content = gdk::ContentProvider::for_value(&file.to_value());
contents.push(content);
}
if let Some(texture) = imp.texture.borrow().as_ref() {
let bytes = texture.save_to_png_bytes();
let content = gdk::ContentProvider::for_bytes("image/png", &bytes);
contents.push(content);
}
Ok(gdk::ContentProvider::new_union(contents.as_slice()))
}
}