필터 지우기
필터 지우기

how to maintain aspect ratio of the GUI?

조회 수: 14 (최근 30일)
Varun Jadhav
Varun Jadhav 2016년 2월 2일
댓글: Varun Jadhav 2016년 6월 7일
Hello,
I have made a GUI and designed it to fit well in the entire screen space of my workstation, but if I run the file on my laptop, it doesn't resize or maintain aspect ratio ergo rendering some parts of the GUI inaccessible. How do I make the changes??? Please help...
Thank you in advance...

채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 2일
You would be able to use this to enforce proportions. Fetch the current figure height and width and use your target aspect ratio to compute the ideal width. If the actual width is larger than the ideal width then make the window narrower leaving the height alone; if the actual width is smaller than the ideal width then make the window shorter leaving the width alone.
Everything else would be set to be positioned proportional to the figure.
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 2월 29일
function my_resize(src, event)
fig = ancestor(src, 'figure'); %but expect src to be fig
target_aspect = 16/9;
pos = get(fig, 'Position');
cur_wid = pos(3);
cur_high = pos(4);
target_wid = cur_high * target_aspect;
target_high = cur_wid / target_aspect;
need_change = true;
if cur_wid > target_wid
cur_wid = target_wid;
elseif cur_wid < target_wid
cur_high = target_high;
else
need_change = false;
end
if need_change
set(fig, 'Position', [pos(1), pos(2), cur_wid, cur_high]);
drawnow();
end
Varun Jadhav
Varun Jadhav 2016년 6월 7일
Thanks, Walter... :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by