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.

reset_origin property

reset_origin

Reset the origin in the placement (moves it to (0, 0)).

apply_absolute classmethod

apply_absolute(placements)

Applies absolute offsets (in place).

Parameters:

Name Type Description Default

placements

list[WidgetPlacement]

A list of placements.

required

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.

process_offset

Apply any absolute offset or constrain rules to the placement.

Parameters:

Name Type Description Default

constrain_region

Region

The container region when applying constrain rules.

required

absolute_offset

Offset

Default absolute offset that moves widget in to screen coordinates.

required

Returns:

Type Description
WidgetPlacement

Processes placement, may be the same instance.

translate classmethod

translate(placements, translate_offset)

Move all non-absolute placements by a given offset.

Parameters:

Name Type Description Default

placements

list[WidgetPlacement]

List of placements.

required

offset

Offset to add to placements.

required

Returns:

Type Description
list[WidgetPlacement]

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