View Source Garnish.Renderer behaviour (garnish v0.2.1)

Logic to render a view tree.

This API is still under development.

Summary

Functions

Renders a view tree to canvas, given a canvas and a root element (an element with the :view tag).

Validates the hierarchy of a view tree given the root element.

Types

child_element()

@type child_element() :: %Garnish.Renderer.Element{
  attributes: term(),
  children: term(),
  tag: child_tag()
}

child_tag()

@type child_tag() ::
  :bar
  | :chart
  | :column
  | :label
  | :overlay
  | :panel
  | :row
  | :sparkline
  | :table
  | :table_cell
  | :table_row
  | :text
  | :tree
  | :tree_node

root_element()

@type root_element() :: %Garnish.Renderer.Element{
  attributes: term(),
  children: [child_element()],
  tag: :view
}

Callbacks

Functions

render(canvas, root)

@spec render(Garnish.Renderer.Canvas.t(), root_element()) ::
  {:ok, Garnish.Renderer.Canvas.t()} | {:error, term()}

Renders a view tree to canvas, given a canvas and a root element (an element with the :view tag).

The tree is rendered by recursively rendering each element in the hierarchy. The canvas serves as both the accumulator for rendered cells at each stage and as the box representing available space for rendering, which shrinks as this space is consumed.

render_tree(canvas, elements)

validate_tree(element)

@spec validate_tree(Garnish.Renderer.Element.t()) :: :ok | {:error, String.t()}

Validates the hierarchy of a view tree given the root element.

Used by the render/2 function to prevent strange errors that may otherwise occur when processing invalid view trees.