Improve example
This commit is contained in:
parent
2b2834ff9d
commit
a646c1259d
2 changed files with 21 additions and 21 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -2070,6 +2070,14 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "keyboard_events"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "khronos-egl"
|
||||
version = "4.1.0"
|
||||
|
|
|
@ -14,43 +14,35 @@ fn main() {
|
|||
);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Content {
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl Default for Content {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
text: "".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
let text_style = TextStyle::Body;
|
||||
let row_height = ui.text_style_height(&text_style);
|
||||
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_rows(ui, row_height, self.text.len(), |ui, _row_range| {
|
||||
//for row in row_range {
|
||||
for line in self.text.lines() {
|
||||
ui.label(line);
|
||||
}
|
||||
.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");
|
||||
}
|
||||
if ctx.input().key_pressed(Key::A) {
|
||||
self.text.push_str("\npressed");
|
||||
}
|
||||
if ctx.input().key_down(Key::A) {
|
||||
self.text.push_str("\nheld");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue