what is the replacement for uisplittool?
3 ビュー (過去 30 日間)
古いコメントを表示
Hello there,
I maintain code for our lab group and someone posted a warning that uisplittool is undocumented and will be removed in future versions of MATLAB.
I was wondering what would be the equivalent command that should be used instead to maintain operability.
Raw error:
uisplittool is an un-documented built-in Matlab tool for handling graphics for toolbars in Matlab. The warning indicates it's deprecated.
3 件のコメント
採用された回答
Shivam
2024 年 3 月 19 日
Hi Christian,
From the provided details, I gather that you are looking for an alternative to uisplittool as it is an un-documented built-in MATLAB tool, which will be removed in future releases. You are using this tool to create a selectable dropdown on an image in the toolbar.
It is important to note that the uisplittool creates a separate button in the toolbar, which is essentially a button split into two sections. One section (image icon) performs an action immediately (primary action), and the other section displays a dropdown arrow that, when clicked, reveals a dropdown menu with additional options (secondary actions).
While there's no direct alternative to uisplittool in MATLAB, there's a promising workaround using uipushtool. This tool, although not designed for splitting into two parts, can simulate the behavior by inserting an image icon in the toolbar. It reveals a context menu (dropdown) below the toolbar when clicked.
You can refer to the provided workaround to get more clarity on the implementation:
% Create a figure and add a toolbar to it
fig = figure('Toolbar', 'none', 'MenuBar', 'none', 'Name', 'Custom Toolbar Dropdown', 'WindowButtonDownFcn', @(src, event)hideContextMenu(src));
tb = uitoolbar(fig);
% Load the icon (e.g. greenarrowicon)
icon = fullfile(matlabroot,'/toolbox/matlab/icons/greenarrowicon.gif');
[cdata,map] = imread(icon);
% Convert white pixels into a transparent background
map(map(:, 1) + map(:, 2) + map(:, 3) == 3) = NaN;
% Convert into 3D RGB-space
cdataRedo = ind2rgb(cdata,map);
% Create a push tool in the toolbar
pt = uipushtool(tb,'cdata',cdataRedo,'TooltipString','Dropdown Menu', 'Separator', 'on');
% Set the callback for the click on image-icon
pt.ClickedCallback = @(src, event)dropdownClicked(src, event, fig);
% Callback for click on image-icon
function dropdownClicked(~, ~, fig, flag)
% Define items for the dropdown
items = {'Movement Function', 'Transformation Function', 'Experiment Code'};
% Create a context menu (acts as dropdown)
cm = uicontextmenu(fig);
% Populate the context menu with items
for i = 1:length(items)
% Different callback function can be made for each option of
% the context menu. Here, selction option is printed
uimenu(cm, 'Label', items{i}, 'Callback', @(s,e)disp(['Selected Option: ', items{i}]));
end
% Sample position of the context-menu
dropdownPos = [15, 420];
cm.Position = dropdownPos;
% Make the context menu visible
cm.Visible = 'on';
end
function hideContextMenu(src)
% Hide the context menu by setting the figure's UIContextMenu to none
src.UIContextMenu = [];
end
It is worth highlighting that the above approach allows for a primary action (displaying the context menu) and secondary actions (the items within the context menu) from a single toolbar button.
For more information, you can visit the following documentation of uipushtool and uicontextmenu:
- https://www.mathworks.com/help/releases/R2023b/matlab/ref/uipushtool.html
- https://www.mathworks.com/help/releases/R2023b/matlab/ref/uicontextmenu.html
I trust this explanation addresses your query.
Thanks
6 件のコメント
Voss
2024 年 3 月 22 日
Thank you!
You can modify this line to adjust the x position of the context menu:
x = 24*idx+4*nnz(sep)-12
In case it's not clear what that's doing, it's assuming each button is 24 pixels wide and each separator is 4 pixels wide (and the -12 is to center it on the button by subtracting half the width). I don't know a way to determine what those pixel values really are, so I just used trial and error to see what worked on my system; they're probably a little different on your system.
I think you're right that it does have to do with the separator. Turn the separator off and see if it lines up properly. If so, then you only need to increase the 4. If not, then you may need to adjust the 24 and the 4 (and change the -12 to minus half the button width you find).
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!