Skip to content

Commit

Permalink
Enable animating offset with string. Textualize#3028
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvalmo committed Aug 7, 2023
1 parent c8af27a commit e117240
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/textual/css/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,24 @@ def resolve(self, size: Size, viewport: Size) -> Offset:
round(y.resolve(size, viewport)),
)

@classmethod
def parse(cls, token: str) -> ScalarOffset:
"""Create a scalar offset from a string.
Args:
token: String to parse (e.g. '1 2' or '1.0 2.0')
Returns:
New offset
"""
x, y = token.split()
# fmt: off
return cls(
Scalar.parse(x, Unit.WIDTH),
Scalar.parse(y, Unit.HEIGHT)
)
# fmt: on


NULL_SCALAR = ScalarOffset(Scalar.from_number(0), Scalar.from_number(0))

Expand Down
2 changes: 2 additions & 0 deletions tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ async def test_animate_height() -> None:
Offset(10, 5),
(10, 5),
(10.0, 5.0),
"10 5",
"10.0 5.0",
]


Expand Down

0 comments on commit e117240

Please sign in to comment.