Skip to content

Commit 5664b3e

Browse files
committed
width dimensions
1 parent f2c06f3 commit 5664b3e

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

src/textual/_arrange.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,13 @@ def arrange(
9999
# Perform any alignment of the widgets.
100100
if styles.align_horizontal != "left" or styles.align_vertical != "top":
101101
bounding_region = WidgetPlacement.get_bounds(layout_placements)
102-
103102
container_width, container_height = dock_region.size
104-
widget.log(
105-
widget, bounding_region=bounding_region, container=dock_region
106-
)
107-
108-
min_height = 0
109-
if styles.min_height is not None:
110-
min_height = int(
111-
styles.min_height.resolve(size, viewport, Fraction(size.height))
112-
)
113-
103+
extrema = widget._extrema
114104
placement_offset += styles._align_size(
115105
bounding_region.size,
116-
Size(
106+
extrema.apply_dimensions(
117107
0 if styles.is_auto_width else container_width,
118-
min_height if styles.is_auto_height else container_height,
108+
0 if styles.is_auto_height else container_height,
119109
),
120110
).clamped
121111

src/textual/_extrema.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from fractions import Fraction
44
from typing import NamedTuple
55

6+
from textual.geometry import Size
7+
68

79
class Extrema(NamedTuple):
810
"""Specifies minimum and maximum dimensions."""
@@ -45,3 +47,18 @@ def apply_height(self, height: Fraction) -> Fraction:
4547
if max_height is not None:
4648
height = min(height, max_height)
4749
return height
50+
51+
def apply_dimensions(self, width: int, height: int) -> Size:
52+
"""Apply extrema to integer dimensions.
53+
54+
Args:
55+
width: Integer width.
56+
height: Integer height.
57+
58+
Returns:
59+
Size with extrema applied.
60+
"""
61+
return Size(
62+
int(self.apply_width(Fraction(width))),
63+
int(self.apply_height(Fraction(height))),
64+
)

src/textual/layout.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from abc import ABC, abstractmethod
44
from dataclasses import dataclass
5+
from fractions import Fraction
56
from typing import TYPE_CHECKING, ClassVar, Iterable, NamedTuple
67

78
from textual._spatial_map import SpatialMap
@@ -237,9 +238,16 @@ def get_content_width(self, widget: Widget, container: Size, viewport: Size) ->
237238
width = 0
238239
else:
239240
arrangement = widget._arrange(
240-
Size(0 if widget.shrink else container.width, 0)
241+
Size(
242+
(
243+
int(widget._extrema.min_width or 0)
244+
if widget.shrink
245+
else int(widget._extrema.apply_width(Fraction(container.width)))
246+
),
247+
0,
248+
)
241249
)
242-
width = arrangement.total_region.right
250+
width = arrangement.total_region.width
243251
return width
244252

245253
def get_content_height(
@@ -264,11 +272,14 @@ def get_content_height(
264272
):
265273
# An exception for containers with all dynamic height widgets
266274
arrangement = widget._arrange(
267-
Size(width, widget._extrema.apply_height(container.height))
275+
Size(
276+
width,
277+
int(widget._extrema.apply_height(Fraction(container.height))),
278+
)
268279
)
269280
else:
270281
arrangement = widget._arrange(
271-
Size(width, widget._extrema.min_height or 0)
282+
Size(width, int(widget._extrema.min_height or 0))
272283
)
273284
height = arrangement.total_region.height
274285
else:

0 commit comments

Comments
 (0)