mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'main' into stuck-screen
This commit is contained in:
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
### Fixed
|
||||
|
||||
- Fixed stuck screen https://github.com/Textualize/textual/issues/1632
|
||||
- Fixed relative units in `grid-rows` and `grid-columns` being computed with respect to the wrong dimension https://github.com/Textualize/textual/issues/1406
|
||||
|
||||
## [0.10.1] - 2023-01-20
|
||||
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
try:
|
||||
import click
|
||||
except ImportError:
|
||||
print("Please install 'textual[dev]' to use the 'textual' command")
|
||||
sys.exit(1)
|
||||
|
||||
import click
|
||||
from importlib_metadata import version
|
||||
|
||||
from textual.pilot import Pilot
|
||||
|
||||
@@ -202,6 +202,9 @@ class ScalarProperty:
|
||||
|
||||
|
||||
class ScalarListProperty:
|
||||
def __init__(self, percent_unit: Unit) -> None:
|
||||
self.percent_unit = percent_unit
|
||||
|
||||
def __set_name__(self, owner: Styles, name: str) -> None:
|
||||
self.name = name
|
||||
|
||||
@@ -229,7 +232,7 @@ class ScalarListProperty:
|
||||
scalars.append(Scalar.from_number(parse_value))
|
||||
else:
|
||||
scalars.append(
|
||||
Scalar.parse(parse_value)
|
||||
Scalar.parse(parse_value, self.percent_unit)
|
||||
if isinstance(parse_value, str)
|
||||
else parse_value
|
||||
)
|
||||
|
||||
@@ -865,16 +865,12 @@ class StylesBuilder:
|
||||
|
||||
def _process_grid_rows_or_columns(self, name: str, tokens: list[Token]) -> None:
|
||||
scalars: list[Scalar] = []
|
||||
percent_unit = Unit.WIDTH if name == "grid-columns" else Unit.HEIGHT
|
||||
for token in tokens:
|
||||
if token.name == "number":
|
||||
scalars.append(Scalar.from_number(float(token.value)))
|
||||
elif token.name == "scalar":
|
||||
scalars.append(
|
||||
Scalar.parse(
|
||||
token.value,
|
||||
percent_unit=Unit.WIDTH if name == "rows" else Unit.HEIGHT,
|
||||
)
|
||||
)
|
||||
scalars.append(Scalar.parse(token.value, percent_unit=percent_unit))
|
||||
else:
|
||||
self.error(
|
||||
name,
|
||||
|
||||
@@ -277,8 +277,8 @@ class StylesBase(ABC):
|
||||
content_align_vertical = StringEnumProperty(VALID_ALIGN_VERTICAL, "top")
|
||||
content_align = AlignProperty()
|
||||
|
||||
grid_rows = ScalarListProperty()
|
||||
grid_columns = ScalarListProperty()
|
||||
grid_rows = ScalarListProperty(percent_unit=Unit.HEIGHT)
|
||||
grid_columns = ScalarListProperty(percent_unit=Unit.WIDTH)
|
||||
|
||||
grid_size_columns = IntegerProperty(default=1, layout=True)
|
||||
grid_size_rows = IntegerProperty(default=0, layout=True)
|
||||
|
||||
@@ -561,8 +561,12 @@ class Widget(DOMNode):
|
||||
|
||||
Args:
|
||||
*widgets: The widget(s) to mount.
|
||||
before: Optional location to mount before.
|
||||
after: Optional location to mount after.
|
||||
before: Optional location to mount before. An `int` is the index
|
||||
of the child to mount before, a `str` is a `query_one` query to
|
||||
find the widget to mount before.
|
||||
after: Optional location to mount after. An `int` is the index
|
||||
of the child to mount after, a `str` is a `query_one` query to
|
||||
find the widget to mount after.
|
||||
|
||||
Returns:
|
||||
An awaitable object that waits for widgets to be mounted.
|
||||
@@ -624,8 +628,12 @@ class Widget(DOMNode):
|
||||
|
||||
Args:
|
||||
child: The child widget to move.
|
||||
before: (int | Widget, optional): Optional location to move before.
|
||||
after: (int | Widget, optional): Optional location to move after.
|
||||
before: Optional location to move before. An `int` is the index
|
||||
of the child to move before, a `str` is a `query_one` query to
|
||||
find the widget to move before.
|
||||
after: Optional location to move after. An `int` is the index
|
||||
of the child to move after, a `str` is a `query_one` query to
|
||||
find the widget to move after.
|
||||
|
||||
Raises:
|
||||
WidgetError: If there is a problem with the child or target.
|
||||
|
||||
42
tests/css/test_grid_rows_columns_relative_units.py
Normal file
42
tests/css/test_grid_rows_columns_relative_units.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
Regression tests for #1406 https://github.com/Textualize/textual/issues/1406
|
||||
|
||||
The scalars in grid-rows and grid-columns were not aware of the dimension
|
||||
they should be relative to.
|
||||
"""
|
||||
|
||||
from textual.css.parse import parse_declarations
|
||||
from textual.css.scalar import Unit
|
||||
from textual.css.styles import Styles
|
||||
|
||||
|
||||
def test_grid_rows_columns_relative_units_are_correct():
|
||||
"""Ensure correct relative dimensions for programmatic assignments."""
|
||||
|
||||
styles = Styles()
|
||||
|
||||
styles.grid_columns = "1fr 5%"
|
||||
fr, percent = styles.grid_columns
|
||||
assert fr.percent_unit == Unit.WIDTH
|
||||
assert percent.percent_unit == Unit.WIDTH
|
||||
|
||||
styles.grid_rows = "1fr 5%"
|
||||
fr, percent = styles.grid_rows
|
||||
assert fr.percent_unit == Unit.HEIGHT
|
||||
assert percent.percent_unit == Unit.HEIGHT
|
||||
|
||||
|
||||
def test_styles_builder_uses_correct_relative_units_grid_rows_columns():
|
||||
"""Ensure correct relative dimensions for CSS parsed from files."""
|
||||
|
||||
CSS = "grid-rows: 1fr 5%; grid-columns: 1fr 5%;"
|
||||
|
||||
styles = parse_declarations(CSS, "test")
|
||||
|
||||
fr, percent = styles.grid_columns
|
||||
assert fr.percent_unit == Unit.WIDTH
|
||||
assert percent.percent_unit == Unit.WIDTH
|
||||
|
||||
fr, percent = styles.grid_rows
|
||||
assert fr.percent_unit == Unit.HEIGHT
|
||||
assert percent.percent_unit == Unit.HEIGHT
|
||||
Reference in New Issue
Block a user