Skip to content

Commit 9d42784

Browse files
committed
process layout hook
1 parent 98899a0 commit 9d42784

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/textual/_arrange.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ def arrange(
9595

9696
if layout_widgets:
9797
# Arrange layout widgets (i.e. not docked)
98-
layout_placements = widget.layout.arrange(
99-
widget, layout_widgets, dock_region.size, greedy=not optimal
98+
layout_placements = widget.process_layout(
99+
widget.layout.arrange(
100+
widget, layout_widgets, dock_region.size, greedy=not optimal
101+
)
100102
)
101103
scroll_spacing = scroll_spacing.grow_maximum(dock_spacing)
102104
placement_offset = dock_region.offset

src/textual/widget.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
Spacing,
8080
clamp,
8181
)
82-
from textual.layout import Layout
82+
from textual.layout import Layout, WidgetPlacement
8383
from textual.layouts.vertical import VerticalLayout
8484
from textual.message import Message
8585
from textual.messages import CallbackType, Prune
@@ -722,6 +722,22 @@ def _cover(self, widget: Widget) -> None:
722722
self.app.stylesheet.apply(widget)
723723
self.refresh(layout=True)
724724

725+
def process_layout(
726+
self, placements: list[WidgetPlacement]
727+
) -> list[WidgetPlacement]:
728+
"""A hook to allow for the manipulation of widget placements before rendering.
729+
730+
You could use this as a way to modify the positions / margins of widgets if your requirement is
731+
not supported in TCSS. In practice, this method is rarely needed!
732+
733+
Args:
734+
placements: A list of [`WidgetPlacement`][textual.layout.WidgetPlacement] objects.
735+
736+
Returns:
737+
A new list of placements.
738+
"""
739+
return placements
740+
725741
def _uncover(self) -> None:
726742
"""Remove any widget, previously set via [`_cover`][textual.widget.Widget._cover]."""
727743
if self._cover_widget is not None:

0 commit comments

Comments
 (0)