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

I want to keep track of my images that have been loaded in the app. I have a vec<Image>. Here is

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"),
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742362631a4429685.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信