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 for percentage dimensions #4037

Merged
merged 6 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `SelectionList` option IDs are usable as soon as the widget is instantiated https://github.com/Textualize/textual/issues/3903
- Fix issue with `Strip.crop` when crop window start aligned with strip end https://github.com/Textualize/textual/pull/3998
- Fixed Strip.crop_extend https://github.com/Textualize/textual/pull/4011
- Fix for percentage dimensions https://github.com/Textualize/textual/pull/4037


## [0.47.1] - 2023-01-05
Expand Down
6 changes: 0 additions & 6 deletions src/textual/css/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class Unit(Enum):
AUTO = 8


UNIT_EXCLUDES_BORDER = {Unit.CELLS, Unit.FRACTION, Unit.VIEW_WIDTH, Unit.VIEW_HEIGHT}

UNIT_SYMBOL = {
Unit.CELLS: "",
Unit.FRACTION: "fr",
Expand Down Expand Up @@ -206,10 +204,6 @@ def is_fraction(self) -> bool:
"""Check if the unit is a fraction."""
return self.unit == Unit.FRACTION

@property
def excludes_border(self) -> bool:
return self.unit in UNIT_EXCLUDES_BORDER

@property
def cells(self) -> int | None:
"""Check if the unit is explicit cells."""
Expand Down
26 changes: 8 additions & 18 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,6 @@ def _get_box_model(

# Container minus padding and border
content_container = container - gutter.totals
# The container including the content
sizing_container = content_container if is_border_box else container

if styles.width is None:
# No width specified, fill available space
Expand All @@ -1099,25 +1097,21 @@ def _get_box_model(
# An explicit width
styles_width = styles.width
content_width = styles_width.resolve(
sizing_container - styles.margin.totals, viewport, width_fraction
container - styles.margin.totals, viewport, width_fraction
)
if is_border_box and styles_width.excludes_border:
if is_border_box:
content_width -= gutter.width

if styles.min_width is not None:
# Restrict to minimum width, if set
min_width = styles.min_width.resolve(
content_container, viewport, width_fraction
)
min_width = styles.min_width.resolve(container, viewport, width_fraction)
if is_border_box:
min_width -= gutter.width
content_width = max(content_width, min_width, Fraction(0))

if styles.max_width is not None:
# Restrict to maximum width, if set
max_width = styles.max_width.resolve(
content_container, viewport, width_fraction
)
max_width = styles.max_width.resolve(container, viewport, width_fraction)
if is_border_box:
max_width -= gutter.width
content_width = min(content_width, max_width)
Expand All @@ -1143,25 +1137,21 @@ def _get_box_model(
styles_height = styles.height
# Explicit height set
content_height = styles_height.resolve(
sizing_container - styles.margin.totals, viewport, height_fraction
container - styles.margin.totals, viewport, height_fraction
)
if is_border_box and styles_height.excludes_border:
rodrigogiraoserrao marked this conversation as resolved.
Show resolved Hide resolved
if is_border_box:
content_height -= gutter.height

if styles.min_height is not None:
# Restrict to minimum height, if set
min_height = styles.min_height.resolve(
content_container, viewport, height_fraction
)
min_height = styles.min_height.resolve(container, viewport, height_fraction)
if is_border_box:
min_height -= gutter.height
content_height = max(content_height, min_height, Fraction(0))

if styles.max_height is not None:
# Restrict maximum height, if set
max_height = styles.max_height.resolve(
content_container, viewport, height_fraction
)
max_height = styles.max_height.resolve(container, viewport, height_fraction)
if is_border_box:
max_height -= gutter.height
content_height = min(content_height, max_height)
Expand Down
Loading
Loading