# Text Layout Classes

class urwid.TextLayout
  layout(text: str | bytes, width: int, align: Literal['left', 'center', 'right'] | Align, wrap: Literal['any', 'space', 'clip', 'ellipsis'] | WrapMode) → list[list[tuple[int, int, int | bytes] | tuple[int, int | None]]]

    Return a layout structure for text.

    Parameters:

      - text – string in current encoding or unicode string

      - width – number of screen columns available

      - align – align mode for text

      - wrap – wrap mode for text

    Layout structure is a list of line layouts, one per output line. Line layouts are lists than may contain the following tuples:

    - (column width of text segment, start offset, end offset)

    - (number of space characters to insert, offset or None)

    - (column width of insert text, offset, “insert text”)

    The offset in the last two tuples is used to determine the attribute used for the inserted spaces or text respectively. The attribute used will be the same as the attribute at that text offset. If the offset is None when inserting spaces then no attribute will be used.

  supports_align_mode(align: Literal['left', 'center', 'right'] | Align) → bool

    Return True if align is a supported align mode.

  supports_wrap_mode(wrap: Literal['any', 'space', 'clip', 'ellipsis'] | WrapMode) → bool

    Return True if wrap is a supported wrap mode.

class urwid.StandardTextLayout
  align_layout(text: str | bytes, width: int, segs: list[list[tuple[int, int, int | bytes] | tuple[int, int | None]]], wrap: Literal['any', 'space', 'clip', 'ellipsis'] | WrapMode, align: Literal['left', 'center', 'right'] | Align) → list[list[tuple[int, int, int | bytes] | tuple[int, int | None]]]

    Convert the layout segments to an aligned layout.

  calculate_text_segments(text: str | bytes, width: int, wrap: Literal['any', 'space', 'clip', 'ellipsis'] | WrapMode) → list[list[tuple[int, int, int | bytes] | tuple[int, int | None]]]

    Calculate the segments of text to display given width screen columns to display them.

    text - unicode text or byte string to display width - number of available screen columns wrap - wrapping mode used

    Returns a layout structure without an alignment applied.

  layout(text: str | bytes, width: int, align: Literal['left', 'center', 'right'] | Align, wrap: Literal['any', 'space', 'clip', 'ellipsis'] | WrapMode) → list[list[tuple[int, int, int | bytes] | tuple[int, int | None]]]

    Return a layout structure for text.

  pack(maxcol: int, layout: list[list[tuple[int, int, int | bytes] | tuple[int, int | None]]]) → int

    Return a minimal maxcol value that would result in the same number of lines for layout.

    layout must be a layout structure returned by self.layout().

  supports_align_mode(align: Literal['left', 'center', 'right'] | Align) → bool

    Return True if align is ‘left’, ‘center’ or ‘right’.

  supports_wrap_mode(wrap: Literal['any', 'space', 'clip', 'ellipsis'] | WrapMode) → bool

    Return True if wrap is ‘any’, ‘space’, ‘clip’ or ‘ellipsis’.