From cf2a832a5e740116b4dc3444409499441109cb2d Mon Sep 17 00:00:00 2001 From: William Casarin Date: Fri, 17 May 2024 19:27:57 -0500 Subject: [PATCH] input: switch to scanning over raw input events Calling key_pressed invokes a filter over the entire event list every time, this is much more efficient, which is important when we are handling many key events. --- src/app.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index 98202a3..301ffb3 100644 --- a/src/app.rs +++ b/src/app.rs @@ -107,10 +107,25 @@ fn send_initial_filters(damus: &mut Damus, relay_url: &str) { fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> { ctx.input(|i| { let amount = 0.2; - if i.key_pressed(egui::Key::Equals) { - ctx.set_pixels_per_point(ctx.pixels_per_point() + amount); - } else if i.key_pressed(egui::Key::Minus) { - ctx.set_pixels_per_point(ctx.pixels_per_point() - amount); + + for event in &i.raw.events { + match event { + egui::Event::Key { + key, pressed: true, .. + } => match key { + egui::Key::Equals => { + ctx.set_pixels_per_point(ctx.pixels_per_point() + amount); + } + + egui::Key::Minus => { + ctx.set_pixels_per_point(ctx.pixels_per_point() - amount); + } + + _ => {} + }, + + _ => {} + } } });