필터 지우기
필터 지우기

Resize font size automatically when app window size is enlarged

조회 수: 19 (최근 30일)
Toufique
Toufique 2023년 4월 30일
댓글: Walter Roberson 2023년 4월 30일
I have built an application. The font size of the application when "Not-enlarged" is perfect. But when enlarged the font sizes dont increase so the all the font sizes look out of place and too tiny in an "enlarged" window of the app. How do i make the font sizes to automatically chnage/adjust with window size.
I tried with the Normalise option but did not help. similarly autoresize children option ON does not help either.
  댓글 수: 1
Adam Danz
Adam Danz 2023년 4월 30일
> I tried with the Normalise option but did not help.
Why didn't setting font units to normalized solve the problem?

댓글을 달려면 로그인하십시오.

답변 (1개)

Simon Chan
Simon Chan 2023년 4월 30일
You may try to use SizeChangedFcn callback to adjust the font size as a workaround.
The following example determine the new font size based ONLY on the vertical size of the figure. You may modify it according to your needs.
uif = uifigure;
defaultSize = uif.Position(4)-uif.Position(2); % Default vertical size of the figure
uif.AutoResizeChildren = 'off';
uif.SizeChangedFcn = {@changeFontSize,uif,defaultSize,fontSize};
fontSize = 12; % Default font size
uilabel(uif,'Position',[50 50 400 50],'Text','Change font size','FontSize',fontSize);
uitextarea(uif,'Position',[300 50 200 50],'Value','234','FontSize',fontSize);
function changeFontSize(src,event,uif,defaultSize,fontSize)
newSize = uif.Position(4)-uif.Position(2); % New vertical size of the figure
factor=newSize/defaultSize; % A factor to determine new font size
obj = findobj(uif.Children,'-property','FontSize'); % Extract objects with FontSize property
for k = 1:length(obj)
obj(k).FontSize = factor*fontSize; % Change to a new font size
end
end
  댓글 수: 5
Adam Danz
Adam Danz 2023년 4월 30일
편집: Adam Danz 2023년 4월 30일
+1 to @Walter Roberson's recommendation to consider fontsize().
The ideal solution is to set all font units to normalized.
Alternatively, you could use SizeChangedFcn in @Simon Chan's answer but instead of finding objects with a fontsize property, compute the change in figure size (newSize / oldSize) and use that ratio as a scale factor in fontsize(fig,scale=sfactor).
Walter Roberson
Walter Roberson 2023년 4월 30일
(The user marked R2020a, so they cannot use fontsize)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by