kivy / kivy

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS
https://kivy.org
MIT License
17k stars 3.04k forks source link

AnchorLayout prevents child widgets from controlling their height #8669

Open nanouasyn opened 1 month ago

nanouasyn commented 1 month ago

Software Versions

Describe the bug When a widget that sets its height based on its width is placed in an AnchorLayout, the height of the widget does not change according to its width set by the AnchorLayout. AnchorLayout controls the height of such a widget, ignoring the outright prohibition (size_hint_y = None).

To Reproduce

Put the Image widget, which increases its height based on its width and image proportions, inside the AnchorLayout. Set size_hint_y to None to prevent AnchorLayout from controlling the height of the Image.

from kivy.lang import Builder
from kivy.app import runTouchApp

runTouchApp(Builder.load_string("""
AnchorLayout:
    anchor_y: 'center'
    Image:
        source: 'data/logo/kivy-icon-256.png'
        fit_mode: 'fill'
        size_hint_y: None
        height: self.width * self.texture_size[1] / self.texture_size[0]
"""))

It is expected that when changing the width of the AnchorLayout, the Image will change its height. But in fact, the height of the Image does not change:

https://github.com/kivy/kivy/assets/27895729/09cc4994-f192-4c57-a73b-02e21554a810

Expected behavior

Image should change size, filling the window in width and keeping the proportions.

https://github.com/kivy/kivy/assets/27895729/3032f785-775d-441d-8ec1-0e27b104983b