Use as follows:
hcmenu1 = uicontextmenu;
Try test_showcontextmenu.m for usage example.
This also contains a number of trivial routine functions:
%returns hObject's parent figure
getPositionOnFigure( hObject,units )
%returns absolute position of object on a figure
getRelPosition( hObject,units )
%get(hObject,'Position') with specific 'units'
getCurrentPoint( hFigure,units )
%get(hFigure,'currentpoint') with specific 'units'
Igor (2020). showcontextmenu (https://www.mathworks.com/matlabcentral/fileexchange/31448-showcontextmenu), MATLAB Central File Exchange. Retrieved .
Concerning FINDALL, are you talking about
test_showcontextmenu3.m line 9?
You're right, and the thing is
get(tbh,'HandleVisibility') == 'off'
that's why we have to use FINDALL...
I haven't tried this yet, Igor, though it looks interesting. I'm intrigued by your use of normalized units, and of the steps you had to take to make this all work in them. (I'm a fan of normalized units, too, and have done similar things.)
Also, I wanted to point out that FINDALL (as opposed to FINDOBJ) returns all children of a specified object, including those whose handles are hidden.
Thanks for your comment,Matt.
I've updated the submission so that it can now handle line as object.
(However I'm still not sure this would work for all such objects (without 'units') since 'current point' seems unreliable in case of button at least.)
This function will error on versions of MATLAB which do not have ASSERT. For example 2006a.
Also, if the handle of the object does not have a 'units' property, the function errors. A line, for example, may have a uicontextmenu, but does not have a 'units' property.
Thanks to Jesse this now supports uipushtool and uitoggletool objects (toolbar items).
+support for lines etc. (objects without 'units' property (menu would be displayed on click position)