egui 0.27.0 button issue
Describe the bug After migrating to the latest version of the egui crate (0.27.0) buttons called by 4 specific functions have stopped working altogether. They seem to be frozen, not returning a correct response. Everything else seems to work as expected.
To Reproduce I couldnt reproduce this anywhere else, but in my project.
Screenshots
Desktop (please complete the following information): Windows 11 build: 22631.2715
Additional context Egui 0.27.1 has the same issue
This needs more details or it isn't actionable
Which version are you upgrading from? There was a change from 0.25 to 0.26 how this is handled (is some situations), so if it is from 0.25 there will be at least somewhere to start digging.
Which version are you upgrading from? There was a change from 0.25 to 0.26 how this is handled (is some situations), so if it is from 0.25 there will be at least somewhere to start digging.
I switched from "0.24.1" to "0.27.0" im going to test out every version to see which one is working
This needs more details or it isn't actionable
What else could I provide?
the main function is async, using #[tokio::async]
these function as called multiple times, because they're in a for loop
I can also provide some source code:
Main function:
https://github.com/marci1175/Matthias/blob/main/src/main.rs
The functions which call the invalid button (image_message_instance, file_message_instance, audio_message_instance, markdown_text_display):
https://github.com/marci1175/Matthias/blob/main/src/app/ui/client_ui/message_instances/message_main.rs#L94
What else could I provide?
A minimal reproduce. A free-standing example similar to https://github.com/emilk/egui/blob/master/examples/hello_world_simple/src/main.rs that clearly shows the problen
What else could I provide?
A minimal reproduce. A free-standing example similar to https://github.com/emilk/egui/blob/master/examples/hello_world_simple/src/main.rs that clearly shows the problen
I tried to reproduce it with simpler code, but I couldn't.
Anyway, I am happy that you found this issue.
Sorry, misclick 😅
You probably have some overlapping responses or responses with the same Id, and that stopped working after the interaction got refactored. You'll have to try to paint those responses with paint_debug_info to see where they overlap. Sort of like this:
egui::CentralPanel::default().show(ctx, |ui| {
let response = ui.allocate_response([200.0; 2].into(), Sense::click());
if response.clicked() {
println!("clicked before button");
}
response.paint_debug_info();
let response = ui
.allocate_ui_at_rect(response.rect, |ui| {
ui.allocate_space([100.0; 2].into());
let res = ui.button("Increment");
if res.clicked() {
println!("clicked button");
}
res.paint_debug_info();
})
.response;
let response = ui.allocate_rect(response.rect, Sense::click());
if response.clicked() {
println!("clicked after button");
}
});
Ive found that text inside this area where button and any kind of response is ignored, text can be selected, but not with clicks I can select text with me dragging my cursor over the letters but not if i triple click it
Is it possible that context menu's reponse are allocated / created before theyre actually shown? Cuz as I have mentioned all of the problems go away if i remove the context menu
I've also encountered this issue and managed to create a minimal reproduction (reproduced on two different systems with Windows 10):
- Create a new cargo project
cargo init --bin. - Replace the context of
Cargo.tomlwith the following:
[package]
name = "rust-egui-context-menu"
version = "0.1.0"
edition = "2021"
[dependencies]
egui = "0.28.1"
eframe = { version = "0.28.1", default-features = false, features = [
"default_fonts", # Embed the default egui fonts.
"glow", # Use the glow rendering backend. Alternative: "wgpu".
] }
- Replace the context of
src/main.rswith:
use eframe::egui;
fn main() {
let native_options = eframe::NativeOptions::default();
eframe::run_native(
"My egui App",
native_options,
Box::new(|cc| Ok(Box::new(MyEguiApp::new(cc)))),
);
}
#[derive(Default)]
struct MyEguiApp {
nr_clicks: usize,
}
impl MyEguiApp {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
Self::default()
}
}
fn add_context_menu(response: egui::Response) {
response.context_menu(|ui| {
ui.menu_button("Menu 1", |ui| {
if ui.button("Option 1.1").clicked() {
ui.close_menu();
}
if ui.button("Option 1.2").clicked() {
ui.close_menu();
}
});
});
}
impl eframe::App for MyEguiApp {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
let response = egui::CentralPanel::default()
.show(ctx, |ui| {
if ui.button("Click me").clicked() {
self.nr_clicks += 1;
}
ui.label(format!("Clicked {} times", self.nr_clicks));
})
.response;
// Uncomment the line below:
// add_context_menu(response);
}
}
4: Run the app with cargo run. Click the button and notice that the counter is updated as expected. Selecting the text of the label also works as expected.
5. Uncomment the line with add_context_menu(response);.
6: Run the app with cargo run. Selecting the text of the label still works as expected, but now the button won't react to hovering above it or clicking it.
I hope this will help you to find the issue.
I've also encountered this issue and managed to create a minimal reproduction (reproduced on two different systems with Windows 10):
- Create a new cargo project
cargo init --bin.- Replace the context of
Cargo.tomlwith the following:[package] name = "rust-egui-context-menu" version = "0.1.0" edition = "2021" [dependencies] egui = "0.28.1" eframe = { version = "0.28.1", default-features = false, features = [ "default_fonts", # Embed the default egui fonts. "glow", # Use the glow rendering backend. Alternative: "wgpu". ] }
- Replace the context of
src/main.rswith:use eframe::egui; fn main() { let native_options = eframe::NativeOptions::default(); eframe::run_native( "My egui App", native_options, Box::new(|cc| Ok(Box::new(MyEguiApp::new(cc)))), ); } #[derive(Default)] struct MyEguiApp { nr_clicks: usize, } impl MyEguiApp { fn new(cc: &eframe::CreationContext<'_>) -> Self { Self::default() } } fn add_context_menu(response: egui::Response) { response.context_menu(|ui| { ui.menu_button("Menu 1", |ui| { if ui.button("Option 1.1").clicked() { ui.close_menu(); } if ui.button("Option 1.2").clicked() { ui.close_menu(); } }); }); } impl eframe::App for MyEguiApp { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { let response = egui::CentralPanel::default() .show(ctx, |ui| { if ui.button("Click me").clicked() { self.nr_clicks += 1; } ui.label(format!("Clicked {} times", self.nr_clicks)); }) .response; // Uncomment the line below: // add_context_menu(response); } }4: Run the app with
cargo run. Click the button and notice that the counter is updated as expected. Selecting the text of the label also works as expected. 5. Uncomment the line withadd_context_menu(response);. 6: Run the app withcargo run. Selecting the text of the label still works as expected, but now the button won't react to hovering above it or clicking it.I hope this will help you to find the issue.
Thanks for replying to such an old issue, I have found a way to make it work. I could find a way to work around the issue, but its still a bug in egui. I think it had to do something with IDs and invalidated responses. If you are still running into this issue I recommend you to use ui.push_id in loops or iterations. I moved on from egui because I got tired of having to write bad code for the sake of it working with egui.