RepaintSignal now implements Sync so it can be sent to another thread
Fixes https://github.com/emilk/egui/issues/82
This commit is contained in:
parent
af1df8d339
commit
958fc2753a
3 changed files with 14 additions and 5 deletions
|
@ -9,6 +9,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed 🐛
|
||||||
|
|
||||||
|
* `RepaintSignal` now implements `Sync` so it can be sent to a background thread.
|
||||||
|
|
||||||
|
|
||||||
## 0.6.0 - 2020-12-26
|
## 0.6.0 - 2020-12-26
|
||||||
|
|
||||||
### Added ⭐
|
### Added ⭐
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub struct IntegrationContext<'a> {
|
||||||
pub tex_allocator: Option<&'a mut dyn TextureAllocator>,
|
pub tex_allocator: Option<&'a mut dyn TextureAllocator>,
|
||||||
/// Where the app can issue commands back to the integration.
|
/// Where the app can issue commands back to the integration.
|
||||||
pub output: AppOutput,
|
pub output: AppOutput,
|
||||||
/// If you need to request a repaint from another thread, clone this and give to that other thread
|
/// If you need to request a repaint from another thread, clone this and send it to that other thread.
|
||||||
pub repaint_signal: std::sync::Arc<dyn RepaintSignal>,
|
pub repaint_signal: std::sync::Arc<dyn RepaintSignal>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ pub trait TextureAllocator {
|
||||||
fn free(&mut self, id: crate::TextureId);
|
fn free(&mut self, id: crate::TextureId);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RepaintSignal: Send {
|
pub trait RepaintSignal: Send + Sync {
|
||||||
/// This signals the Egui integration that a repaint is required.
|
/// This signals the Egui integration that a repaint is required.
|
||||||
/// This is meant to be called when a background process finishes in an async context and/or background thread.
|
/// This is meant to be called when a background process finishes in an async context and/or background thread.
|
||||||
fn request_repaint(&self);
|
fn request_repaint(&self);
|
||||||
|
|
|
@ -31,11 +31,13 @@ impl egui::app::TextureAllocator for Painter {
|
||||||
|
|
||||||
struct RequestRepaintEvent;
|
struct RequestRepaintEvent;
|
||||||
|
|
||||||
struct GliumRepaintSignal(glutin::event_loop::EventLoopProxy<RequestRepaintEvent>);
|
struct GliumRepaintSignal(
|
||||||
|
std::sync::Mutex<glutin::event_loop::EventLoopProxy<RequestRepaintEvent>>,
|
||||||
|
);
|
||||||
|
|
||||||
impl egui::app::RepaintSignal for GliumRepaintSignal {
|
impl egui::app::RepaintSignal for GliumRepaintSignal {
|
||||||
fn request_repaint(&self) {
|
fn request_repaint(&self) {
|
||||||
self.0.send_event(RequestRepaintEvent).ok();
|
self.0.lock().unwrap().send_event(RequestRepaintEvent).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +107,9 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
||||||
let event_loop = glutin::event_loop::EventLoop::with_user_event();
|
let event_loop = glutin::event_loop::EventLoop::with_user_event();
|
||||||
let display = create_display(app.name(), window_settings, app.is_resizable(), &event_loop);
|
let display = create_display(app.name(), window_settings, app.is_resizable(), &event_loop);
|
||||||
|
|
||||||
let repaint_signal = std::sync::Arc::new(GliumRepaintSignal(event_loop.create_proxy()));
|
let repaint_signal = std::sync::Arc::new(GliumRepaintSignal(std::sync::Mutex::new(
|
||||||
|
event_loop.create_proxy(),
|
||||||
|
)));
|
||||||
|
|
||||||
let mut ctx = egui::CtxRef::default();
|
let mut ctx = egui::CtxRef::default();
|
||||||
*ctx.memory() = storage
|
*ctx.memory() = storage
|
||||||
|
|
Loading…
Reference in a new issue