Skip to Content
defold-typescript libraries
Pause-Gamesflow

Pause-Games/flow/flow.flex

A fluent flexbox Node class for Flow: build nodes, chain style setters and compute their layout.

  • GitHub: Pause-Games/flow — pinned to 1.0.0
    1. Pick a release from Pause-Games/flow releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as flex from "flow.flex"

Functions

calculate_layout(root: Flow_Element, width?: number | undefined, height?: number | undefined): Flow_Element

Run the layout engine on a node tree without creating a Node instance. Convenience function for callers using plain Lua table element trees.

Parameters

  • root: Flow_Element — The root element tree to compute layout for
  • width?: number | undefined — Available width (falls back to numeric root.style.width or 0)
  • height?: number | undefined — Available height (falls back to numeric root.style.height or 0)

Returns

  • Flow_Element — The root element (layout written to root.layout and descendants)

Node.new(opts?: Flow_FlexNodeOptions | undefined): Node

Create a new FlexNode with initial properties. All fields have sensible defaults; only key is typically required.

Parameters

  • opts?: Flow_FlexNodeOptions | undefined — Initial properties

Returns

  • Node — A new node with the given properties

Types

Node

Node.insert_child(child: Flow_FlexNode, index?: number | undefined): Node

Insert a child node at a given index (1-based, default = append). Chainable — returns self.

Parameters

  • child: Flow_FlexNode — The child node to insert
  • index?: number | undefined — 1-based insertion index; default appends after last child. ⚠️ 1-based; passed to flow.flex unchanged.

Returns

  • Node

Node.remove_child(child: Flow_FlexNode): Node

Remove a child node by reference. No-op when child is not found. Chainable — returns self.

Parameters

  • child: Flow_FlexNode — The child node to remove (matched by reference)

Returns

  • Node

Node.get_child(index: number): Flow_FlexNode | undefined

Return the child at a 0-based index (Yoga API convention). Index 0 returns the first child.

Parameters

  • index: number — 0-based child index. 0️⃣ 0-based; passed to flow.flex unchanged.

Returns

  • Flow_FlexNode | undefined — The child at that index, or nil

Node.get_child_count(): number

Return the total number of children.

Returns

  • number — Child count

Node.set_style(key: string, value: unknown): Node

Set an arbitrary style property by key. Chainable.

Parameters

  • key: string — The style field name (e.g. "flex_direction")
  • value: unknown — The value to assign

Returns

  • Node

Node.get_style(key: string): unknown

Read an arbitrary style property by key.

Parameters

  • key: string — The style field name

Returns

  • unknown — The current value, or nil if not set

Node.set_width(value: number): Node

Set the fixed width in pixels. Chainable.

Parameters

  • value: number — Width in pixels

Returns

  • Node

Node.set_height(value: number): Node

Set the fixed height in pixels. Chainable.

Parameters

  • value: number — Height in pixels

Returns

  • Node

Node.set_width_percent(value: number): Node

Set the width as a percentage of the parent's width. Chainable.

Parameters

  • value: number — Width percentage (0..100)

Returns

  • Node

Node.set_height_percent(value: number): Node

Set the height as a percentage of the parent's height. Chainable.

Parameters

  • value: number — Height percentage (0..100)

Returns

  • Node

Node.set_min_width(value: number): Node

Store a minimum width constraint in pixels. Chainable. Kept for API compatibility; the current layout engine does not enforce it.

Parameters

  • value: number — Minimum width in pixels

Returns

  • Node

Node.set_min_height(value: number): Node

Store a minimum height constraint in pixels. Chainable. Kept for API compatibility; the current layout engine does not enforce it.

Parameters

  • value: number — Minimum height in pixels

Returns

  • Node

Node.set_max_width(value: number): Node

Store a maximum width constraint in pixels. Chainable. Kept for API compatibility; the current layout engine does not enforce it.

Parameters

  • value: number — Maximum width in pixels

Returns

  • Node

Node.set_max_height(value: number): Node

Store a maximum height constraint in pixels. Chainable. Kept for API compatibility; the current layout engine does not enforce it.

Parameters

  • value: number — Maximum height in pixels

Returns

  • Node

Node.set_flex_direction(value: "column" | "row"): Node

Set the main-axis direction for children. Chainable.

Parameters

  • value: "column" | "row" — Use FLEX_DIRECTION_* constants

Returns

  • Node

Node.set_flex_grow(value: number): Node

Set how much this node grows to fill available space on the main axis. Chainable.

Parameters

  • value: number — Growth factor (0 = no growth, 1 = equal share, >1 = larger share)

Returns

  • Node

Node.set_flex_shrink(value: number): Node

Store the flex shrink factor. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • value: number — Shrink factor (default 1; 0 = do not shrink)

Returns

  • Node

Node.set_flex_basis(value: number | string): Node

Store the flex basis value. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • value: number | string — Size in pixels or percentage string

Returns

  • Node

Node.set_justify_content(value: string): Node

Set how children are distributed along the main axis. Chainable.

Parameters

  • value: string — Use JUSTIFY_* constants

Returns

  • Node

Node.set_align_items(value: string): Node

Set how children are aligned on the cross axis. Chainable.

Parameters

  • value: string — Use ALIGN_* constants

Returns

  • Node

Node.set_align_self(value: string): Node

Override the parent's align_items for this node only. Chainable.

Parameters

  • value: string — Use ALIGN_* constants

Returns

  • Node

Node.set_gap(value: number): Node

Set the gap between children in pixels. Chainable.

Parameters

  • value: number — Gap size in pixels

Returns

  • Node

Node.set_padding(edge: string, value: number): Node

Set padding on one or more edges. Chainable.

Parameters

  • edge: string — Use EDGE_* constants (EDGE_ALL sets uniform padding)
  • value: number — Padding in pixels

Returns

  • Node

Node.set_padding_percent(edge: string, value: number): Node

Set padding on one or more edges as a percentage of parent size. Chainable.

Parameters

  • edge: string — Use EDGE_* constants
  • value: number — Padding as percentage (0..100)

Returns

  • Node

Node.set_margin(edge: string, value: number): Node

Store margin on one or more edges in pixels. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • edge: string — Use EDGE_* constants
  • value: number — Margin in pixels

Returns

  • Node

Node.set_margin_percent(edge: string, value: number): Node

Store margin on one or more edges as a percentage of parent size. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • edge: string — Use EDGE_* constants
  • value: number — Margin as percentage (0..100)

Returns

  • Node

Node.set_border(edge: string, value: number): Node

Store border width on one or more edges in pixels. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • edge: string — Use EDGE_* constants
  • value: number — Border width in pixels

Returns

  • Node

Node.set_position(edge: string, value: number): Node

Store position offsets on one or more edges in pixels. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • edge: string — Use EDGE_* constants
  • value: number — Position offset in pixels

Returns

  • Node

Node.set_position_type(value: string): Node

Store the position type (static / relative / absolute). Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • value: string — Use POSITION_TYPE_* constants

Returns

  • Node

Node.set_flex_wrap(value: string): Node

Store the flex wrap behavior. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • value: string — Use WRAP_* constants

Returns

  • Node

Node.set_overflow(value: string): Node

Store the overflow behavior. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • value: string — Use OVERFLOW_* constants

Returns

  • Node

Node.set_display(value: string): Node

Store the display mode. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • value: string — Use DISPLAY_FLEX or DISPLAY_NONE

Returns

  • Node

Node.set_aspect_ratio(value: number): Node

Store the aspect ratio (width / height). Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • value: number — Desired width-to-height ratio (e.g. 16/9)

Returns

  • Node

Node.set_direction(value: string): Node

Store the text direction for this subtree. Chainable. Kept for API compatibility; the current layout engine does not consume it.

Parameters

  • value: string — Use DIRECTION_* constants

Returns

  • Node

Node.set_measure_func(fn: (...args: any[]) => unknown): Node

Attach a custom measure function to this node. The measure function is called by the layout engine to determine intrinsic content size (e.g. for text or image elements). Not used by the default flow/layout.lua but reserved for compatibility with future extensions.

Parameters

  • fn: (...args: any[]) => unknown — Returns measured width and height

Returns

  • Node

Node.calculate_layout(width?: number | undefined, height?: number | undefined): Node

Run the layout engine on this node tree and store results in node.layout. After calling this, use get_computed_* or get_layout() to read the results.

Parameters

  • width?: number | undefined — Available width in pixels (falls back to numeric style.width or 0)
  • height?: number | undefined — Available height in pixels (falls back to numeric style.height or 0)

Returns

  • Node — (for chaining or immediate result reading)

Node.get_layout(): Flow_LayoutRect | undefined

Return the full layout result table ({x, y, w, h}) after calculate_layout().

Returns

  • Flow_LayoutRect | undefined — The computed layout, or nil if not yet calculated

Node.get_computed_left(): number

Return the computed left edge (x) of this node in layout space.

Returns

  • number — The x coordinate, or 0 if layout has not been computed

Node.get_computed_top(): number

Return the computed top edge (y + h) of this node in layout space. Note: layout uses bottom-left origin, so "top" = y + height.

Returns

  • number — The top coordinate, or 0 if layout has not been computed

Node.get_computed_width(): number

Return the computed width of this node in pixels.

Returns

  • number — Width in pixels, or 0 if layout has not been computed

Node.get_computed_height(): number

Return the computed height of this node in pixels.

Returns

  • number — Height in pixels, or 0 if layout has not been computed

On this page

Functionscalculate_layout(root: Flow_Element, width?: number | undefined, height?: number | undefined): Flow_ElementNode.new(opts?: Flow_FlexNodeOptions | undefined): NodeTypesNodeNode.insert_child(child: Flow_FlexNode, index?: number | undefined): NodeNode.remove_child(child: Flow_FlexNode): NodeNode.get_child(index: number): Flow_FlexNode | undefinedNode.get_child_count(): numberNode.set_style(key: string, value: unknown): NodeNode.get_style(key: string): unknownNode.set_width(value: number): NodeNode.set_height(value: number): NodeNode.set_width_percent(value: number): NodeNode.set_height_percent(value: number): NodeNode.set_min_width(value: number): NodeNode.set_min_height(value: number): NodeNode.set_max_width(value: number): NodeNode.set_max_height(value: number): NodeNode.set_flex_direction(value: "column" | "row"): NodeNode.set_flex_grow(value: number): NodeNode.set_flex_shrink(value: number): NodeNode.set_flex_basis(value: number | string): NodeNode.set_justify_content(value: string): NodeNode.set_align_items(value: string): NodeNode.set_align_self(value: string): NodeNode.set_gap(value: number): NodeNode.set_padding(edge: string, value: number): NodeNode.set_padding_percent(edge: string, value: number): NodeNode.set_margin(edge: string, value: number): NodeNode.set_margin_percent(edge: string, value: number): NodeNode.set_border(edge: string, value: number): NodeNode.set_position(edge: string, value: number): NodeNode.set_position_type(value: string): NodeNode.set_flex_wrap(value: string): NodeNode.set_overflow(value: string): NodeNode.set_display(value: string): NodeNode.set_aspect_ratio(value: number): NodeNode.set_direction(value: string): NodeNode.set_measure_func(fn: (...args: any[]) => unknown): NodeNode.calculate_layout(width?: number | undefined, height?: number | undefined): NodeNode.get_layout(): Flow_LayoutRect | undefinedNode.get_computed_left(): numberNode.get_computed_top(): numberNode.get_computed_width(): numberNode.get_computed_height(): number