How to capture both left and right mouse click on ClickableWidget?

Started by doomista, 02 September 2019, 18:24:42

doomista

I have a tgui::Canvas object, to which I connected events using "MousePressed":

auto canvas = tgui::Canvas::create();
canvas->connect("MousePressed", [this]() { /*...*/ });


But it seems the event is only triggered on left mouse click, not on right mouse click.

Is there any way to trigger on both?

texus

The name MousePressed has been in use before right clicks were supported at all, which is why the name doesn't make it clear that it only refers to left mouse clicks.
Support for right mouse clicks is currently extremely limited. Widgets know when the right mouse is pressed with the internal rightMousePressed and rightMouseReleased functions, but ListView is currently the only widget with a RightClicked callback.

What are you trying to do exactly? Would you need a callback on the actual click, or already when the right mouse button goes down?

doomista

I need the callback when mouse goes down and then also when mouse goes up.

I can simulate it from outside code, I just wanted to know whether there is easy way to do it or maybe error on my side.

texus

There currently is no easy way.
I could perhaps add RightMousePressed, RightMouseReleased and RightClicked callbacks to ClickableWidget though.

doomista

It would be certainly convenient for me, but question is whether there is some greater need for this feature.

texus

The ability to right click came up once or twice in the past, so I guess it wouldn't hurt to add callbacks to ClickableWidget and Panel. I'll do that soon.

texus

RightMousePressed, RightMouseReleased and RightClicked signals have been added to ClickableWidget and Panel widgets.