diff options
author | chickenleaf <lashwinib@gmail.com> | 2025-03-10 20:02:39 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-10 14:32:39 +0000 |
commit | 52119c339c281aa5793c1a29096b2ae582c425a9 (patch) | |
tree | 9e64c452e0ddc2cc64ef05ecebac6770b0c19cc3 | |
parent | c6527c4118a94a69866dff7039d2eab858628bc8 (diff) | |
download | servo-52119c339c281aa5793c1a29096b2ae582c425a9.tar.gz servo-52119c339c281aa5793c1a29096b2ae582c425a9.zip |
servoshell: Allow keyboard interaction with dialogs (enter / escape) (#35673)
Signed-off-by: L Ashwin B <lashwinib@gmail.com>
-rw-r--r-- | ports/servoshell/desktop/dialog.rs | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/ports/servoshell/desktop/dialog.rs b/ports/servoshell/desktop/dialog.rs index b1cd00deff4..906e0a4a267 100644 --- a/ports/servoshell/desktop/dialog.rs +++ b/ports/servoshell/desktop/dialog.rs @@ -153,7 +153,9 @@ impl Dialog { ui, |_ui| {}, |ui| { - if ui.button("Close").clicked() { + if ui.button("Close").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Escape)) + { is_open = false; if let Err(e) = response_sender.send(AlertResponse::Ok) { warn!("Failed to send alert dialog response: {}", e); @@ -176,13 +178,17 @@ impl Dialog { ui, |_ui| {}, |ui| { - if ui.button("Ok").clicked() { + if ui.button("Ok").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Enter)) + { is_open = false; if let Err(e) = response_sender.send(ConfirmResponse::Ok) { warn!("Failed to send alert dialog response: {}", e); } } - if ui.button("Cancel").clicked() { + if ui.button("Cancel").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Escape)) + { is_open = false; if let Err(e) = response_sender.send(ConfirmResponse::Cancel) { warn!("Failed to send alert dialog response: {}", e); @@ -206,7 +212,9 @@ impl Dialog { ui, |_ui| {}, |ui| { - if ui.button("Ok").clicked() { + if ui.button("Ok").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Enter)) + { is_open = false; if let Err(e) = response_sender.send(PromptResponse::Ok(input.clone())) @@ -214,7 +222,9 @@ impl Dialog { warn!("Failed to send input dialog response: {}", e); } } - if ui.button("Cancel").clicked() { + if ui.button("Cancel").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Escape)) + { is_open = false; if let Err(e) = response_sender.send(PromptResponse::Cancel) { warn!("Failed to send input dialog response: {}", e); @@ -263,13 +273,17 @@ impl Dialog { ui, |_ui| {}, |ui| { - if ui.button("Sign in").clicked() { + if ui.button("Sign in").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Enter)) + { let request = request.take().expect("non-None until dialog is closed"); request.authenticate(username.clone(), password.clone()); is_open = false; } - if ui.button("Cancel").clicked() { + if ui.button("Cancel").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Escape)) + { is_open = false; } }, @@ -286,13 +300,17 @@ impl Dialog { ui, |_ui| {}, |ui| { - if ui.button("Allow").clicked() { + if ui.button("Allow").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Enter)) + { let request = request.take().expect("non-None until dialog is closed"); request.allow(); is_open = false; } - if ui.button("Deny").clicked() { + if ui.button("Deny").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Escape)) + { let request = request.take().expect("non-None until dialog is closed"); request.deny(); @@ -332,7 +350,9 @@ impl Dialog { ui, |_ui| {}, |ui| { - if ui.button("Ok").clicked() { + if ui.button("Ok").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Enter)) + { if let Err(e) = response_sender .send(Some(devices[*selected_device_index].clone())) { @@ -340,7 +360,9 @@ impl Dialog { } is_open = false; } - if ui.button("Cancel").clicked() { + if ui.button("Cancel").clicked() || + ui.input(|i| i.key_pressed(egui::Key::Escape)) + { if let Err(e) = response_sender.send(None) { warn!("Failed to send cancellation: {}", e); } |