Skip to content

Commit dabb773

Browse files
authored
Merge pull request #5186 from Textualize/layout-micro-ops
micro ops
2 parents f28764e + e90d6d2 commit dabb773

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

src/textual/_resolve.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ def resolve_fraction_unit(
104104
Returns:
105105
The value of 1fr.
106106
"""
107+
_Fraction = Fraction
107108
if not remaining_space or not widget_styles:
108-
return Fraction(1)
109+
return _Fraction(1)
109110

110111
initial_space = remaining_space
111112

@@ -155,19 +156,19 @@ def resolve_scalar(
155156

156157
while remaining_fraction > 0:
157158
remaining_space_changed = False
158-
resolve_fraction = Fraction(remaining_space, remaining_fraction)
159+
resolve_fraction = _Fraction(remaining_space, remaining_fraction)
159160
for index, (scalar, min_value, max_value) in enumerate(resolve):
160161
value = resolved[index]
161162
if value is None:
162163
resolved_scalar = scalar.resolve(size, viewport_size, resolve_fraction)
163164
if min_value is not None and resolved_scalar < min_value:
164165
remaining_space -= min_value
165-
remaining_fraction -= Fraction(scalar.value)
166+
remaining_fraction -= _Fraction(scalar.value)
166167
resolved[index] = min_value
167168
remaining_space_changed = True
168169
elif max_value is not None and resolved_scalar > max_value:
169170
remaining_space -= max_value
170-
remaining_fraction -= Fraction(scalar.value)
171+
remaining_fraction -= _Fraction(scalar.value)
171172
resolved[index] = max_value
172173
remaining_space_changed = True
173174

@@ -219,8 +220,16 @@ def resolve_box_models(
219220
else widget._get_box_model(
220221
size,
221222
viewport_size,
222-
max(fraction_zero, fraction_width - margin_width),
223-
max(fraction_zero, fraction_height - margin_height),
223+
(
224+
fraction_zero
225+
if (_width := fraction_width - margin_width) < 0
226+
else _width
227+
),
228+
(
229+
fraction_zero
230+
if (_height := fraction_height - margin_height) < 0
231+
else _height
232+
),
224233
)
225234
)
226235
for (_dimension, widget, (margin_width, margin_height)) in zip(

src/textual/demo/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ class WidgetsScreen(PageScreen):
446446
}
447447
"""
448448

449-
BINDINGS = [("escape", "unfocus")]
449+
BINDINGS = [("escape", "unfocus", "Unfocus any focused widget")]
450450

451451
def compose(self) -> ComposeResult:
452452
with containers.VerticalScroll() as container:

src/textual/layouts/vertical.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ def arrange(
3737
),
3838
sum(
3939
[
40-
max(margin1[2], margin2[0])
41-
for margin1, margin2 in zip(box_margins, box_margins[1:])
40+
bottom if bottom > top else top
41+
for (_, _, bottom, _), (top, _, _, _) in zip(
42+
box_margins, box_margins[1:]
43+
)
4244
]
4345
)
4446
+ (box_margins[0].top + box_margins[-1].bottom),
@@ -56,9 +58,14 @@ def arrange(
5658
)
5759

5860
margins = [
59-
max((box1.margin.bottom, box2.margin.top))
60-
for box1, box2 in zip(box_models, box_models[1:])
61+
(
62+
margin_bottom
63+
if (margin_bottom := margin1.bottom) > (margin_top := margin2.top)
64+
else margin_top
65+
)
66+
for (_, _, margin1), (_, _, margin2) in zip(box_models, box_models[1:])
6167
]
68+
6269
if box_models:
6370
margins.append(box_models[-1].margin.bottom)
6471

@@ -82,9 +89,9 @@ def arrange(
8289
_WidgetPlacement(
8390
_Region(
8491
box_margin.left,
85-
int(y),
86-
int(content_width),
87-
int(next_y) - int(y),
92+
y.__int__(),
93+
content_width.__int__(),
94+
next_y.__int__() - y.__int__(),
8895
),
8996
box_margin,
9097
widget,

0 commit comments

Comments
 (0)