Toddy.Iced.Widget.Table (Toddy v0.3.0)

Copy Markdown View Source

Data table -- composite widget built from columns, rows, and scrollable containers.

Props

  • columns (list of maps) -- column definitions. Each column is %{key: string, label: string}. The key maps to row data fields. Optional per-column fields:
    • align -- horizontal alignment for the column cells ("left", "center", "right"). Default: "left".
    • width -- column width as a Toddy.Iced.Length value. Default: :fill.
    • sortable -- whether clicking the header triggers a sort event. Default: false.
  • rows (list of maps) -- data rows. Each row is a map where keys correspond to column key values.
  • header (boolean) -- show header row. Default: true.
  • separator (boolean) -- show separator line below header. Default: true.
  • width (length) -- table width. Default: fill. See Toddy.Iced.Length.
  • padding (number | map) -- table padding. See Toddy.Iced.Padding.

  • sort_by (string | nil) -- key of the currently sorted column.

  • sort_order (:asc | :desc | nil) -- current sort direction.

  • header_text_size (number) -- header row text size in pixels.
  • row_text_size (number) -- body row text size in pixels.
  • cell_spacing (number) -- horizontal spacing between cells in pixels.
  • row_spacing (number) -- vertical spacing between rows in pixels.
  • separator_thickness (number) -- separator line thickness in pixels.
  • separator_color (color) -- separator line color. See Toddy.Iced.Color.
  • a11y (map) -- accessibility overrides. See Toddy.Iced.A11y.

Summary

Functions

Sets accessibility annotations.

Converts this table struct to a ui_node() map via the Toddy.Iced.Widget protocol.

Sets the horizontal spacing between cells in pixels.

Sets the column definitions.

Sets whether the header row is shown.

Sets the header text size in pixels.

Creates a new table struct with optional keyword opts.

Sets the table padding.

Sets the vertical spacing between rows in pixels.

Sets the row text size in pixels.

Sets the data rows.

Sets whether the separator line is shown.

Sets the separator line color.

Sets the separator line thickness in pixels.

Sets the currently sorted column key.

Sets the current sort direction.

Sets the table width.

Applies keyword options to an existing table struct.

Types

option()

@type option() ::
  {:columns, [map()]}
  | {:rows, [map()]}
  | {:header, boolean()}
  | {:separator, boolean()}
  | {:width, Toddy.Iced.Length.t()}
  | {:padding, Toddy.Iced.Padding.t()}
  | {:sort_by, String.t()}
  | {:sort_order, sort_order()}
  | {:header_text_size, number()}
  | {:row_text_size, number()}
  | {:cell_spacing, number()}
  | {:row_spacing, number()}
  | {:separator_thickness, number()}
  | {:separator_color, Toddy.Iced.Color.input()}
  | {:a11y, Toddy.Iced.A11y.t()}

sort_order()

@type sort_order() :: :desc | :asc

t()

@type t() :: %Toddy.Iced.Widget.Table{
  a11y: Toddy.Iced.A11y.t() | nil,
  cell_spacing: number() | nil,
  columns: [map()] | nil,
  header: boolean() | nil,
  header_text_size: number() | nil,
  id: String.t(),
  padding: Toddy.Iced.Padding.t() | nil,
  row_spacing: number() | nil,
  row_text_size: number() | nil,
  rows: [map()] | nil,
  separator: boolean() | nil,
  separator_color: Toddy.Iced.Color.t() | nil,
  separator_thickness: number() | nil,
  sort_by: String.t() | nil,
  sort_order: sort_order() | nil,
  width: Toddy.Iced.Length.t() | nil
}

Functions

a11y(tbl, a11y)

@spec a11y(table :: t(), a11y :: Toddy.Iced.A11y.t()) :: t()

Sets accessibility annotations.

build(tbl)

@spec build(table :: t()) :: Toddy.Iced.ui_node()

Converts this table struct to a ui_node() map via the Toddy.Iced.Widget protocol.

cell_spacing(tbl, cell_spacing)

@spec cell_spacing(table :: t(), cell_spacing :: number()) :: t()

Sets the horizontal spacing between cells in pixels.

columns(tbl, columns)

@spec columns(table :: t(), columns :: [map()]) :: t()

Sets the column definitions.

header(tbl, header)

@spec header(table :: t(), header :: boolean()) :: t()

Sets whether the header row is shown.

header_text_size(tbl, header_text_size)

@spec header_text_size(table :: t(), header_text_size :: number()) :: t()

Sets the header text size in pixels.

new(id, opts \\ [])

@spec new(id :: String.t(), opts :: [option()]) :: t()

Creates a new table struct with optional keyword opts.

padding(tbl, padding)

@spec padding(table :: t(), padding :: Toddy.Iced.Padding.t()) :: t()

Sets the table padding.

row_spacing(tbl, row_spacing)

@spec row_spacing(table :: t(), row_spacing :: number()) :: t()

Sets the vertical spacing between rows in pixels.

row_text_size(tbl, row_text_size)

@spec row_text_size(table :: t(), row_text_size :: number()) :: t()

Sets the row text size in pixels.

rows(tbl, rows)

@spec rows(table :: t(), rows :: [map()]) :: t()

Sets the data rows.

separator(tbl, separator)

@spec separator(table :: t(), separator :: boolean()) :: t()

Sets whether the separator line is shown.

separator_color(tbl, separator_color)

@spec separator_color(table :: t(), separator_color :: Toddy.Iced.Color.input()) ::
  t()

Sets the separator line color.

separator_thickness(tbl, separator_thickness)

@spec separator_thickness(table :: t(), separator_thickness :: number()) :: t()

Sets the separator line thickness in pixels.

sort_by(tbl, sort_by)

@spec sort_by(table :: t(), sort_by :: String.t()) :: t()

Sets the currently sorted column key.

sort_order(tbl, sort_order)

@spec sort_order(table :: t(), sort_order :: sort_order()) :: t()

Sets the current sort direction.

width(tbl, width)

@spec width(table :: t(), width :: Toddy.Iced.Length.t()) :: t()

Sets the table width.

with_options(tbl, opts)

@spec with_options(table :: t(), opts :: [option()]) :: t()

Applies keyword options to an existing table struct.