emilk / emilk/egui

Add an api to check if a window is "closing"

Open
#3,418 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

**Is your feature request related to a problem? Please describe.**

In my application I have implemented an error popup system that will dynamically add the error to a `Vec` . Each frame, I loop over the `Vec` and display an `egui::Window` for each error. Here's a simplified example:

```rust
use egui::{Context, Id, Window};
use anyhow::Error;

struct ErrorWindow {
open: bool,
error: Error
}

pub struct MyUi {
errors: Vec,
}

impl MyUi {
pub fn add_error_popup(&mut self, error: Error) {
self.errors.push(ErrorWindow {
open: true,
error
});
}

fn show_errors(&mut self, ctx: &Context) {
let mut i = 0;
while i < self.errors.len() {
let ErrorWindow { error, open } = &mut self.errors[i];
let id = Id::new(&**error as *const _);
Window::new("⚠ Error")
.id(id)
.open(open)
.show(ctx, |ui| {
ui.label(format!("{error:#}"));
});

// HACK: If the window is closed, it still needs to show the close animation before we remove
// it from the list. Grab the progress of the internal close animation and check if it
// has completed.
if *open || ctx.animate_bool(id.with("close_animation"), false) > 0.0 {
i += 1;
} else {
// Error window was closed, remove it from the list. Replace the current error with
// the "last" one.
let last_error = self.errors.pop().unwrap();
if let Some(error) = self.errors.get_mut(i) {
*error = last_error;
}
}
}
}
}
```

In order for the close/fade-out animation for the error windows to render, I need to keep closed error entries in the list, as I need to continue to call `Window::show()`. The above code uses `ctx.animate_bool` to get the progress of the close animation. I would consider this a "hack" as it depends on the internal implementation details of `Window`.

**Describe the solution you'd like**

Can we come up with some sort of API for users to get the progress of the window close animation? Maybe something like `window.is_closing()` or `window.closing()`?

**Describe alternatives you've considered**

Please let me know if there's already a better/supported way to do this, or if the above hack is actually the intended method.

**Additional context**

I'm happy to look at putting together a quick PR for this.

Contributor guide

Open the contributing guide

Research direction

Start with the Window::show and Context::animate_bool usage shown in the issue, and inspect how the window close animation is exposed internally. Define and document an API that lets callers detect or read the close animation state without relying on internal IDs, then verify it supports keeping a closed window visible until its animation finishes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.