-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Final polish for new image loading (#3328)
* add egui logo to widget gallery * improve "no image loaders" error message * rework static URIs to accept `Cow<'static>` * remove `RetainedImage` from `http_app` in `egui_demo_app` * hide `RetainedImage` from docs * use `ui.image`/`Image` over `RawImage` * remove last remanant of `RawImage` * remove unused doc link * add style option to disable image spinners * use `Into<Image>` instead of `Into<ImageSource>` to allow configuring the underlying image * propagate `image_options` through `ImageButton` * calculate image size properly in `Button` * properly calculate size in `ImageButton` * Update crates/egui/src/widgets/image.rs Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com> * improve no image loaders error message * add `size()` helper to `TexturePoll` * try get size from poll in `Button` * add `paint_at` to `Spinner` * use `Spinner::paint_at` and hover on image button response * `show_spinner` -> `show_loading_spinner` * avoid `allocate_ui` in `Image` when painting spinner * make icon smaller + remove old texture * add `load_and_calculate_size` + expose `paint_image_at` * update `egui_plot` to paint image in the right place * Add helpers for painting an ImageSource directly * Use max_size=INF as default * Use new API in WidgetGallery * Make egui_demo_app work by default * Remove Option from scale * Refactor ImageSize * Fix docstring * Small refactor --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
- Loading branch information
Showing
25 changed files
with
534 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use super::*; | ||
|
||
#[derive(Default)] | ||
pub struct DefaultBytesLoader { | ||
cache: Mutex<HashMap<Cow<'static, str>, Bytes>>, | ||
} | ||
|
||
impl DefaultBytesLoader { | ||
pub fn insert(&self, uri: impl Into<Cow<'static, str>>, bytes: impl Into<Bytes>) { | ||
self.cache | ||
.lock() | ||
.entry(uri.into()) | ||
.or_insert_with_key(|uri| { | ||
let bytes: Bytes = bytes.into(); | ||
|
||
#[cfg(feature = "log")] | ||
log::trace!("loaded {} bytes for uri {uri:?}", bytes.len()); | ||
|
||
bytes | ||
}); | ||
} | ||
} | ||
|
||
impl BytesLoader for DefaultBytesLoader { | ||
fn id(&self) -> &str { | ||
generate_loader_id!(DefaultBytesLoader) | ||
} | ||
|
||
fn load(&self, _: &Context, uri: &str) -> BytesLoadResult { | ||
match self.cache.lock().get(uri).cloned() { | ||
Some(bytes) => Ok(BytesPoll::Ready { | ||
size: None, | ||
bytes, | ||
mime: None, | ||
}), | ||
None => Err(LoadError::NotSupported), | ||
} | ||
} | ||
|
||
fn forget(&self, uri: &str) { | ||
#[cfg(feature = "log")] | ||
log::trace!("forget {uri:?}"); | ||
|
||
let _ = self.cache.lock().remove(uri); | ||
} | ||
|
||
fn forget_all(&self) { | ||
#[cfg(feature = "log")] | ||
log::trace!("forget all"); | ||
|
||
self.cache.lock().clear(); | ||
} | ||
|
||
fn byte_size(&self) -> usize { | ||
self.cache.lock().values().map(|bytes| bytes.len()).sum() | ||
} | ||
} |
Oops, something went wrong.