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

A canvas represents a terminal window, a subvision of it for rendering, and a sparse mapping of positions to cells.

A %Canvas{} struct can be rendered to different output formats. This includes the primary use-case of rendering to the termbox-managed window, but also rendering to strings, which is useful for testing.

Summary

Functions

Copies the canvas to a new one with the render box consumed by the given dx and dy.

Creates a new canvas with n columns (from the left) consumed.

Creates a new canvas with n rows (from the top) consumed.

Creates an empty canvas with the given dimensions.

Merges a list of cells into the canvas, provided that the cells are located within the canvas's rendering box. Returns a new canvas with the merged cells.

Copies the canvas to a new one with the render box padded on each side (top, left, bottom, right) by size. Pass a negative size to remove padding.

Types

t()

@type t() :: %Garnish.Renderer.Canvas{
  cells: map(),
  outer_box: Garnish.Renderer.Box.t(),
  render_box: Garnish.Renderer.Box.t()
}

Functions

consume(canvas, dx, dy)

@spec consume(t(), integer(), integer()) :: t()

Copies the canvas to a new one with the render box consumed by the given dx and dy.

The render box is used to indicate the empty, renderable space on the canvas, so this might be called with a dy of 1 after rendering a line of text. The box is consumed left-to-right and top-to-bottom.

consume_columns(canvas, n)

@spec consume_columns(t(), integer()) :: t()

Creates a new canvas with n columns (from the left) consumed.

consume_rows(canvas, n)

@spec consume_rows(t(), integer()) :: t()

Creates a new canvas with n rows (from the top) consumed.

fill_background(canvas)

from_dimensions(x, y)

@spec from_dimensions(non_neg_integer(), non_neg_integer()) :: t()

Creates an empty canvas with the given dimensions.

Examples

iex> Canvas.from_dimensions(10, 20)
%Canvas{
  outer_box: %Garnish.Renderer.Box{
    top_left: %Garnish.Position{x: 0, y: 0},
    bottom_right: %Garnish.Position{x: 9, y: 19}
  },
  render_box: %Garnish.Renderer.Box{
    top_left: %Garnish.Position{x: 0, y: 0},
    bottom_right: %Garnish.Position{x: 9, y: 19}
  },
  cells: %{}
}

merge_cells(canvas, cells)

@spec merge_cells(t(), [Garnish.Cell.t()]) :: t()

Merges a list of cells into the canvas, provided that the cells are located within the canvas's rendering box. Returns a new canvas with the merged cells.

padded(canvas, size)

@spec padded(t(), integer()) :: t()

Copies the canvas to a new one with the render box padded on each side (top, left, bottom, right) by size. Pass a negative size to remove padding.

put_box(canvas, render_box)

@spec put_box(t(), Garnish.Renderer.Box.t()) :: t()

render_to_string(canvas)

@spec render_to_string(t()) :: String.t()

render_to_strings(canvas)

@spec render_to_strings(t()) :: [String.t()]

render_to_termbox(bindings, canvas)

@spec render_to_termbox(module(), t()) :: :ok

translate(canvas, dx, dy)

@spec translate(t(), integer(), integer()) :: t()