How to Detect when Mouse Leaves PluginGui

I’m creating a GUI to allow configuring some properties, and I wanted to add a tooltip for the properties. My plan was to make the tooltip visible when the mouse enters the GUI and disappear when it leaves.

However, MouseLeave doesn’t fire if the mouse leaves the entire PluginGui, as such:

2018-09-09_20-28-23

Does anyone have any ideas on how I might work around this? I know it’s an old problem (also happens in the main viewport), but it’s much more annoying in a PluginGui because I may leave the PluginGui for a longer period of time. Also, in the main viewport, I usually don’t have my guis run right up to the edges.

One attempt I made...

I tried using GetRelativeMousePosition in a loop to detect if the mouse moves outside of the PluginGui, but the return value for that function gets locked at whatever the last position your mouse had while it was still in the PluginGui.

1 Like

Seems like this is what you’re looking for, but I don’t think it’s functional quite yet.
https://www.robloxdev.com/api-reference/function/PluginGui/GetRelativeMousePosition
image

I took a shot at using that API (I hid away my strategy in the OP so I wouldn’t wordwall). A few things:

  1. How do you see that text?
I see very little on that page.

  1. “or it is a drag and leaves gui” doesn’t bode well for me, because my scenario doesn’t require mouse drag. Just a mouse movement. It does appear to do what the description says, though – just tested it while depressing mouse1 and all went fine.

Anything… hackier you can give me? :stuck_out_tongue:

1 Like

Ack, I always miss the details panes, that’ll be the death of me.

Since the issue with the API has a specific symptom (always returning the same position) you may be able to use that to your advantage. Every time you call GetRelativeMousePosition(), compare that to the previous condition. If it’s the same for more than a couple seconds, that means the mouse has left the frame… or it just means the mouse is idle. I suppose you could write some more hacky code to discern between the two, but it probably wouldn’t be a big deal if the tooltips faded in both cases.

So, if GetRelativeMousePosition() returns the same thing for 3-ish seconds, make the tooltip disappear. Hacky enough for ya? :stuck_out_tongue:

Yeah, I think that’s probably fair. The one point of confusion is that hovering your mouse is how you’re supposed to make tooltips appear, not disappear. But hey, do what you gotta do. I’ll settle on making them automatically go away after a few seconds

I don’t really know how one would discern between normal hover vs. mouse left the PluginGui, truth be told.


I’m still receptive to more ideas, though, if anyone has experienced this issue before and came up with a decent solution.

I’d try giving the titles invisible triggers that don’t hug the widget’s edges.

e.g:

Where the green area on each title is an invisible frame which is used to trigger the tooltip.

Also, since I thought about it: If you ever just want to know if the cursor is on the widget, I think it’d be mostly accurate to just check if the cursor is idle within N pixels of the widget’s edges using GetRelativeMousePosition. And as a backup, if the widget loses focus I think it’s very safe to say the cursor isn’t on it.