Update gui to properly send keys to calculator

This commit is contained in:
Austen Adler 2023-04-14 02:16:52 -04:00
parent 78498fbfcd
commit d935cf6101

View File

@ -1,3 +1,4 @@
use egui::Key;
use rpn_rs::calc::Calculator; use rpn_rs::calc::Calculator;
/// We derive Deserialize/Serialize so we can persist app state on shutdown. /// We derive Deserialize/Serialize so we can persist app state on shutdown.
@ -115,11 +116,78 @@ impl eframe::App for TemplateApp {
// format!("Keys pressed: {:?}", i.key_pressed(egui::Key::I) ) // format!("Keys pressed: {:?}", i.key_pressed(egui::Key::I) )
// })); // }));
ui.label(ui.input(|i| { ui.input(|i| {
format!("Keys pressed: {:?}", i.keys_down ) if i.events.is_empty() {
})); return;
}
// ui.label(format!("Keys pressed: {:?}", InputState.keys_down)) for e in i.events.iter() {
match e {
egui::Event::Text(t) => {
self.calculator.take_input(t.chars().next().unwrap());
}
egui::Event::Key {
key: Key::ArrowLeft,
pressed: true,
..
} => {
self.calculator.take_input('<');
}
egui::Event::Key {
key: Key::ArrowRight,
pressed: true,
..
} => {
self.calculator.take_input('>');
}
egui::Event::Key {
key: Key::Enter,
pressed: true,
..
} => {
self.calculator.take_input(' ');
}
egui::Event::Copy => continue,
egui::Event::Cut => continue,
egui::Event::Paste(_) => continue,
egui::Event::Key {
key,
pressed,
repeat,
modifiers,
} => continue,
egui::Event::PointerMoved(_) => continue,
egui::Event::PointerButton {
pos,
button,
pressed,
modifiers,
} => continue,
egui::Event::PointerGone => continue,
egui::Event::Scroll(_) => continue,
egui::Event::Zoom(_) => continue,
egui::Event::CompositionStart => continue,
egui::Event::CompositionUpdate(_) => continue,
egui::Event::CompositionEnd(_) => continue,
egui::Event::Touch {
device_id,
id,
phase,
pos,
force,
} => continue,
egui::Event::AccessKitActionRequest(_) => continue,
}
}
eprintln!("Got events: {:#?}", i.events);
// format!("Keys pressed: {:?}", i.keys_down)
});
ui.label(format!("Calc details: {:#?}", self.calculator.stack));
ui.label(format!("Entry buffer: {}", self.calculator.get_l()));
egui::warn_if_debug_build(ui); egui::warn_if_debug_build(ui);
}); });