Catching input
Closed this issue · 8 comments
SUIT does not "catch" mouse input (in the sense that say a click on a button will still result in a mouseclicked event for the rest of the program) and I can't see any feature to turn it on. Is there at least a way to know if a certain mouseclick was registered by SUIT? If the player presses a button, I don't want my game to react to that.
Intercepting mouse clicks is not in the spirit of SUIT (there are no "events", only state). Mouse clicks are handled by the widgets themselves and they signal a mouse hit in their return state. I can see that this is a bit inconvenient.
What would be a good interface to query if a mouse click was caught by a widget?
I'm currently using the AnyHovered function with pretty good results, but I imagine there are edge cases where it would cause wrong behavior. What I'd like is something similar that could be queried on whether the last mouse press event caused any widgets to return true on their hit, as I could then ignore that event on my game input. Would that be doable?
anyActive()
(mouse pressed on any widget) is straightforward to implement, and anyHit()
(mouse pressed and released on any widget) should also be possible. Will that solve the edge cases?
I think that should cover it, yes. The edge cases I had in mind were if the user pressed on a button and quickly moved off it, or maybe pressed outside of it and moved on before I had time to call AnyHovered()
. I don't know enough about how you handle mouse events to see if that is actually realistic or possible, but AnyHovered()
feels dirty to use when you're actually asking about the last click.
Especially anyHit()
is what I would use.
Also, is there a function like suit.has_keyboard_focus()
?
There is no function in the document I can use to tell whether an Input has focus.
I found suit.keyboardFocus
, but it is always nil
.
@buckle2000 There is suit.hasKeyboardFocus(id). Note that you can only only access keyboardFocus
from suit instances, but not from the default instance.
For the default instance, you can get the id that currently has keyboard focus with suit._instance.keyboardFocus
.