-
I've been using egui without any issues for a while on my project. However, after upgrading from eframe 0.23 to 0.28.1, I noticed that the In my previous version (based on eframe 0.23), after I've edited the extension list text field, I could press the "Save" button and everything would save as expected. But in the latest version, when I click on "Save", the extension list loses focus and resets its content. For some context, the code related to this hasn't changed between these releases: were there some changes in egui itself that I'm not aware of or is this a bug? ui.horizontal(|ui| {
ui.label("Extension List")
.on_hover_text("Extension list to filter input files");
let extension_response: egui::Response = ui.add(
egui::TextEdit::singleline(&mut gui_app.text_edit_extensions)
.hint_text("Add at least one file extension!")
.char_limit(crate::constants::CHAR_LIMIT)
.text_color(constants::EXTENSION_COLOR),
);
if ui
.add(egui::Button::new("Save").min_size(crate::constants::BUTTON_SIZE_SMALL))
.clicked()
{
gui_app.extension_list = gui_app.text_edit_extensions.clone();
}
if ui
.add(egui::Button::new("Reset").min_size(crate::constants::BUTTON_SIZE_SMALL))
.clicked()
{
gui_app.text_edit_extensions = crate::constants::DEFAULT_EXTENSIONS.join(", ");
gui_app.extension_list = crate::constants::DEFAULT_EXTENSIONS.join(", ");
}
// if we changed something but did not save -> revert everything
if extension_response.lost_focus() {
gui_app.text_edit_extensions = gui_app.extension_list.clone();
}
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There have been some changes to how the focus works, to try and fix bugs related to things like tab order, and many changes to how responses work in general as well. I guess one consequence is that now the impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
let mut save = false;
let response = ui.text_edit_singleline(&mut self.name);
// This won't work
if ui.button("Save").clicked() {
save = true;
println!("Clicked at {}", ui.input(|i| i.time));
}
// This will work
if ui.button("Save").hovered() && ui.input(|i| i.pointer.primary_pressed()) {
save = true;
println!("Pressed at {}", ui.input(|i| i.time));
}
if response.lost_focus() {
println!("Lost focus at {}", ui.input(|i| i.time));
if !save {
self.name.clear();
}
}
});
}
} But if you want the button to act on release as usual, you might have to make a little state machine to keep track of the sequence of events and decide whether to reset the field. |
Beta Was this translation helpful? Give feedback.
There have been some changes to how the focus works, to try and fix bugs related to things like tab order, and many changes to how responses work in general as well. I guess one consequence is that now the
TextEdit
loses focus on button press, whereas the click event is on button release, which comes in a later frame. One quick and dirty fix would be to make the button act on press rather than release, so it will happen on the same frame as the lost focus. Here is an example: