mvlabat / bevy_egui

This crate provides an Egui integration for the Bevy game engine. 🇺🇦 Please support the Ukrainian army: https://savelife.in.ua/en/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image clicked() doesn't fire

spacekookie opened this issue · comments

I have this code:

let img = ui.image(SizedTexture::new(item.unwrap(), size));

if img.clicked() {
    info!("Image was clicked!");
}

if let Some(pos) = img.interact_pointer_pos() {
    info!("Interaction pos {pos:?}");
}

(the interact_pointer_pos() section is only there for testing). Neither of these two if blocks trigger when clicking on the added image. Funnily enough though .hovered() works!

Any idea what I'm doing wrong? I'm on the latest bevy_egui version (0.26?) and latest bevy (0.13)

Hi! You can try constructing an Image widget manually, after that you can change its sense property to allow it to react to clicks.

Ooh interesting! The Image needs to have the drag sense enabled. This works:

let img = ui.add(
    egui::Image::new(SizedTexture::new(item_images[0].unwrap(), size))
        .rounding(5.0)
        .sense(Sense::click_and_drag()),
);

Is this documented and I just missed it? 😅 Or is this a bug?

If it starts reacting to clicks only with the Sense::click_and_drag() sense (not just click), then it might be a bug, I'm not sure. 🤔 If you believe it's a bug, you can file an issue in the Egui repo, I don't think bevy_egui is doing something that's causing it.

I'll close this issue since there's unlikely to be a problem with bevy_egui