use eframe::{run_native, App, CreationContext, Frame, NativeOptions};
use egui::{Context, Modifiers, Window};
use egui_bind::{Bind, BindTarget, KeyOrPointer};
type Binding = Option<(KeyOrPointer, Modifiers)>;
#[derive(Default)]
struct ExampleApp {
bind: Binding,
count: usize,
check: bool,
}
impl App for ExampleApp {
fn update(&mut self, ctx: &Context, _: &mut Frame) {
Window::new("Example").show(ctx, |ui| {
if self.bind.pressed(ctx) {
self.count += 1;
self.check = !self.check;
}
let r = ui.checkbox(&mut self.check, "Check");
if egui_bind::show_bind_popup(ui, &mut self.bind, "check_popup", &r) {
println!("Rebinded from popup");
}
if ui.add(Bind::new("_test", &mut self.bind)).changed() {
println!("Rebinded!");
}
ui.label(format!("Counter: {}", self.count));
});
}
}
type DynError = Box<dyn std::error::Error + Send + Sync>;
#[allow(clippy::box_default)]
fn create(
CreationContext { egui_ctx: ctx, .. }: &CreationContext,
) -> Result<Box<dyn App>, DynError> {
ctx.set_pixels_per_point(1.5);
Ok(Box::new(ExampleApp::default()))
}
fn main() -> Result<(), eframe::Error> {
run_native("Example", NativeOptions::default(), Box::new(create))
}