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

Copy Markdown View Source

Pick list -- dropdown selection.

Props

  • options (list of strings) -- the available choices.
  • selected (string | nil) -- the currently selected value.

  • placeholder (string) -- placeholder text when nothing is selected.
  • width (length) -- widget width. Default: shrink. See Toddy.Iced.Length.
  • padding (number | map) -- internal padding. See Toddy.Iced.Padding.

  • text_size (number) -- text size in pixels.
  • font (string | map) -- font specification. See Toddy.Iced.Font.

  • line_height (number | map) -- text line height.

  • menu_height (number) -- maximum height of the dropdown menu in pixels.
  • text_shaping -- text shaping strategy. See Toddy.Iced.Shaping.
  • handle (map) -- customise the dropdown handle indicator. Map with a type key:
    • %{type: "arrow"} -- default arrow (optional size in pixels).
    • %{type: "arrow", size: 12} -- arrow with explicit size.
    • %{type: "static", icon: icon_map} -- fixed icon.
    • %{type: "dynamic", closed: icon_map, open: icon_map} -- state-dependent icons.
    • %{type: "none"} -- no handle. Icon maps: %{code_point: "char", size: n, font: font, spacing: n, line_height: n}.
  • ellipsis (string) -- text ellipsis strategy: "none", "start", "middle", or "end". Default: "end".
  • menu_style (map) -- inline style for the dropdown menu. Map with optional keys: background, text_color, selected_text_color, selected_background, border, shadow.
  • style -- :default or StyleMap.t() for custom styling. See Toddy.Iced.StyleMap.
  • a11y (map) -- accessibility overrides. See Toddy.Iced.A11y.

Events

  • %Widget{type: :select, id: id, value: value} -- emitted when an option is selected.
  • %Widget{type: :open, id: id} -- emitted when the dropdown menu is opened (requires on_open: true).
  • %Widget{type: :close, id: id} -- emitted when the dropdown menu is closed (requires on_close: true).

Summary

Functions

Sets accessibility annotations.

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

Sets the text ellipsis strategy.

Sets the font.

Sets the dropdown handle style.

Sets the text line height.

Sets the maximum dropdown menu height in pixels.

Sets the dropdown menu style overrides.

Creates a new pick list struct with the given options and optional keyword opts.

Enables or disables the close event when the dropdown menu closes.

Enables or disables the open event when the dropdown menu opens.

Sets the internal padding.

Sets the placeholder text.

Sets the currently selected value.

Sets the pick list style. Accepts :default or a StyleMap.

Sets the text shaping strategy.

Sets the text size in pixels.

Sets the pick list width.

Applies keyword options to an existing pick list struct.

Types

option()

@type option() ::
  {:selected, String.t()}
  | {:placeholder, String.t()}
  | {:width, Toddy.Iced.Length.t()}
  | {:padding, Toddy.Iced.Padding.t()}
  | {:text_size, number()}
  | {:font, Toddy.Iced.Font.t()}
  | {:line_height, number() | map()}
  | {:menu_height, number()}
  | {:text_shaping, Toddy.Iced.Shaping.t()}
  | {:handle, map()}
  | {:ellipsis, String.t()}
  | {:menu_style, map()}
  | {:style, style()}
  | {:on_open, boolean()}
  | {:on_close, boolean()}
  | {:a11y, Toddy.Iced.A11y.t()}

style()

@type style() :: :default | Toddy.Iced.StyleMap.t()

t()

@type t() :: %Toddy.Iced.Widget.PickList{
  a11y: Toddy.Iced.A11y.t() | nil,
  ellipsis: String.t() | nil,
  font: Toddy.Iced.Font.t() | nil,
  handle: map() | nil,
  id: String.t(),
  line_height: number() | map() | nil,
  menu_height: number() | nil,
  menu_style: map() | nil,
  on_close: boolean() | nil,
  on_open: boolean() | nil,
  options: [String.t()],
  padding: Toddy.Iced.Padding.t() | nil,
  placeholder: String.t() | nil,
  selected: String.t() | nil,
  style: style() | nil,
  text_shaping: Toddy.Iced.Shaping.t() | nil,
  text_size: number() | nil,
  width: Toddy.Iced.Length.t() | nil
}

Functions

a11y(pl, a11y)

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

Sets accessibility annotations.

build(pl)

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

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

ellipsis(pl, ellipsis)

@spec ellipsis(pick_list :: t(), ellipsis :: String.t()) :: t()

Sets the text ellipsis strategy.

font(pl, font)

@spec font(pick_list :: t(), font :: Toddy.Iced.Font.t()) :: t()

Sets the font.

handle(pl, handle)

@spec handle(pick_list :: t(), handle :: map()) :: t()

Sets the dropdown handle style.

line_height(pl, line_height)

@spec line_height(pick_list :: t(), line_height :: number() | map()) :: t()

Sets the text line height.

new(id, options, opts \\ [])

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

Creates a new pick list struct with the given options and optional keyword opts.

on_close(pl, on_close)

@spec on_close(pick_list :: t(), on_close :: boolean()) :: t()

Enables or disables the close event when the dropdown menu closes.

on_open(pl, on_open)

@spec on_open(pick_list :: t(), on_open :: boolean()) :: t()

Enables or disables the open event when the dropdown menu opens.

padding(pl, padding)

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

Sets the internal padding.

placeholder(pl, placeholder)

@spec placeholder(pick_list :: t(), placeholder :: String.t()) :: t()

Sets the placeholder text.

selected(pl, selected)

@spec selected(pick_list :: t(), selected :: String.t()) :: t()

Sets the currently selected value.

style(pl, style)

@spec style(pick_list :: t(), style :: style()) :: t()

Sets the pick list style. Accepts :default or a StyleMap.

text_shaping(pl, text_shaping)

@spec text_shaping(pick_list :: t(), text_shaping :: Toddy.Iced.Shaping.t()) :: t()

Sets the text shaping strategy.

text_size(pl, text_size)

@spec text_size(pick_list :: t(), text_size :: number()) :: t()

Sets the text size in pixels.

width(pl, width)

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

Sets the pick list width.

with_options(pl, opts)

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

Applies keyword options to an existing pick list struct.