mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-29 21:34:50 +00:00
Add support for embedding resources in the rust generator
This is relatively straight-forward via a pass in the compiler to collect the resources to embed and then use include_bytes! (once per resource). What's really annoying is that the rust resource enum can't store a &'static [u8] because cbindgen doesn't represent that, probably because the slice representation isn't guaranteed to stay as it is. So instead this, for now, uses raw pointers.
This commit is contained in:
parent
82a7c3e070
commit
1404cb73ae
15 changed files with 105 additions and 98 deletions
|
@ -314,6 +314,11 @@ impl RenderingPrimitivesBuilder for GLRenderingPrimitivesBuilder {
|
|||
let image = image::open(image_path.as_path()).unwrap().into_rgba();
|
||||
Some(self.create_image(image))
|
||||
}
|
||||
Resource::EmbeddedData { ptr, len } => {
|
||||
let image_slice = unsafe { std::slice::from_raw_parts(*ptr, *len) };
|
||||
let image = image::load_from_memory(image_slice).unwrap().to_rgba();
|
||||
Some(self.create_image(image))
|
||||
}
|
||||
Resource::None => None,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue