wijjit.layout.engine.LayoutNode

class wijjit.layout.engine.LayoutNode(width='auto', height='auto', id=None)[source]

Base class for layout tree nodes.

A layout node can be either a container (with children) or a leaf (wrapping an Element).

Parameters:
  • width (int, str, or Size, optional) – Width specification (default: “auto”)

  • height (int, str, or Size, optional) – Height specification (default: “auto”)

  • id (str, optional) – Node identifier

Variables:
  • width_spec (Size) – Width specification

  • height_spec (Size) – Height specification

  • id (str or None) – Node identifier

  • constraints (SizeConstraints or None) – Calculated size constraints

  • bounds (Bounds or None) – Assigned position and size

__init__(width='auto', height='auto', id=None)[source]
Parameters:
Return type:

None

Methods

__init__([width, height, id])

assign_bounds(x, y, width, height)

Assign absolute position and size (top-down pass).

calculate_constraints()

Calculate size constraints (bottom-up pass).

collect_elements()

Collect all Element objects in this subtree.

get_height_for_width(width)

Return the height this node needs when laid out at width.

abstractmethod calculate_constraints()[source]

Calculate size constraints (bottom-up pass).

Returns:

Calculated constraints

Return type:

SizeConstraints

abstractmethod assign_bounds(x, y, width, height)[source]

Assign absolute position and size (top-down pass).

Parameters:
  • x (int) – X position

  • y (int) – Y position

  • width (int) – Assigned width

  • height (int) – Assigned height

Return type:

None

get_height_for_width(width)[source]

Return the height this node needs when laid out at width.

The bottom-up constraint pass has to guess a height before any width is known, which is wrong for anything whose height depends on its width. Wrapped text is the case that bites: a long line measures as one row, is allocated one row, and paints its continuation lines over whichever sibling was laid out beneath it. Containers call this on the way down, once a child’s width is settled, to correct the guess.

Parameters:

width (int) – The width this node will be laid out at.

Returns:

Required height. The default reports the constraint-pass value, which is correct for every node whose height is width-independent.

Return type:

int

abstractmethod collect_elements()[source]

Collect all Element objects in this subtree.

Returns:

All elements in the subtree

Return type:

list of Element