how to add a separator line in popup uicontrol?

15 visualizaciones (últimos 30 días)
Xiangrui Li
Xiangrui Li el 25 de Dic. de 2015
Editada: Yvan Lengwiler el 14 de Jul. de 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

Respuestas (2)

Walter Roberson
Walter Roberson el 25 de Dic. de 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 comentario
Xiangrui Li
Xiangrui Li el 26 de Dic. de 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.

Iniciar sesión para comentar.


Yvan Lengwiler
Yvan Lengwiler el 12 de Jul. de 2016
Editada: Yvan Lengwiler el 14 de Jul. de 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.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by