Popup Menus
Bob Sneidar
bobsneidar at iotecdigital.com
Wed Nov 3 18:58:04 EDT 2021
NVM I solved it. The code may be useful to others. The function popupRect() will return the popup area, not including the button rect, of a button whose longid you pass to it:
on menuPick
put the mouseLoc into tMouseLoc
put popupRect(the long id of me) into tPopupRect
if tMouseLoc is not within tPopupRect then \
return false
end menuPick
function popupRect pButtonID
put the rect of pButtonID into tMyRect
put min(the menuLines of pButtonID,the number of lines of the text of pButtonID) into tVisibleLines
put the effective textHeight of pButtonID into tLineHeight
put tLineHeight * tVisibleLines into tEffectiveOptionsHeight
add tEffectiveOptionsHeight to item 4 of tMyRect
subtract 18 from item 3 of tMyRect
add the effective height of pButtonID to item 2 of tMyRect
return tMyRect
end popupRect
Bob S
(ps. This should go into the MasterLibrary)
> On Nov 3, 2021, at 13:42 , Bob Sneidar via use-livecode <use-livecode at lists.runrev.com> wrote:
>
> Hi all. This is a little difficult to explain.
>
> I have a popup menu. The first item in the text of the menu is "New Customer..." so that if I popup the menu then let go somewhere OUTSIDE the rect or the popped up items, menuPick is STILL triggered and the first item in the text of the popup button is the parameter passed to it.
>
> This means that even if a user clicks off a popped menu, the handler is still triggered. I think this is a bug, and popup menus ought not work that way, but neither here nor there.
>
> A workaround would be to detect if the mouseLoc was within the rect of the menu options that pop up when the menu is clicked, but alas the rect of the popup menu is only the size of the button, and does NOT include the options that appear when the button is clicked.
>
> Is there any way to get that rect? I suppose I could calculate it based on the max(<lines of the text>, <max visible lines>) given the line height and width of the button, but that is a bit of a kludge.
>
> Bob S
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list