how to add a separator line in popup uicontrol?

21 vues (au cours des 30 derniers jours)
Xiangrui Li
Xiangrui Li le 25 Déc 2015
Modifié(e) : Yvan Lengwiler le 14 Juil 2016
Is there a way to add a separator line for a popup uicontrol, like what "Separator" keyword does for uimenu?
I searched, but did not get useful information. Did I search wrong keyword?
-Xiangrui Li

Réponses (2)

Walter Roberson
Walter Roberson le 25 Déc 2015
uicontrol('style','popup') do not support separator lines. You can add an entry which is a bunch of dashes but that will affect the count of the entries.
There is a trick you might be interested in: each individual cell in the cell array of strings will be parsed as HTML if it begins with '<HTML>'. For example,
uicontrol('string', {'hello', 'ab cd', '<HTML>ab cd', '<HTML>ab<br>cdef', '<HTML>ab<br>--------', 'pqrs'})
the first nbsp will be treated as pure text because it is not within an HTML marker; the one on the next line will be. The '<br>' works on the line after that leading to the '<br>' followed by a line of dashes to allow a visual separator. The drawback is that when the item is chosen, the dashes will show up as part of the current selection.
  1 commentaire
Xiangrui Li
Xiangrui Li le 26 Déc 2015
It is an interesting trick, although it doesn't look perfect. It is pity that matlab does not support this. I know one program (Igor) simply uses '-' as separator, but it will take a count of entries. Thank you for answering.

Connectez-vous pour commenter.


Yvan Lengwiler
Yvan Lengwiler le 12 Juil 2016
Modifié(e) : Yvan Lengwiler le 14 Juil 2016
Here's a solution to this problem.
function MyGUI
hline = '--------------------------------'; % string for a horiz line
mPos = 1; % store position in menu
hMenu = uicontrol(... % create popup menu
'Style' ,'popupmenu',...
'String' ,{'item 1','item 2',hline,'item 3'},...
'Callback' ,@MenuItemChanged);
function MenuItemChanged(varargin) % callback of menu control
if strcmp(hMenu.String(hMenu.Value),hline) % user picked the hline?
hMenu.Value = mPos; % then undo this choice
else
mPos = hMenu.Value; % otherwise store the new choice
end
end
end
mPos stores the previous legitimate (non-separator) item chosen in the menu. If the user selects a separator line, the callback function overrides this and selects the previous choice. The process is sufficiently such that the user does not see that the separator is selected and then immediately unselected again.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by