flamendless / Slab

An immediate mode GUI for the Love2D framework.
MIT License
286 stars 25 forks source link

Check if an event was consumed by Slab? #172

Closed Voycawojka closed 4 months ago

Voycawojka commented 4 months ago

Is there a way to check if an event (for example a mouse press) was consumed/handled by Slab? Let's say that players can select units by clicking on them with a mouse. What if a Slab window is occluding the unit? If I handle the selection like this:

function love.mousepressed(x, y)
   selectUnit(x, y)
end

...then the unit will be selected even though the player pressed on the UI window, not on the unit.

From what I understand by looking at the source code it's impossible to handle this case properly. But maybe I'm missing something?

I have found that I can use IsVoidHovered and IsVoidClicked functions but there still are two problems:

Is there another way?

flamendless commented 4 months ago

Hi, due to the nature of immediate mode GUIs (ImGUI) such as Slab, it will be difficult to rely on callbacks/events like mousepressed. What you can do, and what I did in my projects before, is you handle the IsVoidClicked and IsVoidHovered in your update, store the results in a variable, and use that in your callbacks. For the keyboard, you can do the same but use this event to check if a slab input is focused or not

Voycawojka commented 4 months ago

Thanks, this is what I ended up doing. And the focus checking function is helpful. I must have missed it