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

Copy Markdown View Source

Text editor -- multi-line editable text area.

The renderer manages an internal text_editor::Content cache keyed by node ID. The content prop seeds the initial content.

Props

  • content (string) -- initial text content (used to seed the editor cache).
  • placeholder (string) -- placeholder text shown when editor is empty.
  • width (number) -- editor width in pixels (note: takes pixels, not length).
  • height (length) -- editor height. Default: shrink. See Toddy.Iced.Length.
  • min_height (number) -- minimum height in pixels.
  • max_height (number) -- maximum height in pixels.
  • font (string | map) -- font specification. See Toddy.Iced.Font.

  • size (number) -- font size in pixels.
  • line_height (number | map) -- line height.

  • padding (number) -- uniform padding in pixels.
  • wrapping -- text wrapping mode. See Toddy.Iced.Wrapping.
  • ime_purpose (string) -- IME input purpose hint: "normal", "secure", "terminal". Default: "normal".
  • highlight_syntax (string) -- language extension for syntax highlighting (e.g. "rs", "py", "ex").
  • highlight_theme (string) -- highlighter theme. One of "solarized_dark", "base16_mocha", "base16_ocean", "base16_eighties", "inspired_github". Defaults to "solarized_dark".
  • style -- :default or StyleMap.t() for custom styling. See Toddy.Iced.StyleMap.
  • key_bindings (list of maps) -- declarative key binding rules for the editor. Each rule is a map with optional key (character), named (named key string), modifiers (list of modifier strings), and binding (the action to take). See key_bindings/2 for details.
  • placeholder_color (color) -- placeholder text color. See Toddy.Iced.Color.
  • selection_color (color) -- text selection highlight color. See Toddy.Iced.Color.
  • a11y (map) -- accessibility overrides. See Toddy.Iced.A11y.

Events

The editor emits text action events handled internally by the renderer. Content changes are reported back to Elixir via the protocol.

Summary

Functions

Sets accessibility annotations.

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

Sets the initial text content.

Sets the font.

Sets the editor height.

Sets the syntax language for highlighting (e.g. "rs", "py", "ex").

Sets the highlighter color theme.

Sets the IME input purpose hint.

Sets declarative key binding rules for the editor.

Sets the line height.

Sets the maximum height in pixels.

Sets the minimum height in pixels.

Creates a new text editor struct with the given id and optional keyword opts.

Sets the uniform padding in pixels.

Sets the placeholder text.

Sets the placeholder text color. Accepts any form Color.cast/1 supports.

Sets the text selection highlight color. Accepts any form Color.cast/1 supports.

Sets the font size in pixels.

Sets the text editor style.

Sets the editor width in pixels.

Applies keyword options to an existing text editor struct.

Sets the text wrapping mode.

Types

option()

@type option() ::
  {:content, String.t()}
  | {:placeholder, String.t()}
  | {:width, number()}
  | {:height, Toddy.Iced.Length.t()}
  | {:min_height, number()}
  | {:max_height, number()}
  | {:font, Toddy.Iced.Font.t()}
  | {:size, number()}
  | {:line_height, number() | map()}
  | {:padding, number()}
  | {:wrapping, Toddy.Iced.Wrapping.t()}
  | {:ime_purpose, String.t()}
  | {:highlight_syntax, String.t()}
  | {:highlight_theme, String.t()}
  | {:style, style()}
  | {:key_bindings, [map()]}
  | {:placeholder_color, Toddy.Iced.Color.input()}
  | {:selection_color, Toddy.Iced.Color.input()}
  | {:a11y, Toddy.Iced.A11y.t()}

style()

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

t()

@type t() :: %Toddy.Iced.Widget.TextEditor{
  a11y: Toddy.Iced.A11y.t() | nil,
  content: String.t() | nil,
  font: Toddy.Iced.Font.t() | nil,
  height: Toddy.Iced.Length.t() | nil,
  highlight_syntax: String.t() | nil,
  highlight_theme: String.t() | nil,
  id: String.t(),
  ime_purpose: String.t() | nil,
  key_bindings: [map()] | nil,
  line_height: number() | map() | nil,
  max_height: number() | nil,
  min_height: number() | nil,
  padding: number() | nil,
  placeholder: String.t() | nil,
  placeholder_color: Toddy.Iced.Color.t() | nil,
  selection_color: Toddy.Iced.Color.t() | nil,
  size: number() | nil,
  style: style() | nil,
  width: number() | nil,
  wrapping: Toddy.Iced.Wrapping.t() | nil
}

Functions

a11y(ed, a11y)

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

Sets accessibility annotations.

build(ed)

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

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

content(ed, content)

@spec content(text_editor :: t(), content :: String.t()) :: t()

Sets the initial text content.

font(ed, font)

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

Sets the font.

height(ed, height)

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

Sets the editor height.

highlight_syntax(ed, highlight_syntax)

@spec highlight_syntax(text_editor :: t(), highlight_syntax :: String.t()) :: t()

Sets the syntax language for highlighting (e.g. "rs", "py", "ex").

highlight_theme(ed, highlight_theme)

@spec highlight_theme(text_editor :: t(), highlight_theme :: String.t()) :: t()

Sets the highlighter color theme.

ime_purpose(ed, ime_purpose)

@spec ime_purpose(text_editor :: t(), ime_purpose :: String.t()) :: t()

Sets the IME input purpose hint.

key_bindings(ed, key_bindings)

@spec key_bindings(text_editor :: t(), key_bindings :: [map()]) :: t()

Sets declarative key binding rules for the editor.

Each rule is a map with:

  • "key" (string) -- a character to match (layout-independent via to_latin).
  • "named" (string) -- a named key like "Enter", "Escape", "Tab", etc.
  • "modifiers" (list of strings) -- required modifiers: "shift", "ctrl", "alt", "logo", "command", "jump".
  • "binding" -- the action: a string like "copy", "cut", "paste", "enter", "backspace", "delete", "unfocus", "select_all", "select_word", "select_line", "default", or a map for complex actions like %{"move" => "left"}, %{"select" => "word_right"}, %{"insert" => "x"}, %{"custom" => "my_tag"}, %{"sequence" => [binding1, binding2, ...]}.

Rules are matched in order. The first matching rule wins. If no rule matches, the key press is ignored (no binding). Use "default" as the binding to delegate to iced's built-in key handler.

line_height(ed, line_height)

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

Sets the line height.

max_height(ed, max_height)

@spec max_height(text_editor :: t(), max_height :: number()) :: t()

Sets the maximum height in pixels.

min_height(ed, min_height)

@spec min_height(text_editor :: t(), min_height :: number()) :: t()

Sets the minimum height in pixels.

new(id, opts \\ [])

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

Creates a new text editor struct with the given id and optional keyword opts.

padding(ed, padding)

@spec padding(text_editor :: t(), padding :: number()) :: t()

Sets the uniform padding in pixels.

placeholder(ed, placeholder)

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

Sets the placeholder text.

placeholder_color(ed, color)

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

Sets the placeholder text color. Accepts any form Color.cast/1 supports.

selection_color(ed, color)

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

Sets the text selection highlight color. Accepts any form Color.cast/1 supports.

size(ed, size)

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

Sets the font size in pixels.

style(ed, style)

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

Sets the text editor style.

width(ed, width)

@spec width(text_editor :: t(), width :: number()) :: t()

Sets the editor width in pixels.

with_options(ed, opts)

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

Applies keyword options to an existing text editor struct.

wrapping(ed, wrapping)

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

Sets the text wrapping mode.