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.
This commit is contained in:
William Casarin
2024-05-17 19:27:57 -05:00
parent 3a891a982c
commit cf2a832a5e

View File

@@ -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);
}
_ => {}
},
_ => {}
}
}
});