trellis/column

Types

Alignment options for column content

pub type Align {
  Left
  Right
  Center
}

Constructors

  • Left
  • Right
  • Center

A type representing a column in the table with header, alignment, and value getter

pub type Column(value) {
  Column(
    header: String,
    align: Align,
    width: option.Option(Int),
    getter: fn(value) -> String,
  )
}

Constructors

  • Column(
      header: String,
      align: Align,
      width: option.Option(Int),
      getter: fn(value) -> String,
    )

Functions

pub fn align(
  column column: Column(a),
  align align: Align,
) -> Column(a)

Sets the alignment for the column’s content. Content can be aligned left, right, or center.

Example

column.new(header: "Age")
|> column.align(Right)
pub fn new(header header: String) -> Column(a)

Creates a new column with the given header text. The column is initially centered with no width constraint and an empty getter function.

Example

let name_col = column.new(header: "Name")
pub fn render(
  column column: Column(a),
  getter getter: fn(b) -> String,
) -> Column(b)

Sets the function used to extract a string value from a row for this column. The getter function should take a value of the type passed into the table and return a string.

Example

column.new(header: "Name")
|> column.render(fn(user) { user.name })
pub fn wrap(
  column column: Column(a),
  width width: Int,
) -> Column(a)

Sets a maximum width for the column in characters. Content longer than this width will be wrapped automatically. The column will never be smaller than the longest word in its content.

Example

column.new(header: "Description") 
|> column.wrap(width: 40)
Search Document