From b5f9d9592deed8336de273cd61ccecfe7128598e Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Sat, 26 Feb 2011 13:29:21 +0100 Subject: [PATCH] image: fix the image ratio calculation. Closes #71 --- kivy/uix/image.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/kivy/uix/image.py b/kivy/uix/image.py index c67ab0733..e60f5840b 100644 --- a/kivy/uix/image.py +++ b/kivy/uix/image.py @@ -100,22 +100,17 @@ class Image(Widget): ratio = self.image_ratio w, h = self.size tw, th = self.texture.size - iw, ih = 0, 0 - # cases if the image is lower than the widget - if iw < w and ih < h: - if iw < w: - iw = w - ih = iw / ratio - elif ih < h: - ih = h - iw = ih * ratio - # cases if the image is bigger than the widget - if iw > w: - iw = w - ih = iw * ratio + + # ensure that the width is always maximized to the containter width + iw = w if tw < w else w + # calculate the appropriate height + ih = iw / ratio + # if the height is too higher, take the height of the container + # and calculate appropriate width. no need to test further. :) if ih > h: ih = h - iw = ih / ratio + iw = ih * ratio + return iw, ih