More on the menu fontsize

2 ビュー (過去 30 日間)
David Koenig
David Koenig 2012 年 2 月 25 日
Earlier today I asked a question about increasing the font size of the menu entries without affecting the font size of subsequent plots. Sean graciously answered with the following script:
ii=1;
while ii==1
oldSPPI = get(0,'screenpixelsperinch'); %store old one
set(0,'screenpixelsperinch',200);
kk = menu('choose','me','no me!','go home it''s Friday!');
set(0,'screenpixelsperinch',oldSPPI); %restore
figure;
plot(1:10,1:10),grid
title('Test Plot')
if kk==1
break
end
end
This script removes the problem I had with error messages. But, after it makes the plot using the original smaller font size, it immediately converts the plot back to the larger font size as soon as it returns to the top of the while loop and executes the set statement. So, while the script is idling waiting for a mouse click, the graph has the undesirable large font size. Only if you mouse click on the first choice, "me", and generate kk=1 do you leave the plot in the desired original font size because the while loop does not go back to the first set statement.
Apparently, it is not possible to increase the font size for the menu and leave the plots in their original font size. Is this true?
Thanks,
Dave

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 2 月 27 日
You misinterpretted by intent. It IS possible to do this, just not with the stock menu() function. You'll have to write your own menu() function (basically a modal figure with a few uicontrols that returns a number. Since you'll be constructing the uicontrols yourself you can give them a nice large fontsize. It should be pretty straightfoward.
Here is something I threw together that should do what you want. It's a bit sloppy on the positioning but could be easily modified to be made pretty:
function selection = mymenu(question,varargin)
%Simple my menu
%
%Usage:
% -selection = mymenu('Choose one please:','monday','tuesday','wednesday')
%
%Inputs:
% -question: string with question
% -options: n strings of options
%
%Outputs:
% -selection: index of selected button
%
%Error checking:
assert(nargin >=2 ,'At least two inputs expected');
assert(ischar(question),'question should be a string');
assert(all(cellfun(@ischar,varargin)), 'options should be strings')
%Build figure:
n = length(varargin); %number of options
hF = figure('windowstyle','modal','units','pix','position',[300 300 200 (n+1)*80]);
uicontrol('style','text','position',[10 (n+1)*70,100,20],'string',question);
for ii = n:-1:1
H(ii) = uicontrol('style','push','units','pix','position',[10 (ii-1)*80 150 60],...
'string',varargin{ii},'fontsize',20,'callback',@select);
end
waitfor(hF)
%Select and close:
function select(src,~)
idx = 1:n;
selection = idx(ismember(H,src));
close(hF)
return
end
end
Save this is in mymenu.m
  1 件のコメント
David Koenig
David Koenig 2012 年 2 月 27 日
Thanks, Sean, for your extra trouble to respond to this.
Regards,
Dave

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by