How to disable or delete cameratoolbar context menu

25 Ansichten (letzte 30 Tage)
Anton Semechko
Anton Semechko vor etwa 11 Stunden
Kommentiert: Adam Danz vor etwa 7 Stunden
Hello Matlab community!
Does anyone here know how to disable or delete the cameratoolbar context menu while maintaining the programmatic functionality of the cameratoolbar? I am asking because I am building a GUI that has is own custom context menu which gets broken when the cameratoolbar is enabled. This issue has been flaggegd five years ago in this post, but received no attention from MathWorks.
I am currently using Matlab R2024a.
Here is the screenshot of the context menu I am referring to:
Up to this point, I tried retrieving ContextMenu handles from the cameratoolbar, and the parent UIFigure, and deleting them but this did not work. Any helpful advice on this problem would be greatly appreciated.
Thanks!

Antworten (1)

Adam Danz
Adam Danz vor etwa 9 Stunden
Bearbeitet: Adam Danz vor etwa 9 Stunden
This stumped me for a bit but I've found a potential workaround. I'll also make a note of this issue for discussion.
Workaround: When creating the custom context menu, assign its Tag property as CameratoolbarContextMenu.
h.ContextMenu = uicontextmenu(fig,'Tag','CameratoolbarContextMenu');
This will trick cameratoolbar into thinking that it already created its context menu.
Another possibility I found is calling cameratoolbar("SetMode","nomode") after creating the axes toolbar. This removes the cameratoolbar context menu. Then you can reassign the original context menu which is in the figure's children. However, this command will also disable some camera motion controls.
  2 Kommentare
Anton Semechko
Anton Semechko vor etwa 8 Stunden
Hi Adam,
Your second suggesting does not work for me because I need to use the 'orbit' SetMode. The reason I need to use it in the first place is because the default rotate3D interaction does not provide intuitive control over the camera pose (please add this point to your internal discussion as well).
The first suggestion only works when there is only one custom context menu for the entire UIFigure. It will not work when:
  1. The custom context menu is assigned to a particular element of the figure (e.g., panel). Right clicking outside the element will erroneously show the context menu when using the cameratoolbar functionality, which is not expected behaviour.
  2. There is more than one custom context menu assigned to different figure elements, which is the case I am dealing with. Right clicking on the element with the custom-assigned context menu, while using the cameratoolbar functionality, will break that element's custom menu.
Adam Danz
Adam Danz vor etwa 7 Stunden
Now you know why I called it a potential workaround.
I'm storing my playground code here in case I ever decide to pick this back up. When cameratoolbar is called, the context menu in the first axes is replaced with the cx menu from the second axes which makes sense given how cameratoolbar cleanup works.
fig = uifigure;
tcl = tiledlayout(fig,1,2);
ax1 = nexttile(tcl);
s1 = surf(ax1,peaks);
s1.ContextMenu = uicontextmenu(fig,'tag','CameratoolbarContextMenu');
uimenu(s1.ContextMenu ,'Text','ChangeColor1','MenuSelectedFcn',@(~,~)colormap(ax1,rand(5,3)));
ax2 = nexttile(tcl);
s2 = surf(ax2,peaks);
s2.ContextMenu = uicontextmenu(fig,'tag','CameratoolbarContextMenu');
uimenu(s2.ContextMenu ,'Text','ChangeColor2','MenuSelectedFcn',@(~,~)colormap(ax2,rand(5,3)));
% cameratoolbar

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by