raysan5 / raygui

A simple and easy-to-use immediate-mode gui library
zlib License
3.61k stars 303 forks source link

Check whatever any GUI element was just clicked #414

Closed VladPavliuk closed 4 months ago

VladPavliuk commented 4 months ago

I'm trying to create a small game editor.

One of the features I want to add is the ability to select any game object on the screen (by clicking) and show related to that entity UI staff. Additionally, if the user clicks on empty space (no game object nor UI element) on the screen, the selection box and entity related UI elements disappear.

The issue is that it's not easy to distinguish a click on UI element and a click on empty space. It's possible to create some kind of a list of all UI elements rectangles and validation does the current click intersects with any of them. Another solution might be to create a texture with 8-bit int pixel format and fill it with all UI elements rectangles on the screen and check is the position of the mouse already occupied by some UI element. But these solutions require addition coding, rather then using something already out of the box.

Is there a way in Raygui to check is any UI element just was clicked?

Also, I tired to look at guiControlExclusiveRec and guiControlExclusiveMode but it seems that they are for a bit different purpose and functions like GuiButton do not change their state.

raysan5 commented 4 months ago

@VladPavliuk I'm afraid it would imply a redesign of raygui and keep a internal list of rectangles, it goes agains the stateless nature of the library. I'm afraid the easiest approach is do that Rectangle management and tracking at user side, actually that's how I do it on my tools.

VladPavliuk commented 4 months ago

@raysan5 got it, thanks for the answer!