edit zoom contex menu

Hello all,
Is there any way to edit the zoom built-in conext menu? I want to add an option to exit zoom mode.
I dont want to create a custom context menu. I want just to edit the original one.
I did it this way:
z = zoom(h.FIG);
z.Enable = 'on';
zoomMenu = findobj(h.FIG, 'Tag', 'ZoomContextMenu');
MENU_exitZoom = uimenu(zoomMenu, 'Text', 'Exit zoom mode', 'Callback', @C_exitZoomMode);
The problem is that the context menu handle is empty if I dont open the menu first with the mouse.
After that, the handle is there, and I can sucessufly add my new option, and it indeed exits zoom mode.
Mathworks states that you cannot add items to the built-in zoom context menu, but you can replace it with your own. But since I did it sucessfully, I suppose this is not entirely true. The only problem is that the menu handle doesn't appear if I dont make the menu show up at least once.
Anyway, I want to create a menu that has all the options of the built-in menu, but with one extra option created by me. Any way for doing this?
Regards,
André

4 Commenti

Adam
Adam il 4 Nov 2019
Extending or truncating Mathworks' default graphics/GUI objects does always seem to be extremely difficult. I have had similar problems trying to programmatically add a toolbar that is just a subset of the default one for a figure.
Looking in my own code I ended up writing a full custom context menu for zooming and panning functionality when I wanted to do something like you are, reprogramming callbacks to do essentially the same as the defaults in many cases too, but it was a lot of effort and seems to span 3 classes. Certainly I didn't find a way to edit the existing menu in a way I wanted.
André
André il 4 Nov 2019
The only alternative I have seen is to create a callback when you click the axes to change the menu. It should work since it the menu is already open. But then whats the surprise: you can not capture mouse events while in zoom mode.
Seems the only way is to program each zoom option individually as you said. Its really a pity having to do things that are already done.
Well, seems I had to program each option individually. It was really annoying, maybe Mathworks could provide a way to use the built-in context menus as ordinary menus valid for editing:
%%
function C_zoomOut(hObject, eventdata)
zoom(AXES, 0.5)
end
%%
function C_resetView(hObject, eventdata)
zoom(AXES, 'out');
end
%%
function C_unConstrainedZoom(hObject, eventdata)
set(hObject.Parent.Children, 'Checked', 'off');
hObject.Checked = 'on';
z = zoom(AXES);
z.Motion = 'both';
end
%%
function C_horizontalZoom(hObject, eventdata)
set(hObject.Parent.Children, 'Checked', 'off');
hObject.Checked = 'on';
z = zoom(AXES);
z.Motion = 'horizontal';
end
%%
function C_verticalZoom(hObject, eventdata)
set(hObject.Parent.Children, 'Checked', 'off');
hObject.Checked = 'on';
z = zoom(AXES);
z.Motion = 'vertical';
end
%%
function C_exitZoomMode(hObject, eventdata)
zoom(AXES, 'off');
end
I had a similar problem in the app designer and noticed that adding these lines did the trick for me:
app.UIAxesZoom=zoom(app.UIAxes);
setAllowAxesZoom(app.UIAxesZoom,app.UIAxes,1);

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Environment and Settings in Centro assistenza e File Exchange

Richiesto:

il 4 Nov 2019

Commentato:

Luc
il 15 Mar 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by