Fix `Context::repaint_causes` returning no causes (#4248)

It would return the causes for repainting again collected this frame,
instead of the cause for repainting the current frame.

* Part of https://github.com/emilk/egui/issues/3931
This commit is contained in:
Emil Ernerfeldt 2024-03-27 16:14:22 +01:00 committed by GitHub
parent bc5ce77819
commit 3c029a45ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 2 deletions

View File

@ -252,7 +252,7 @@ struct ViewportState {
}
/// What called [`Context::request_repaint`]?
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct RepaintCause {
/// What file had the call that requested the repaint?
pub file: &'static str,
@ -261,6 +261,12 @@ pub struct RepaintCause {
pub line: u32,
}
impl std::fmt::Debug for RepaintCause {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}", self.file, self.line)
}
}
impl RepaintCause {
/// Capture the file and line number of the call site.
#[allow(clippy::new_without_default)]
@ -1465,7 +1471,7 @@ impl Context {
self.read(|ctx| {
ctx.viewports
.get(&ctx.viewport_id())
.map(|v| v.repaint.causes.clone())
.map(|v| v.repaint.prev_causes.clone())
})
.unwrap_or_default()
}