Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Widget does not sense clicks. #42

Closed
robertsonb opened this issue Nov 15, 2020 · 2 comments
Closed

Image Widget does not sense clicks. #42

robertsonb opened this issue Nov 15, 2020 · 2 comments

Comments

@robertsonb
Copy link

robertsonb commented Nov 15, 2020

Hello,

It appears that the Image widget does not have a "sense" hooked up and therefore doesn't listen for button clicks.

At least, that's how it appeared after quickly comparing Image to Button implementations.

I'm not sure if this is intentional and I should wrap the image in some other container that detects clicks... or if this is indeed a bug / missing functionality.

What I'm trying to do is implement a simple Tile picker/chooser, and so I was looking to just show the image, detect clicks on it, get the mouse cursor offset into the widget, do the math, and pick the tile. I didn't see any other obvious way of doing it with the current EGUI types, so I went this route.

Thanks!

@emilk
Copy link
Owner

emilk commented Nov 15, 2020

Hi!

When adding a widget (such as an Image) you get back an egui::Response which includes the Rect for its location. You can detect clicks on it using ui.interact as so:

let response = ui.image(...);
let id = ui.make_position_id(); 
let response = ui.interact(response.rect, id, Sense::click());
if response.clicked {
    ...
}

This should work well, but has the downside of the image looking the same regardless of the mouse hovering or clicking on it (while a regular button changes color when you interact with it). I am planning to one day add some sort of button container that adds a frame around e.g. an image so that you get that nice mouse-over effect, but I haven't gotten around to it yet.

@robertsonb
Copy link
Author

That did the trick, all good on my end.

Really enjoying the UI system your putting together, nice work :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants