how to add a separator line in popup uicontrol?

14 visualizzazioni (ultimi 30 giorni)
Xiangrui Li
Xiangrui Li il 25 Dic 2015
Modificato: Yvan Lengwiler il 14 Lug 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

Risposte (2)

Walter Roberson
Walter Roberson il 25 Dic 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 Commento
Xiangrui Li
Xiangrui Li il 26 Dic 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.

Accedi per commentare.


Yvan Lengwiler
Yvan Lengwiler il 12 Lug 2016
Modificato: Yvan Lengwiler il 14 Lug 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.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by