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

Copy Markdown View Source

Rich text display with individually styled spans.

Props

  • spans (list of maps) -- list of span descriptors. Each span is a map with:
    • text (string) -- the text content.
    • size (number) -- font size in pixels.
    • color (color) -- text color. See Toddy.Iced.Color.
    • font (string | map) -- font specification. See Toddy.Iced.Font.

    • link (string) -- makes this span a clickable link.
    • underline (boolean) -- renders the span with an underline.
    • strikethrough (boolean) -- renders the span with a strikethrough line.
    • line_height (number) -- relative line height for this span.
    • padding (number | map) -- padding around the span. A number applies uniformly; a map with top, right, bottom, left keys sets per-side.

    • highlight (map) -- visual highlight behind the span text. Accepts:
      • background (color) -- background color. See Toddy.Iced.Color.
      • border (map) -- border around the highlight. Accepts color (color), width (number), and radius (number or list of 4 numbers).
  • width (length) -- widget width. Default: shrink. See Toddy.Iced.Length.
  • height (length) -- widget height. Default: shrink.
  • size (number) -- default font size for all spans.
  • font (string | map) -- default font for all spans.

  • color (color) -- default text color for all spans.
  • line_height (number | map) -- line height.

  • wrapping -- text wrapping mode. See Toddy.Iced.Wrapping.
  • ellipsis (string) -- text ellipsis mode: "none", "start", "middle", "end". Truncates text that overflows and inserts an ellipsis character at the given position.
  • a11y (map) -- accessibility overrides. See Toddy.Iced.A11y.

Events

  • %Widget{type: :click, id: "id:link_value"} -- emitted when a span link is clicked.

Summary

Functions

Sets accessibility annotations.

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

Sets the default text color for all spans.

Sets the text ellipsis mode. One of: "none", "start", "middle", "end".

Sets the default font for all spans.

Sets the widget height.

Sets the line height.

Creates a new rich text struct with optional keyword opts.

Sets the default font size for all spans.

Sets the list of span descriptors.

Sets the widget width.

Applies keyword options to an existing rich text struct.

Sets the text wrapping mode.

Types

option()

@type option() ::
  {:spans, [map()]}
  | {:width, Toddy.Iced.Length.t()}
  | {:height, Toddy.Iced.Length.t()}
  | {:size, number()}
  | {:font, Toddy.Iced.Font.t()}
  | {:color, Toddy.Iced.Color.input()}
  | {:line_height, number() | map()}
  | {:wrapping, Toddy.Iced.Wrapping.t()}
  | {:ellipsis, String.t()}
  | {:a11y, Toddy.Iced.A11y.t()}

t()

@type t() :: %Toddy.Iced.Widget.RichText{
  a11y: Toddy.Iced.A11y.t() | nil,
  color: Toddy.Iced.Color.t() | nil,
  ellipsis: String.t() | nil,
  font: Toddy.Iced.Font.t() | nil,
  height: Toddy.Iced.Length.t() | nil,
  id: String.t(),
  line_height: number() | map() | nil,
  size: number() | nil,
  spans: [map()] | nil,
  width: Toddy.Iced.Length.t() | nil,
  wrapping: Toddy.Iced.Wrapping.t() | nil
}

Functions

a11y(rt, a11y)

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

Sets accessibility annotations.

build(rt)

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

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

color(rt, color)

@spec color(rich_text :: t(), color :: Toddy.Iced.Color.input()) :: t()

Sets the default text color for all spans.

ellipsis(rt, ellipsis)

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

Sets the text ellipsis mode. One of: "none", "start", "middle", "end".

font(rt, font)

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

Sets the default font for all spans.

height(rt, height)

@spec height(rich_text :: t(), height :: Toddy.Iced.Length.t()) :: t()

Sets the widget height.

line_height(rt, line_height)

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

Sets the line height.

new(id, opts \\ [])

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

Creates a new rich text struct with optional keyword opts.

size(rt, size)

@spec size(rich_text :: t(), size :: number()) :: t()

Sets the default font size for all spans.

spans(rt, spans)

@spec spans(rich_text :: t(), spans :: [map()]) :: t()

Sets the list of span descriptors.

width(rt, width)

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

Sets the widget width.

with_options(rt, opts)

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

Applies keyword options to an existing rich text struct.

wrapping(rt, wrapping)

@spec wrapping(rich_text :: t(), wrapping :: Toddy.Iced.Wrapping.t()) :: t()

Sets the text wrapping mode.