Skip to content

textual.layout

DockArrangeResult dataclass

DockArrangeResult(
    placements, widgets, scroll_spacing, _spatial_map=None
)

Result of Layout.arrange.

placements instance-attribute

placements

A WidgetPlacement for every widget to describe its location on screen.

scroll_spacing instance-attribute

scroll_spacing

Spacing to reduce scrollable area.

spatial_map property

spatial_map

A lazy-calculated spatial map.

total_region property

total_region

The total area occupied by the arrangement.

Returns:

Type Description
Region

A Region.

widgets instance-attribute

widgets

A set of widgets in the arrangement.

get_visible_placements

get_visible_placements(region)

Get the placements visible within the given region.

Parameters:

Name Type Description Default

region

Region

A region.

required

Returns:

Type Description
list[WidgetPlacement]

Set of placements.

Layout

Bases: ABC

Base class of the object responsible for arranging Widgets within a container.

arrange abstractmethod

arrange(parent, children, size)

Generate a layout map that defines where on the screen the widgets will be drawn.

Parameters:

Name Type Description Default

parent

Widget

Parent widget.

required

size

Size

Size of container.

required

Returns:

Type Description
ArrangeResult

An iterable of widget location

render_keyline

render_keyline(container)

Render keylines around all widgets.

Parameters:

Name Type Description Default

container

Widget

The container widget.

required

Returns:

Type Description
StripRenderable

A renderable to draw the keylines.

WidgetPlacement

Bases: NamedTuple

The position, size, and relative order of a widget within its parent.

get_bounds classmethod

get_bounds(placements)

Get a bounding region around all placements.

Parameters:

Name Type Description Default

placements

Iterable[WidgetPlacement]

A number of placements.

required

Returns:

Type Description
Region

An optimal binding box around all placements.

translate classmethod

translate(placements, offset)

Move all placements by a given offset.

Parameters:

Name Type Description Default

placements

list[WidgetPlacement]

List of placements.

required

offset

Offset

Offset to add to placements.

required

Returns:

Type Description
list[WidgetPlacement]

Placements with adjusted region, or same instance if offset is null.