Effacer les filtres
Effacer les filtres

how to maintain aspect ratio of the GUI?

14 vues (au cours des 30 derniers jours)
Varun Jadhav
Varun Jadhav le 2 Fév 2016
Commenté : Varun Jadhav le 7 Juin 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...

Réponse acceptée

Walter Roberson
Walter Roberson le 2 Fév 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 commentaires
Walter Roberson
Walter Roberson le 29 Fév 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 le 7 Juin 2016
Thanks, Walter... :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by