Filter löschen
Filter löschen

how to maintain aspect ratio of the GUI?

14 Ansichten (letzte 30 Tage)
Varun Jadhav
Varun Jadhav am 2 Feb. 2016
Kommentiert: Varun Jadhav am 7 Jun. 2016
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...

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Feb. 2016
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 Kommentare
Walter Roberson
Walter Roberson am 29 Feb. 2016
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 am 7 Jun. 2016
Thanks, Walter... :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by