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 divider strech #1540

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/divider/divider/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def startup(self):
self.main_window = toga.MainWindow(title=self.name, size=(300, 150))

style = Pack(padding_top=24)
substyle = Pack(padding_right=12, padding_left=12, flex=1)
substyle = Pack(padding_right=12, padding_left=12)

# Add the content on the main window
self.main_window.content = toga.Box(
Expand All @@ -27,7 +27,7 @@ def startup(self):
toga.Divider(direction=toga.Divider.VERTICAL, style=substyle),
toga.TextInput(placeholder="Second textbox"),
],
style=Pack(direction=ROW, padding=24, flex=1),
style=Pack(direction=ROW, padding=24),
),
],
style=Pack(direction=COLUMN, padding=24)
Expand Down
46 changes: 31 additions & 15 deletions src/core/toga/style/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)
from travertino.declaration import BaseStyle, Choices
from travertino.layout import BaseBox
from travertino.size import BaseIntrinsicSize
from travertino.size import BaseIntrinsicSize, at_least

from toga.fonts import SYSTEM_DEFAULT_FONT_SIZE, Font

Expand Down Expand Up @@ -321,14 +321,22 @@ def _layout_row_children(self, node, available_width, available_height, scale):
)
height = max(height, child_height)

# Pass 4: set vertical position of each child.
# Pass 4: set vertical position of each child, and extend flexible children to the full height.
for child in node.children:
extra = (
height
- child.layout.content_height
+ scale(child.style.padding_top)
+ scale(child.style.padding_bottom)
)
if child.style.flex or type(child.intrinsic.height) is at_least:
child.layout.content_height = (
height
- scale(child.style.padding_top)
- scale(child.style.padding_bottom)
)
extra = 0
else:
extra = (
height
- child.layout.content_height
+ scale(child.style.padding_top)
+ scale(child.style.padding_bottom)
)
# self._debug("row extra height", extra)
if self.alignment is BOTTOM:
child.layout.content_top = extra + scale(child.style.padding_top)
Expand Down Expand Up @@ -459,14 +467,22 @@ def _layout_column_children(self, node, available_width, available_height, scale
)
width = max(width, child_width)

# Pass 4: set horizontal position of each child.
# Pass 4: set horizontal position of each child, and extend flexible children to full width.
for child in node.children:
extra = (
width
- child.layout.content_width
+ scale(child.style.padding_left)
+ scale(child.style.padding_right)
)
if child.style.flex or type(child.intrinsic.width) is at_least:
child.layout.content_width = (
width
- scale(child.style.padding_left)
- scale(child.style.padding_right)
)
extra = 0
else:
extra = (
width
- child.layout.content_width
+ scale(child.style.padding_left)
+ scale(child.style.padding_right)
)
# self._debug("row extra width", extra)
if self.alignment is LEFT:
child.layout.content_left = extra + scale(child.style.padding_left)
Expand Down