Raxol.UI.Layout.Grid (Raxol v2.0.1)

View Source

Grid layout utility functions.

Summary

Functions

Creates grid cell information for a grid layout.

Calculates spacing between grid cells based on gap value.

Calculates the position for a cell in the grid.

Measures the space needed by a grid element.

Creates a new grid layout with the given options.

Processes a grid element, calculating layout for it and its children.

Renders the grid layout.

Functions

calculate_grid_cells(grid_attrs, space)

Creates grid cell information for a grid layout.

Parameters

  • grid_attrs - The grid attributes
  • space - The available space

Returns

A map containing cell dimensions and grid information.

calculate_spacing(grid)

@spec calculate_spacing(map()) :: {:ok, map()}

Calculates spacing between grid cells based on gap value.

Returns a map with calculated spacing values.

cell_position(col, row, grid_cells, space)

Calculates the position for a cell in the grid.

Parameters

  • col - The column index (0-based)
  • row - The row index (0-based)
  • grid_cells - The grid cell information from calculate_grid_cells/2
  • space - The base space for the grid

Returns

A space map with x, y, width, and height for the cell.

measure_grid(map, available_space)

Measures the space needed by a grid element.

Parameters

  • grid - The grid element to measure
  • available_space - The available space for the grid

Returns

The dimensions of the grid: %{width: w, height: h}

new(opts \\ [])

@spec new(keyword()) :: map()

Creates a new grid layout with the given options.

Options

  • :columns - number of columns
  • :rows - number of rows
  • :gap - gap between cells
  • :children - child elements
  • :width - grid width
  • :height - grid height

process(arg1, space, acc)

Processes a grid element, calculating layout for it and its children.

Parameters

  • grid - The grid element to process
  • space - The available space for the grid
  • acc - The accumulator for rendered elements

Returns

A list of positioned elements with absolute coordinates.

render(grid)

@spec render(map()) :: {:ok, map()}

Renders the grid layout.

Returns the layout with calculated positions for all children.