Raxol.Core.Renderer.Layout (Raxol v2.0.1)

View Source

Central layout coordinator for the Raxol renderer system.

This module provides a unified interface for layout calculations and delegates to specific layout modules (Flex, Grid, etc.) based on the layout type.

Summary

Functions

Applies layout to a view or list of views, calculating absolute positions.

Creates a column layout container.

Creates a flex layout container.

Creates a grid layout container.

Calculates layout for a box container.

Calculates layout for a button element.

Calculates layout for a checkbox element.

Calculates layout for a label element.

Calculates the layout for a single view based on its type.

Calculates layout for a text element.

Creates a row layout container.

Functions

apply_layout(view, dimensions)

Applies layout to a view or list of views, calculating absolute positions.

Parameters

  • view - A single view or list of views to layout
  • dimensions - Available space dimensions %{width: w, height: h}

Returns

A list of positioned elements with absolute coordinates.

column(opts \\ [])

Creates a column layout container.

Options

  • :align - Alignment of children (:start, :center, :end)
  • :justify - Justification of children (:start, :center, :end, :space_between)
  • :gap - Space between children (integer)
  • :children - List of child views
  • :style - Style options for the container

Examples

Layout.column(children: [view1, view2])
Layout.column(align: :center, justify: :space_between, children: [view1, view2])

flex(opts \\ [])

Creates a flex layout container.

Options

  • :direction - Layout direction (:row or :column)
  • :align - Alignment of children (:start, :center, :end)
  • :justify - Justification of children (:start, :center, :end, :space_between)
  • :gap - Space between children (integer)
  • :wrap - Whether to wrap children (boolean)
  • :children - List of child views
  • :style - Style options for the container

Examples

Layout.flex(direction: :row, children: [view1, view2])
Layout.flex(direction: :column, align: :center, children: [view1, view2])

grid(opts \\ [])

Creates a grid layout container.

Options

  • :columns - Number of columns or list of column sizes
  • :rows - Number of rows or list of row sizes
  • :gap - Gap between grid items {x, y}
  • :align - Alignment of items within grid cells
  • :justify - Justification of items within grid cells
  • :children - List of child views to place in the grid

Examples

Layout.grid(columns: 3, rows: 2, children: [view1, view2, view3, view4])
Layout.grid(columns: [1, 2, 1], rows: ["auto", "1fr"], children: [view1, view2, view3])

layout_box(box, arg)

Calculates layout for a box container.

layout_button(button, arg)

Calculates layout for a button element.

layout_checkbox(checkbox, arg)

Calculates layout for a checkbox element.

layout_label(label, arg)

Calculates layout for a label element.

layout_single_view(view, available_space)

Calculates the layout for a single view based on its type.

layout_text(text, arg)

Calculates layout for a text element.

row(opts \\ [])

Creates a row layout container.

Options

  • :align - Alignment of children (:start, :center, :end)
  • :justify - Justification of children (:start, :center, :end, :space_between)
  • :gap - Space between children (integer)
  • :children - List of child views
  • :style - Style options for the container

Examples

Layout.row(children: [view1, view2])
Layout.row(align: :center, justify: :space_between, children: [view1, view2])