what is the replacement for uisplittool?

3 visualizaciones (últimos 30 días)
Christian
Christian el 4 de Mzo. de 2024
Comentada: Voss el 22 de Mzo. de 2024
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 comentarios
Christian
Christian el 19 de Mzo. de 2024
It is used in the dropdown case instead of inserting an image-icon in the toolbar
```
case 'dropdown'
hm = uisplittool(toolbar,'tooltipstring',row{colm.ToolTip});
set(hm,'separator',row{colm.Separator});
```
Christian
Christian el 19 de Mzo. de 2024
I looked more into the specific function of it. It is a dropdown on an image that is in the toolbar. This code was written before the UI tools that were introduced in the R2016a release.

Iniciar sesión para comentar.

Respuesta aceptada

Shivam
Shivam el 19 de Mzo. de 2024
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:
I trust this explanation addresses your query.
Thanks
  6 comentarios
Christian
Christian el 22 de Mzo. de 2024
Those are useful and cool changes @Voss. On my machine, the dropdown's left edge is aligned with the center of the button but only for the first button. The last button's left edge is flush with the dropdown's left edge unfortunately. I don't know if it has anything to do with the separator line or how to make thoes consistent
Voss
Voss el 22 de Mzo. de 2024
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).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by