mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Make epi::Frame cloneable so you can allocate textures in other threads (#999)
Closes https://github.com/emilk/egui/issues/673 Also adds `epi::Image`
This commit is contained in:
@@ -5,6 +5,9 @@ NOTE: [`egui_web`](egui_web/CHANGELOG.md), [`egui-winit`](egui-winit/CHANGELOG.m
|
||||
|
||||
|
||||
## Unreleased
|
||||
* `Frame` can now be cloned, saved, and passed to background threads ([#999](https://github.com/emilk/egui/pull/999)).
|
||||
* Added `Frame::request_repaint` to replace `repaint_signal` ([#999](https://github.com/emilk/egui/pull/999)).
|
||||
* Added `Frame::alloc_texture/free_texture` to replace `tex_allocator` ([#999](https://github.com/emilk/egui/pull/999)).
|
||||
|
||||
|
||||
## 0.15.0 - 2021-10-24
|
||||
|
||||
@@ -11,7 +11,7 @@ impl epi::App for MyApp {
|
||||
"Native file dialogs and drag-and-drop files"
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::CtxRef, _frame: &mut epi::Frame<'_>) {
|
||||
fn update(&mut self, ctx: &egui::CtxRef, _frame: &epi::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.label("Drag-and-drop files onto the window!");
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ impl epi::App for MyApp {
|
||||
"My egui App"
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
|
||||
fn update(&mut self, ctx: &egui::CtxRef, frame: &epi::Frame) {
|
||||
let Self { name, age } = self;
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
|
||||
@@ -10,26 +10,20 @@ impl epi::App for MyApp {
|
||||
"Show an image with eframe/egui"
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
|
||||
fn update(&mut self, ctx: &egui::CtxRef, frame: &epi::Frame) {
|
||||
if self.texture.is_none() {
|
||||
// Load the image:
|
||||
let image_data = include_bytes!("rust-logo-256x256.png");
|
||||
use image::GenericImageView;
|
||||
let image = image::load_from_memory(image_data).expect("Failed to load image");
|
||||
let image_buffer = image.to_rgba8();
|
||||
let size = (image.width() as usize, image.height() as usize);
|
||||
let size = [image.width() as usize, image.height() as usize];
|
||||
let pixels = image_buffer.into_vec();
|
||||
assert_eq!(size.0 * size.1 * 4, pixels.len());
|
||||
let pixels: Vec<_> = pixels
|
||||
.chunks_exact(4)
|
||||
.map(|p| egui::Color32::from_rgba_unmultiplied(p[0], p[1], p[2], p[3]))
|
||||
.collect();
|
||||
let image = epi::Image::from_rgba_unmultiplied(size, &pixels);
|
||||
|
||||
// Allocate a texture:
|
||||
let texture = frame
|
||||
.tex_allocator()
|
||||
.alloc_srgba_premultiplied(size, &pixels);
|
||||
let size = egui::Vec2::new(size.0 as f32, size.1 as f32);
|
||||
let texture = frame.alloc_texture(image);
|
||||
let size = egui::Vec2::new(size[0] as f32, size[1] as f32);
|
||||
self.texture = Some((size, texture));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
//! "My egui App"
|
||||
//! }
|
||||
//!
|
||||
//! fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
|
||||
//! fn update(&mut self, ctx: &egui::CtxRef, frame: &epi::Frame) {
|
||||
//! egui::CentralPanel::default().show(ctx, |ui| {
|
||||
//! ui.heading("Hello World!");
|
||||
//! });
|
||||
@@ -127,7 +127,7 @@ pub fn start_web(canvas_id: &str, app: Box<dyn epi::App>) -> Result<(), wasm_bin
|
||||
/// "My egui App"
|
||||
/// }
|
||||
///
|
||||
/// fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
|
||||
/// fn update(&mut self, ctx: &egui::CtxRef, frame: &epi::Frame) {
|
||||
/// egui::CentralPanel::default().show(ctx, |ui| {
|
||||
/// ui.heading("Hello World!");
|
||||
/// });
|
||||
|
||||
Reference in New Issue
Block a user