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

Copy Markdown View Source

Image display -- renders a raster image from a file path or an in-memory handle.

Props

  • source (string or handle ref) -- path to the image file, or %{handle: name} for an in-memory image created via Toddy.Command.create_image/2.
  • width (length) -- image width. Default: shrink. See Toddy.Iced.Length.
  • height (length) -- image height. Default: shrink.
  • content_fit -- how the image fits its bounds. See Toddy.Iced.ContentFit.
  • rotation (number) -- rotation angle in degrees.
  • opacity (number) -- opacity from 0.0 (transparent) to 1.0 (opaque).
  • border_radius (number) -- corner radius in pixels.
  • filter_method -- image interpolation mode. See Toddy.Iced.FilterMethod.
  • expand (boolean) -- expand image to fill available space.
  • scale (number) -- scale factor for the image.
  • crop (map) -- crop rectangle: %{x, y, width, height} (integer pixel values).
  • alt (string) -- alt text for the image (accessibility).
  • description (string) -- longer description for the image (accessibility).
  • a11y (map) -- accessibility overrides. See Toddy.Iced.A11y.

Summary

Types

Image source: a file path string or a handle reference map.

t()

Functions

Sets accessibility annotations.

Sets the alt text for the image.

Sets the border radius in pixels.

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

Sets how the image fits its bounds.

Sets the crop rectangle.

Sets a longer description for the image.

Sets whether the image expands to fill available space.

Sets the image filter method.

Sets the image height.

Creates a new image struct with the given source and optional keyword opts.

Sets the image opacity (0.0 to 1.0).

Sets the rotation angle in degrees.

Sets the image scale factor.

Sets the image width.

Applies keyword options to an existing image struct.

Types

option()

@type option() ::
  {:width, Toddy.Iced.Length.t()}
  | {:height, Toddy.Iced.Length.t()}
  | {:content_fit, Toddy.Iced.ContentFit.t()}
  | {:rotation, number()}
  | {:opacity, number()}
  | {:border_radius, number()}
  | {:filter_method, Toddy.Iced.FilterMethod.t()}
  | {:expand, boolean()}
  | {:scale, number()}
  | {:crop, map()}
  | {:alt, String.t()}
  | {:description, String.t()}
  | {:a11y, Toddy.Iced.A11y.t()}

source()

@type source() :: String.t() | %{handle: String.t()}

Image source: a file path string or a handle reference map.

t()

@type t() :: %Toddy.Iced.Widget.Image{
  a11y: Toddy.Iced.A11y.t() | nil,
  alt: String.t() | nil,
  border_radius: number() | nil,
  content_fit: Toddy.Iced.ContentFit.t() | nil,
  crop: map() | nil,
  description: String.t() | nil,
  expand: boolean() | nil,
  filter_method: Toddy.Iced.FilterMethod.t() | nil,
  height: Toddy.Iced.Length.t() | nil,
  id: String.t(),
  opacity: number() | nil,
  rotation: number() | nil,
  scale: number() | nil,
  source: source(),
  width: Toddy.Iced.Length.t() | nil
}

Functions

a11y(img, a11y)

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

Sets accessibility annotations.

alt(img, alt)

@spec alt(image :: t(), alt :: String.t()) :: t()

Sets the alt text for the image.

border_radius(img, border_radius)

@spec border_radius(image :: t(), border_radius :: number()) :: t()

Sets the border radius in pixels.

build(img)

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

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

content_fit(img, content_fit)

@spec content_fit(image :: t(), content_fit :: Toddy.Iced.ContentFit.t()) :: t()

Sets how the image fits its bounds.

crop(img, crop)

@spec crop(image :: t(), crop :: map()) :: t()

Sets the crop rectangle.

description(img, description)

@spec description(image :: t(), description :: String.t()) :: t()

Sets a longer description for the image.

expand(img, expand)

@spec expand(image :: t(), expand :: boolean()) :: t()

Sets whether the image expands to fill available space.

filter_method(img, filter_method)

@spec filter_method(image :: t(), filter_method :: Toddy.Iced.FilterMethod.t()) :: t()

Sets the image filter method.

height(img, height)

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

Sets the image height.

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

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

Creates a new image struct with the given source and optional keyword opts.

The source can be a file path string or a handle reference map (%{handle: "name"}) for in-memory images created via Toddy.Command.create_image/2.

opacity(img, opacity)

@spec opacity(image :: t(), opacity :: number()) :: t()

Sets the image opacity (0.0 to 1.0).

rotation(img, rotation)

@spec rotation(image :: t(), rotation :: number()) :: t()

Sets the rotation angle in degrees.

scale(img, scale)

@spec scale(image :: t(), scale :: number()) :: t()

Sets the image scale factor.

width(img, width)

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

Sets the image width.

with_options(img, opts)

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

Applies keyword options to an existing image struct.