12个重大版本发布

0.13.0 2024年7月16日
0.12.0 2024年3月27日
0.11.0 2024年2月6日
0.9.0 2023年12月1日
0.4.0 2022年10月31日

#405编码

Download history 18/week @ 2024-04-16 138/week @ 2024-04-23 199/week @ 2024-04-30 10/week @ 2024-05-07 15/week @ 2024-05-21 4/week @ 2024-05-28 1/week @ 2024-06-11 33/week @ 2024-07-02 141/week @ 2024-07-16 113/week @ 2024-07-23 63/week @ 2024-07-30

317 每月下载量

MIT 许可证

47KB
465

egui-bind

显示按键和指针绑定的库

安装

[dependencies]
egui-bind = "0.5"

# Or if you wish for your binds to be serializable
# [dependencies]
# egui-bind = { version = "0.5", 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));
            });
    }
}

依赖项

~4.5–10MB
~84K SLoC