Skip to content

Commit

Permalink
micro ops
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Oct 28, 2024
1 parent c083950 commit 56d4efd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
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)

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
1 change: 1 addition & 0 deletions src/textual/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def get_content_height(
Returns:
Content height (in lines).
"""

if not widget._nodes:
height = 0
else:
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 56d4efd

Please sign in to comment.