Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AnchorLayout children height bug (#8669) #8670

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions kivy/tests/test_uix_anchorlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,40 @@ def test_anchor_layout_xy(self):
layout = AnchorLayout(anchor_y='top', anchor_x='right')
layout.add_widget(b(1, 0, 0))
r(layout)


class TestAnchorLayout:

def test_anchorlayout_no_height_control(self):
from kivy.uix.widget import Widget
from kivy.uix.anchorlayout import AnchorLayout

def update_height(widget, value):
widget.height = 2 * widget.width

widget = Widget(size_hint=(1, None))
widget.bind(width=update_height)
layout = AnchorLayout(size=(1000, 1000))
layout.add_widget(widget)

layout.do_layout()

assert widget.size == [1000, 2000]
assert widget.pos == [0, -500]

def test_anchorlayout_no_width_control(self):
from kivy.uix.widget import Widget
from kivy.uix.anchorlayout import AnchorLayout

def update_width(widget, value):
widget.width = 2 * widget.height

widget = Widget(size_hint=(None, 1))
widget.bind(height=update_width)
layout = AnchorLayout(size=(1000, 1000))
layout.add_widget(widget)

layout.do_layout()

assert widget.size == [2000, 1000]
assert widget.pos == [-500, 0]
6 changes: 4 additions & 2 deletions kivy/uix/anchorlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def do_layout(self, *largs):

for c in self.children:
x, y = _x, _y
cw, ch = c.size
shw, shh = c.size_hint
shw_min, shh_min = c.size_hint_min
shw_max, shh_max = c.size_hint_max
Expand All @@ -97,13 +96,17 @@ def do_layout(self, *largs):
cw = shw_min
elif shw_max is not None and cw > shw_max:
cw = shw_max
c.width = cw

if shh is not None:
ch = shh * (height - pad_top - pad_bottom)
if shh_min is not None and ch < shh_min:
ch = shh_min
elif shh_max is not None and ch > shh_max:
ch = shh_max
c.height = ch

cw, ch = c.size

if anchor_x == 'left':
x = x + pad_left
Expand All @@ -119,4 +122,3 @@ def do_layout(self, *largs):
y = y + (height - pad_top + pad_bottom - ch) / 2

c.pos = x, y
c.size = cw, ch