View Source Garnish.Renderer.Box (garnish v0.2.2)

This defines the internal representation of a rectangular region---a box---for rendering, as well as logic for transforming these boxes.

Boxes live on a coordinate plane. The y-axis is inverted so that the y values increase as the box's height grows.

--------------> x
|
|    ________
|    |      |
|    |______|
v
y

A Box struct stores the coordinates for two corners of the box---the top-left and bottom-right corners--from which the remaining attributes (height, width, other corners) can be computed.

 _________________
|                 |
|  A              |
|                 |
|                 |
|                 |
|              B  |
|_________________|

A: top-left corner, e.g. (0, 0)
B: bottom-right corner, e.g. (10, 10)

For rendering purposes, the outermost box will typically have a top-left corner (0, 0) and a bottom-right corner (x, y) where x is the number of rows and y is the number of columns on the terminal.

This outermost box can then be subdivided as necessary to render different elements of the view.

Summary

Types

t()

@type t() :: %Garnish.Renderer.Box{
  bottom_right: Garnish.Position.t(),
  top_left: Garnish.Position.t()
}

Functions

bottom_left(box)

bottom_right(box)

consume(box, dx, dy)

contains?(box, position)

from_dimensions(width, height, origin \\ %Position{x: 0, y: 0})

head(box, n)

Given a box, returns a slice of the y axis with n rows from the top.

height(box)

padded(box, size)

positions(box)

tail(box, n)

Given a box, returns a slice of the y axis with n rows from the bottom.

top_left(box)

top_right(box)

translate(box, dx, dy)

width(box)