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 3 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
6 changes: 2 additions & 4 deletions src/cocoa/toga_cocoa/widgets/divider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from travertino.size import at_least

from toga_cocoa.libs import NSBox, NSBoxType

from .base import Widget
Expand All @@ -18,9 +16,9 @@ def rehint(self):

if self.interface.direction == self.interface.VERTICAL:
self.interface.intrinsic.width = content_size.width
self.interface.intrinsic.height = at_least(content_size.height)
self.interface.intrinsic.height = 0
else:
self.interface.intrinsic.width = at_least(content_size.width)
self.interface.intrinsic.width = 0
self.interface.intrinsic.height = content_size.height

def set_direction(self, value):
Expand Down
40 changes: 28 additions & 12 deletions src/core/toga/style/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,20 @@ def _layout_row_children(self, node, available_width, available_height, scale):

# Pass 4: set vertical position of each child.
for child in node.children:
extra = (
height
- child.layout.content_height
+ scale(child.style.padding_top)
+ scale(child.style.padding_bottom)
)
if not self.height and not child.intrinsic.height:
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 @@ -461,12 +469,20 @@ def _layout_column_children(self, node, available_width, available_height, scale

# Pass 4: set horizontal position of each child.
for child in node.children:
extra = (
width
- child.layout.content_width
+ scale(child.style.padding_left)
+ scale(child.style.padding_right)
)
if not self.width and not child.intrinsic.width:
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