2022-11-30 19:40:11 +00:00
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
|
|
|
|
|
|
use eframe::egui;
|
|
|
|
use egui::*;
|
2022-12-12 14:16:32 +00:00
|
|
|
fn main() -> Result<(), eframe::EframeError> {
|
2022-11-30 19:40:11 +00:00
|
|
|
// Log to stdout (if you run with `RUST_LOG=debug`).
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
|
|
let options = eframe::NativeOptions::default();
|
|
|
|
eframe::run_native(
|
|
|
|
"Keyboard events",
|
|
|
|
options,
|
|
|
|
Box::new(|_cc| Box::new(Content::default())),
|
2022-12-12 14:16:32 +00:00
|
|
|
)
|
2022-11-30 19:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct Content {
|
|
|
|
text: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl eframe::App for Content {
|
|
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
|
|
ui.heading("Press/Hold/Release example. Press A to test.");
|
|
|
|
if ui.button("Clear").clicked() {
|
|
|
|
self.text.clear();
|
|
|
|
}
|
|
|
|
ScrollArea::vertical()
|
|
|
|
.auto_shrink([false; 2])
|
|
|
|
.stick_to_bottom(true)
|
|
|
|
.show(ui, |ui| {
|
|
|
|
ui.label(&self.text);
|
|
|
|
});
|
|
|
|
|
|
|
|
if ctx.input().key_pressed(Key::A) {
|
|
|
|
self.text.push_str("\nPressed");
|
|
|
|
}
|
|
|
|
if ctx.input().key_down(Key::A) {
|
|
|
|
self.text.push_str("\nHeld");
|
|
|
|
ui.ctx().request_repaint(); // make sure we note the holding.
|
|
|
|
}
|
|
|
|
if ctx.input().key_released(Key::A) {
|
|
|
|
self.text.push_str("\nReleased");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|