MainWindow.size strange behaviour in android #2273
Replies: 1 comment 1 reply
-
The underlying problem is that at the point you're asking for the window size, the window doesn't exist yet. It won't exist until after I've logged this as #2274; see that ticket for an explanation and a potential workaround. However, in terms of the way Toga tries to represent layouts, it's also not the best approach for the use case you're describing. By setting the imageView to a specific width, the layout can't dynamically adapt to size changes. The layout will work as long as the phone is in portrait mode, but if the phone rotates to landscape mode, the layout won't adapt. You'll also see this on Windows if you resize the window. Unfortunately, this is also an area where Toga has a bug at present. If an image is smaller than the window, specifying flex=1 will cause Toga to make the image expand to fill the available space; however, if the image is larger than the window, it won't shrink the image to fit the window. I've logged this as #2275; I think I have a fix for this problem - watch the ticket for updates. |
Beta Was this translation helpful? Give feedback.
-
Moving my first steps on toga, I run in this strange behaviour of MainWindow.size:
The following minimum working example work differently on windows and android.
On windows the button text change when the application is started, and it shows the real window dimension (e.g. (640,480)), while on android when the application is started it shows (0,0). However when I press the button,
my_func
works ok and it gives the real window size.My real question is: how can I get the window dimensions on the startup? My goal is to add a image to the windows that fit the windows width, something like:
toga.ImageView(my_image, style=Pack(flex=1, width=self.main_window.size[0]))
which works on windows but not on android
Beta Was this translation helpful? Give feedback.
All reactions