Hi all, these approaches don't really work as a 'proper' tooltip:
- show on both mouseEnter
and when the mouse stands still for a while: mouseEnter alone won't cover this. You can fix a delay but the tooltip should not appear if mouse is still moving
- hide if mouse moves,
even if still inside the object (ie mouseLeave doesn't come into it)
- show again if moved within the object
and then mouse stands still for a while, i.e. even if mouseEnter isn't fired again
- hide when mouse leaves object - with a simple mouseEnter/Leave approach, if you do a super-quick exit, the tooltip is 'stuck' showing.
I worked around these issues by implementing a method for checking mouseLoc and comparing with a stored mouseLoc at a designated interval - the 'delay' requested above.
For mouseLeave, I had to both check that the mouse was actually out of bounds of the object as it seems to fire continuously (bug?) AND clear this handler from the pendingMessages as it seems mouseLeave gets called a lot, even if mouse hasn't left!
The attached works perfectly. The main text field has the script in it, but easily could be a behaviour to attach to any field. The 'tooltip' has a script in it to format its width (up to a limit set in the script) and it's height in case of longer messages.
The message to show in the tooltip, the delay and a switch to show whether tooltips should be shown are all custom props of the field (uTooltip, uDelay and uShowTooltip respectively).
The main script is:
Code: Select all
local sLastMouseLoc
on mouseEnter
if the uShowtooltip of me then
put the mouseLoc into sLastMouseLoc
send "checkIfMouseMoved" to me in (the uDelay of me) milliseconds
end if
end mouseEnter
command checkIfMouseMoved
if the tool is "pointer tool" then exit checkIfMouseMoved
if the mouseLoc is not within the rect of me then exit checkIfMouseMoved
if the mouseLoc <> sLastMouseLoc then
hide field "tooltip"
put the mouseLoc into sLastMouseLoc
send "checkIfMouseMoved" to me in (the uDelay of me) milliseconds
else
dispatch "setMyText" to field "toolTip" with the uTooltip of me
end if
end checkIfMouseMoved
on mouseLeave
if the tool is "pointer tool" then exit mouseLeave
if the mouseLoc is not within the rect of me then
repeat for each line tLine in the pendingMessages
if "checkIfMouseMoved" is in item 1 of tLine then cancel item 1 of tLine
end repeat
hide field "tooltip"
end if
end mouseLeave
Hope this helps
S.