Azzera filtri
Azzera filtri

how to maintain aspect ratio of the GUI?

14 visualizzazioni (ultimi 30 giorni)
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...

Risposta accettata

Walter Roberson
Walter Roberson il 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 Commenti
Walter Roberson
Walter Roberson il 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 il 7 Giu 2016
Thanks, Walter... :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by