Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/views/img.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::PathBuf;
use std::rc::Rc;

use floem_reactive::create_effect;
Expand Down Expand Up @@ -89,10 +90,23 @@ pub struct Img {
content_node: Option<NodeId>,
}

#[deprecated]
pub fn img(image: impl Fn() -> Vec<u8> + 'static) -> Img {
img_from_bytes(image)
}

pub fn img_from_bytes(image: impl Fn() -> Vec<u8> + 'static) -> Img {
img_dynamic(move || image::load_from_memory(&image()).ok().map(Rc::new))
}

pub fn img_from_image(image: impl Fn() -> DynamicImage + 'static) -> Img {
img_dynamic(move || Some(Rc::new(image())))
}

pub fn img_from_path(image: impl Fn() -> PathBuf + 'static) -> Img {
img_dynamic(move || image::open(&image()).ok().map(Rc::new))
}

pub(crate) fn img_dynamic(image: impl Fn() -> Option<Rc<DynamicImage>> + 'static) -> Img {
let id = ViewId::new();
create_effect(move |_| {
Expand Down
Loading