-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix key press event * Add example with key presses * Changelog line for key_press fix * PR review improvements * Add PR link in changelog Co-authored-by: Emil Ernerfeldt <[email protected]>
- Loading branch information
Showing
6 changed files
with
97 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "keyboard_events" | ||
version = "0.1.0" | ||
authors = ["Jose Palazon <[email protected]>"] | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
rust-version = "1.65" | ||
publish = false | ||
|
||
|
||
[dependencies] | ||
eframe = { path = "../../crates/eframe" } | ||
tracing-subscriber = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```sh | ||
cargo run -p hello_world | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release | ||
|
||
use eframe::egui; | ||
use egui::*; | ||
fn main() { | ||
// 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())), | ||
); | ||
} | ||
|
||
#[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"); | ||
} | ||
}); | ||
} | ||
} |