最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rust - Different ways to check if egui has loaded a image? - Stack Overflow

programmeradmin0浏览0评论

I want to keep track of my images that have been loaded in the app. I have a vec<Image>. Here is store each image (id, uri,thumbhash etc.). Now I want to add a loading state. Therefore i need to intercept the loading process in different areas of my app. Like this:


let img =egui::Image::from_uri(img_path.clone()).max_height(p_min_width).max_width(p_min_width);
let test = img.load_for_size(ctx, ui.available_size());

let loading = matches!(test, Ok(egui::load::TexturePoll::Pending { .. }));
println!(is "{:?}",loading); // Do something store in vec etc.

// loads with hash thumbnail 
frame.content_ui.add_sized(max_size, ThumbhashImage::new(img,&thash.as_ref().unwrap()));  

Question:

  1. Is this a practical way ? I mean it works, but maybe there is an easier way.Are there other ways besides ImagePoll and TexturePoll to check if some image is loaded?
  2. Egui can fet a single image by the uri with the ctx.fet_image(uri) method. Therefore i assume egui relates each uri to some specific memory space. Is it possible to retrieve some info about the current state of an image (memory)? Like ctx.info_image(uri)? I mean it seems the uri relates to the image like some id. So why not go the other way around? Tell me if something is deposited at the uri and is it loaded?

What i am looking for are different ways to check the loading state of an image without generating extra variables or fetching the info local on initialization. If the context tracks the memory for an image, it should also tell me if there is some memory allocate in relation to the uri or not.

I want to keep track of my images that have been loaded in the app. I have a vec<Image>. Here is store each image (id, uri,thumbhash etc.). Now I want to add a loading state. Therefore i need to intercept the loading process in different areas of my app. Like this:


let img =egui::Image::from_uri(img_path.clone()).max_height(p_min_width).max_width(p_min_width);
let test = img.load_for_size(ctx, ui.available_size());

let loading = matches!(test, Ok(egui::load::TexturePoll::Pending { .. }));
println!(is "{:?}",loading); // Do something store in vec etc.

// loads with hash thumbnail 
frame.content_ui.add_sized(max_size, ThumbhashImage::new(img,&thash.as_ref().unwrap()));  

Question:

  1. Is this a practical way ? I mean it works, but maybe there is an easier way.Are there other ways besides ImagePoll and TexturePoll to check if some image is loaded?
  2. Egui can fet a single image by the uri with the ctx.fet_image(uri) method. Therefore i assume egui relates each uri to some specific memory space. Is it possible to retrieve some info about the current state of an image (memory)? Like ctx.info_image(uri)? I mean it seems the uri relates to the image like some id. So why not go the other way around? Tell me if something is deposited at the uri and is it loaded?

What i am looking for are different ways to check the loading state of an image without generating extra variables or fetching the info local on initialization. If the context tracks the memory for an image, it should also tell me if there is some memory allocate in relation to the uri or not.

Share Improve this question asked Nov 20, 2024 at 11:15 black_hole_sunblack_hole_sun 9561 gold badge16 silver badges44 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You could try this:

match ui.ctx().loaders().include.load(ui.ctx(), "your uri here") {
    Ok(BytesPoll::Pending { size }) => todo!("draw loading indicator"),
    Ok(BytesPoll::Ready { size, bytes, mime }) => todo!("draw image"),
    Err(_) => todo!("draw error indicator"),
}
发布评论

评论列表(0)

  1. 暂无评论