-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add keyboard handling example and update documentation (#294)
* Add keyboard handling example * Update documentation about handling keyboard input * Run cargo fmt to pass all CL * Fix to pass CL
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "keyboard_handler" | ||
edition = "2021" | ||
license.workspace = true | ||
version.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
floem = { path = "../.." } |
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,31 @@ | ||
use floem::{ | ||
event::{Event, EventListener}, | ||
keyboard::Key, | ||
unit::UnitExt, | ||
view::View, | ||
views::{stack, text, Decorators}, | ||
}; | ||
|
||
fn app_view() -> impl View { | ||
let view = | ||
stack((text("Example: Keyboard event handler").style(|s| s.padding(10.0)),)).style(|s| { | ||
s.size(100.pct(), 100.pct()) | ||
.flex_col() | ||
.items_center() | ||
.justify_center() | ||
}); | ||
view.keyboard_navigatable() | ||
.on_event_stop(EventListener::KeyDown, move |e| { | ||
if let Event::KeyDown(e) = e { | ||
if e.key.logical_key == Key::Character("q".into()) { | ||
println!("Goodbye :)"); | ||
std::process::exit(0) | ||
} | ||
println!("Key pressed in KeyCode: {:?}", e.key.physical_key); | ||
} | ||
}) | ||
} | ||
|
||
fn main() { | ||
floem::launch(app_view); | ||
} |
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