1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Specify deifferent minification and magnification filters (#2224)

* Specify deifferent minification and magnification filters

* Fixes

* Update changelogs

* Doctest fixes

* Add deprecation notice for RetainedImage::with_texture_filter
This commit is contained in:
Emil Ernerfeldt
2022-11-02 17:54:06 +01:00
committed by GitHub
parent 8e79a5a8ae
commit 34e6e12f00
19 changed files with 147 additions and 97 deletions

View File

@@ -1,5 +1,4 @@
use egui::mutex::Mutex;
use egui::TextureFilter;
use egui::{mutex::Mutex, TextureFilter, TextureOptions};
/// An image to be shown in egui.
///
@@ -13,7 +12,7 @@ pub struct RetainedImage {
image: Mutex<egui::ColorImage>,
/// Lazily loaded when we have an egui context.
texture: Mutex<Option<egui::TextureHandle>>,
filter: TextureFilter,
options: TextureOptions,
}
impl RetainedImage {
@@ -23,7 +22,7 @@ impl RetainedImage {
size: image.size,
image: Mutex::new(image),
texture: Default::default(),
filter: Default::default(),
options: Default::default(),
}
}
@@ -68,7 +67,7 @@ impl RetainedImage {
Self::from_svg_bytes(debug_name, svg_str.as_bytes())
}
/// Set the texture filter to use for the image.
/// Set the texture filters to use for the image.
///
/// **Note:** If the texture has already been uploaded to the GPU, this will require
/// re-uploading the texture with the updated filter.
@@ -76,7 +75,7 @@ impl RetainedImage {
/// # Example
/// ```rust
/// # use egui_extras::RetainedImage;
/// # use egui::{Color32, epaint::{ColorImage, textures::TextureFilter}};
/// # use egui::{Color32, epaint::{ColorImage, textures::TextureOptions}};
/// # let pixels = vec![Color32::BLACK];
/// # let color_image = ColorImage {
/// # size: [1, 1],
@@ -85,10 +84,10 @@ impl RetainedImage {
/// #
/// // Upload a pixel art image without it getting blurry when resized
/// let image = RetainedImage::from_color_image("my_image", color_image)
/// .with_texture_filter(TextureFilter::Nearest);
/// .with_options(TextureOptions::NEAREST);
/// ```
pub fn with_texture_filter(mut self, filter: TextureFilter) -> Self {
self.filter = filter;
pub fn with_options(mut self, options: TextureOptions) -> Self {
self.options = options;
// If the texture has already been uploaded, this will force it to be re-uploaded with the
// updated filter.
@@ -97,6 +96,14 @@ impl RetainedImage {
self
}
#[deprecated = "Use with_options instead"]
pub fn with_texture_filter(self, filter: TextureFilter) -> Self {
self.with_options(TextureOptions {
magnification: filter,
minification: filter,
})
}
/// The size of the image data (number of pixels wide/high).
pub fn size(&self) -> [usize; 2] {
self.size
@@ -130,7 +137,7 @@ impl RetainedImage {
.get_or_insert_with(|| {
let image: &mut ColorImage = &mut self.image.lock();
let image = std::mem::take(image);
ctx.load_texture(&self.debug_name, image, self.filter)
ctx.load_texture(&self.debug_name, image, self.options)
})
.id()
}