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

micro ops #5186

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
21 changes: 15 additions & 6 deletions src/textual/_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ def resolve_fraction_unit(
Returns:
The value of 1fr.
"""
F = Fraction
if not remaining_space or not widget_styles:
return Fraction(1)
return F(1)
darrenburns marked this conversation as resolved.
Show resolved Hide resolved

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 = F(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 -= F(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 -= F(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
Loading