Jump to content

Click events on containers


photo

Recommended Posts

I'm often finding myself in the situation where I have a bunch of labels and sprites within a container (usually a groupbox) and I want the whole lot to act as a single item in a list of some sort (e.g. many of these groupboxes stacked within in a vbox). I can detect clicks on the components within the groupbox but there are no clicked or double_clicked callbacks on the groupbox itself. So, for instance, I can click on either of two labels to select the entire group, but if I click on the empty space between the labels it isn't detected.

 

How could I implement clicks and double-clicks on containers like this efficiently? I could constantly poll in the update to check if the pointer is within the bounds of the widget and then check the state of the mouse button, but that seems like a lotta work, particularly to detect double clicks. Preferably I'd like to do this entirely via script, without modifying the engine.

 

Just had another thought... I guess I could add a background sprite in the groupbox and then detect clicks on that. Still seems very wasteful though. Surely there's a better way?

Link to comment

Just tried this with the clicked callback on an empty groupbox and the clicks still seem to be ignored. Also note that groupbox is not listed as a supported widget in the documentation for the clicked or double_clicked callbacks. I see why you say it should happen though since the WidgetGroupBox class does have a checkCallbacks method. Could you maybe trace this and see if there's some other reason why it's not being triggered? I'm not set up to compile/debug the source currently.

 

On a side note I've also realized that just catching clicks on the groupbox might not be enough because they will likely have other vboxes, hboxes etc inside them. Will the clicks pass through to the widget underneath in those cases? If not then would it be possible to implement the callbacks on all the container type widgets? The WidgetVBox for example has a checkCallbacks method, but that never goes on to call check_default_callbacks so it seems likely it would block them.

Link to comment
×
×
  • Create New...