Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Textualize/textual into themes
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Oct 28, 2024
2 parents 4589f09 + dabb773 commit 2608413
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
23 changes: 16 additions & 7 deletions src/textual/_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def resolve(

fraction_gutter = Fraction(gutter)
offsets = [0] + [
int(fraction)
fraction.__int__()
for fraction in accumulate(
value
for fraction in resolved_fractions
Expand Down Expand Up @@ -104,8 +104,9 @@ def resolve_fraction_unit(
Returns:
The value of 1fr.
"""
_Fraction = Fraction
if not remaining_space or not widget_styles:
return Fraction(1)
return _Fraction(1)

initial_space = remaining_space

Expand Down Expand Up @@ -155,19 +156,19 @@ def resolve_scalar(

while remaining_fraction > 0:
remaining_space_changed = False
resolve_fraction = Fraction(remaining_space, remaining_fraction)
resolve_fraction = _Fraction(remaining_space, remaining_fraction)
for index, (scalar, min_value, max_value) in enumerate(resolve):
value = resolved[index]
if value is None:
resolved_scalar = scalar.resolve(size, viewport_size, resolve_fraction)
if min_value is not None and resolved_scalar < min_value:
remaining_space -= min_value
remaining_fraction -= Fraction(scalar.value)
remaining_fraction -= _Fraction(scalar.value)
resolved[index] = min_value
remaining_space_changed = True
elif max_value is not None and resolved_scalar > max_value:
remaining_space -= max_value
remaining_fraction -= Fraction(scalar.value)
remaining_fraction -= _Fraction(scalar.value)
resolved[index] = max_value
remaining_space_changed = True

Expand Down Expand Up @@ -219,8 +220,16 @@ def resolve_box_models(
else widget._get_box_model(
size,
viewport_size,
max(fraction_zero, fraction_width - margin_width),
max(fraction_zero, fraction_height - margin_height),
(
fraction_zero
if (_width := fraction_width - margin_width) < 0
else _width
),
(
fraction_zero
if (_height := fraction_height - margin_height) < 0
else _height
),
)
)
for (_dimension, widget, (margin_width, margin_height)) in zip(
Expand Down
2 changes: 1 addition & 1 deletion src/textual/demo/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ class WidgetsScreen(PageScreen):
}
"""

BINDINGS = [("escape", "unfocus")]
BINDINGS = [("escape", "unfocus", "Unfocus any focused widget")]

def compose(self) -> ComposeResult:
with containers.VerticalScroll() as container:
Expand Down
21 changes: 14 additions & 7 deletions src/textual/layouts/vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def arrange(
),
sum(
[
max(margin1[2], margin2[0])
for margin1, margin2 in zip(box_margins, box_margins[1:])
bottom if bottom > top else top
for (_, _, bottom, _), (top, _, _, _) in zip(
box_margins, box_margins[1:]
)
]
)
+ (box_margins[0].top + box_margins[-1].bottom),
Expand All @@ -56,9 +58,14 @@ def arrange(
)

margins = [
max((box1.margin.bottom, box2.margin.top))
for box1, box2 in zip(box_models, box_models[1:])
(
margin_bottom
if (margin_bottom := margin1.bottom) > (margin_top := margin2.top)
else margin_top
)
for (_, _, margin1), (_, _, margin2) in zip(box_models, box_models[1:])
]

if box_models:
margins.append(box_models[-1].margin.bottom)

Expand All @@ -82,9 +89,9 @@ def arrange(
_WidgetPlacement(
_Region(
box_margin.left,
int(y),
int(content_width),
int(next_y) - int(y),
y.__int__(),
content_width.__int__(),
next_y.__int__() - y.__int__(),
),
box_margin,
widget,
Expand Down

0 comments on commit 2608413

Please sign in to comment.