how to maintain aspect ratio of the GUI?
11 次查看(过去 30 天)
显示 更早的评论
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...
0 个评论
采纳的回答
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!