Replies: 1 comment
-
This isn't available as a method in the Click to open example
struct MyApp {
age: u32,
}
impl Default for MyApp {
fn default() -> Self {
Self { age: 42 }
}
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label(format!("N = {}", self.age));
let response = ui.image(egui::include_image!(
"../../../crates/egui/assets/ferris.png"
));
if response.hovered() {
let delta = ui.input(|i| {
i.events.iter().find_map(|e| match e {
egui::Event::MouseWheel {
unit: _,
delta,
modifiers,
} if modifiers.command_only() => Some(*delta),
_ => None,
})
});
if let Some(delta) = delta {
self.age = self
.age
.wrapping_add_signed(delta.max_elem().signum() as i32);
}
}
});
}
} Screencast.from.2024-05-23.19-19-36.mp4If you just want to use the zoom and scroll events as defined by egui (e.g., Ctrl to zoom, Shift to scroll horizontally), you can also do what the plot widget does: egui/crates/egui_plot/src/lib.rs Lines 1093 to 1130 in a98c42e |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Using code outside of Egui, I am rendering a "map" to a Texture, which I then display in Egui as an Image.
I can display the Image right now. I can also listen for drag events on the img via:
this is enough for panning left/right up/down
I also want to intercept MouseWheel events on the image (so I can call the underlying custom wgpu map rendering code to zoom in/out).
How do I listen to MouseWheel events on this egui Image ?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions