Skip to content

Commit 43485ed

Browse files
authored
Merge pull request #6108 from Textualize/reduce-layout
Made arrange public
2 parents 1f05b1b + 1a29456 commit 43485ed

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Changed
1111

1212
- Eager tasks are now enabled On Python3.12 and above https://github.com/Textualize/textual/pull/6102
13+
- `Widget._arrange` is now public (as `Widget.arrange`) https://github.com/Textualize/textual/pull/6108
14+
- Reduced number of layout operations required to update the screen https://github.com/Textualize/textual/pull/6108
1315

1416
### Added
1517

src/textual/_compositor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def add_widget(
597597

598598
if widget.is_container:
599599
# Arrange the layout
600-
arrange_result = widget._arrange(child_region.size)
600+
arrange_result = widget.arrange(child_region.size)
601601

602602
arranged_widgets = arrange_result.widgets
603603
widgets.update(arranged_widgets)

src/textual/layout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def get_content_width(self, widget: Widget, container: Size, viewport: Size) ->
240240
if not widget._nodes:
241241
width = 0
242242
else:
243-
arrangement = widget._arrange(
243+
arrangement = widget.arrange(
244244
Size(0 if widget.shrink else container.width, 0),
245245
optimal=True,
246246
)
@@ -266,9 +266,9 @@ def get_content_height(
266266
child.styles.is_dynamic_height for child in widget.displayed_children
267267
):
268268
# An exception for containers with all dynamic height widgets
269-
arrangement = widget._arrange(Size(width, container.height))
269+
arrangement = widget.arrange(Size(width, container.height))
270270
else:
271-
arrangement = widget._arrange(Size(width, 0))
271+
arrangement = widget.arrange(Size(width, 0))
272272
height = arrangement.total_region.height
273273
else:
274274
height = 0

src/textual/layouts/stream.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from textual.layout import ArrangeResult, Layout, WidgetPlacement
77

88
if TYPE_CHECKING:
9-
109
from textual.widget import Widget
1110

1211

@@ -110,7 +109,7 @@ def get_content_height(
110109
Content height (in lines).
111110
"""
112111
if widget._nodes:
113-
arrangement = widget._arrange(Size(width, 0))
112+
arrangement = widget.arrange(Size(width, 0))
114113
height = arrangement.total_region.height
115114
else:
116115
height = 0

src/textual/screen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def active_bindings(self) -> dict[str, ActiveBinding]:
468468

469469
return bindings_map
470470

471-
def _arrange(self, size: Size) -> DockArrangeResult:
471+
def arrange(self, size: Size) -> DockArrangeResult:
472472
"""Arrange children.
473473
474474
Args:

src/textual/widget.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def __init__(
460460
self._content_height_cache: tuple[object, int] = (None, 0)
461461

462462
self._arrangement_cache: FIFOCache[
463-
tuple[Size, int, Widget | None], DockArrangeResult
463+
tuple[Size, int, bool], DockArrangeResult
464464
] = FIFOCache(4)
465465

466466
self._styles_cache = StylesCache()
@@ -1264,11 +1264,14 @@ def render_str(self, text_content: str | Content) -> Content:
12641264
return text_content
12651265
return Content.from_markup(text_content)
12661266

1267-
def _arrange(self, size: Size, optimal: bool = False) -> DockArrangeResult:
1268-
"""Arrange children.
1267+
def arrange(self, size: Size, optimal: bool = False) -> DockArrangeResult:
1268+
"""Arrange child widgets.
1269+
1270+
This method is best left along, unless you have a deep understanding of what it does.
12691271
12701272
Args:
12711273
size: Size of container.
1274+
optimal: Whether fr units should expand the widget (`False`) or avoid expanding the widget (`True`).
12721275
12731276
Returns:
12741277
Widget locations.
@@ -4201,6 +4204,8 @@ def refresh(
42014204
if not isinstance(ancestor, Widget):
42024205
break
42034206
ancestor._clear_arrangement_cache()
4207+
if not ancestor.styles.auto_dimensions:
4208+
break
42044209

42054210
if recompose:
42064211
self._recompose_required = True

0 commit comments

Comments
 (0)