Skip to content

Commit

Permalink
Merge branch 'pack-fixes' into audit-imageview
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Jun 4, 2023
2 parents 66b9fdd + a697875 commit d4d2216
Show file tree
Hide file tree
Showing 20 changed files with 3,549 additions and 2,002 deletions.
1 change: 1 addition & 0 deletions changes/1958.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pack layout now honors an explicit width/height setting of 0.
1 change: 1 addition & 0 deletions changes/1958.removal.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A row box contained inside a row box will now expand to the full height of its parent, rather than collapsing to the maximum height of the inner box's child content.
1 change: 1 addition & 0 deletions changes/1958.removal.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A column box contained inside a column box will now expand to the full width of its parent, rather than collapsing to the maximum width of the inner box's child content.
8 changes: 4 additions & 4 deletions cocoa/src/toga_cocoa/widgets/imageview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from travertino.size import at_least

from toga.style.pack import COLUMN
from toga.style.pack import COLUMN, NONE
from toga_cocoa.libs import (
NSImageAlignment,
NSImageFrameNone,
Expand Down Expand Up @@ -34,18 +34,18 @@ def rehint(self):
image = self.native.image
if image:
style = self.interface.style
if style.width and style.height:
if style.width != NONE and style.height != NONE:
# Explicit width and height for image. Scale the rendered image
# to fit the explicitly provided size.
width = style.width
height = style.height
self.native.imageScaling = NSImageScaleAxesIndependently
elif style.width:
elif style.width != NONE:
# Explicit width, implicit height. Preserve aspect ratio.
width = style.width
height = style.width * image.size.height // image.size.width
self.native.imageScaling = NSImageScaleProportionallyUpOrDown
elif style.height:
elif style.height != NONE:
# Explicit height, implicit width. Preserve aspect ratio.
width = style.height * image.size.width // image.size.height
height = style.height
Expand Down
384 changes: 253 additions & 131 deletions core/src/toga/style/pack.py

Large diffs are not rendered by default.

Empty file.
Empty file.
99 changes: 99 additions & 0 deletions core/tests/style/pack/layout/test_beeliza.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from travertino.size import at_least

from toga.style.pack import COLUMN, ROW, Pack

from ..utils import ExampleNode, ExampleViewport, assert_layout


def test_beeliza():
root = ExampleNode(
"app",
style=Pack(direction=COLUMN),
children=[
ExampleNode(
"detailedlist",
style=Pack(flex=1),
size=(at_least(100), at_least(100)),
),
ExampleNode(
"box",
style=Pack(direction=ROW),
children=[
ExampleNode(
"input",
style=Pack(flex=1, padding=5),
size=(at_least(100), 15),
),
ExampleNode(
"button", style=Pack(padding=5), size=(at_least(40), 10)
),
],
),
],
)

# Minimum size
root.style.layout(root, ExampleViewport(0, 0, dpi=96))
assert_layout(
root,
(160, 125),
{
"origin": (0, 0),
"content": (160, 125),
"children": [
{"origin": (0, 0), "content": (100, 100)},
{
"origin": (0, 100),
"content": (160, 25),
"children": [
{"origin": (5, 105), "content": (100, 15)},
{"origin": (115, 105), "content": (40, 10)},
],
},
],
},
)

# Normal size
root.style.layout(root, ExampleViewport(640, 480, dpi=96))
assert_layout(
root,
(640, 480),
{
"origin": (0, 0),
"content": (640, 480),
"children": [
{"origin": (0, 0), "content": (640, 455)},
{
"origin": (0, 455),
"content": (640, 25),
"children": [
{"origin": (5, 460), "content": (580, 15)},
{"origin": (595, 460), "content": (40, 10)},
],
},
],
},
)

# HiDPI Normal size
root.style.layout(root, ExampleViewport(640, 480, dpi=144))
assert_layout(
root,
(640, 480),
{
"origin": (0, 0),
"content": (640, 480),
"children": [
{"origin": (0, 0), "content": (640, 451)},
{
"origin": (0, 451),
"content": (640, 29),
"children": [
{"origin": (7, 458), "content": (572, 15)},
{"origin": (593, 458), "content": (40, 10)},
],
},
],
},
)
Loading

0 comments on commit d4d2216

Please sign in to comment.