Crates.io | egui-bind |
lib.rs | egui-bind |
version | |
source | src |
created_at | 2022-10-27 20:37:41.650948+00 |
updated_at | 2025-02-07 13:19:02.7484+00 |
description | Library for showing keybinds |
homepage | |
repository | https://github.com/ItsEthra/egui-bind |
max_upload_size | |
id | 699749 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Library for showing key and pointer binds
[dependencies]
egui-bind = "0.14"
# Or if you wish for your binds to be serializable
# [dependencies]
# egui-bind = { version = "0.14", features = ["serde"] }
// Foreword: You can find this example in `examples/bind.rs`
#[derive(Default)]
struct ExampleApp {
// This can also be serialized with `serde`. You just
// need to enable `serde` feature.
bind: Option<(KeyOrPointer, Modifiers)>,
count: usize,
}
impl App for ExampleApp {
fn update(&mut self, ctx: &Context, _: &mut Frame) {
Window::new("Example")
.show(ctx, |ui| {
// Order matters, If you were to put this if case
// after the bind was shown, then it would trigger `self.cout += 1`
// on the same frame user assigned a new bind, which may not be the
// desired behavior. But you can mitigate this by using the return
// value of a `Bind::show` as shown below with `println!`.
if self.bind.pressed(ui.input()) {
self.count += 1;
}
// `Bind::new` accepts a reference to a type that implements `BindTarget`
// Most common of those are:
// `Key`, `PointerButton`, `KeyOrPointer`, `(BindTarget, Modifiers)`
// `Option<BindTarget>`
let assigned = Bind::new("_test", &mut self.bind).show(ui);
// Here it checks if the bind was pressed but not assigned on the same frame.
if !assigned && self.bind.pressed(ui.input()) {
println!("I was pressed");
}
ui.label(format!("Counter: {}", self.count));
});
}
}