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:
- 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?
- 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)? Likectx.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:
- 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?
- 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)? Likectx.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.
1 Answer
Reset to default 0You 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条)