Markex.Element (markex v1.1.0) View Source

Creating and working with elements for 2D markup

Link to this section Summary

Types

List of strings, where all string the same length

Functions

Positions this to the left of that, makes the elements higher if needed

The correct way to get the height of an element

Adds space to the top and bottom of the element so that the height matches n

Creates new element using regular string or list of strings

Fills an element of length w and height h with char ch

Positions this on top of that, makes the elements wider as needed

The correct and safe way to get the width and height of an element

Return string representation of element

Adds space to the sides of the element so that the width matches n

The correct and safe way to get the width of an element

Link to this section Types

Specs

element() :: [String.t()]

List of strings, where all string the same length

Link to this section Functions

Link to this function

beside(this, that, align \\ :center)

View Source (since 1.1.0)

Specs

beside(element(), element(), :center | :top | :bottom) :: element()

Positions this to the left of that, makes the elements higher if needed

The align argument can be used to position the elements correctly relative to each other and can be :center, :top, or :bottom.

See also Markex.Element.Operators.<|>/2 and Markex.Element.higher/2.

Examples

iex> Markex.Element.beside(Markex.Element.new("#"), Markex.Element.new("$", 2, 3))
[
  " $$",
  "#$$",
  " $$"
]
Link to this function

height(element)

View Source (since 1.0.0)

Specs

height(element()) :: non_neg_integer()

The correct way to get the height of an element

Also see Markex.Element.size/1

Link to this function

higher(element, n, align \\ :center)

View Source (since 1.1.0)

Specs

higher(element(), pos_integer(), :center | :top | :bottom) :: element()

Adds space to the top and bottom of the element so that the height matches n

Examples

iex> Markex.Element.new("#") |> Markex.Element.higher(6)
[
  " ",
  " ",
  "#",
  " ",
  " ",
  " "
]
Link to this function

new(content)

View Source (since 1.0.0)

Specs

new(String.t()) :: element()
new([String.t()]) :: element()

Creates new element using regular string or list of strings

In the latter case, automatically makes all strings the same length.

Examples

iex> Markex.Element.new("Hello, world!")
["Hello, wordl!"]

iex> Markex.Element.new(["Hello, world!", "or something idk", "."])
[
  "Hello, world!   ",
  "or something idk",
  ".               "
]
Link to this function

new(ch, w, h)

View Source (since 1.0.0)

Specs

Fills an element of length w and height h with char ch

Examples

iex> Markex.Element.new("#", 5, 5)
[
  "#####",
  "#####",
  "#####",
  "#####",
  "#####"
]
Link to this function

over(this, that, align \\ :center)

View Source (since 1.1.0)

Specs

over(element(), element(), :center | :left | :right) :: element()

Positions this on top of that, makes the elements wider as needed

The align argument can be used to position the elements correctly relative to each other and can be :center, :left, or :right.

See also Markex.Element.Operators.<~>/2 and Markex.Element.wider/2.

Examples

iex> Markex.Element.over(Markex.Element.new("#", 1, 2), Markex.Element.new("$", 3, 2))
[
  " # ",
  " # ",
  "$$$",
  "$$$"
]
Link to this function

size(element)

View Source (since 1.0.0)

Specs

The correct and safe way to get the width and height of an element

See also Markex.Element.width/1 and Markex.Element.height/1.

Examples

iex> Markex.Element.new("#", 4, 5) |> Markex.Element.size()
{4, 5}
Link to this function

to_string(element)

View Source (since 1.0.0)

Specs

to_string(element()) :: String.t()

Return string representation of element

Examples

iex> Markex.Element.new("#", 2, 2) |> Markex.Element.to_string()
"##\n##"
Link to this function

wider(element, n, align \\ :center)

View Source (since 1.1.0)

Specs

wider(element(), pos_integer(), :center | :left | :right) :: element()

Adds space to the sides of the element so that the width matches n

Examples

iex> Markex.Element.new("#") |> Markex.Element.wider(6)
[
  "  #   "
]
Link to this function

width(element)

View Source (since 1.0.0)

Specs

width(element()) :: non_neg_integer()

The correct and safe way to get the width of an element

Also see Markex.Element.size/1