FloUI.Scrollable.Direction (FloUI v0.1.0-alpha.5) View Source

Utility module for limiting certain operations along a certain direction only. A value can be connected to either horizontal or vertical directions.

Link to this section Summary

Types

The directions a value can be associated with.

t()

The Direction type. A value can be either associated with the horizontal or the vertical direction, by pairing the :horizontal or :vertical atoms with the value in a tuple.

Data structure representing a vector 2, in the form of an {x, y} tuple.

Functions

Add two t:Scenic.Scrollable.Direction.t/0 values. Only values associated with the same direction will be added. Non numeric values are ignored.

Associate a value with the horizontal direction.

Associate a value with the vertical direction.

Divide two t:Scenic.Scrollable.Direction.t/0 values. Only values associated with the same direction will be divided. Non numeric values are ignored.

Create a t:Scenic.Scrollable.Direction.t/0 from a Scenic.Math.vector_2/0.

Convert a horizontal t:Scenic.Scrollable.Direction.t/0 to a vertical one, and vice versa.

Apply a function to the t:Scenic.Scrollable.Direction.t inner value. Returns a new t:Scenic.Scrollable.Direction.t.

Apply a function only if the t:Scenic.Scrollable.Direction.t is associated with the horizontal direction. Returns a new t:Scenic.Scrollable.Direction.t.

Apply a function only if the t:Scenic.Scrollable.Direction.t is associated with the vertical direction. Returns a new t:Scenic.Scrollable.Direction.t.

Multiply two t:Scenic.Scrollable.Direction.t/0 values. Only values associated with the same direction will be multiplied. Non numeric values are ignored.

Associate a value with a direction.

Subtract two t:Scenic.Scrollable.Direction.t/0 values. Only values associated with the same direction will be subtracted. Non numeric values are ignored.

Convert a t:Scenic.Scrollable.Direction.t/0 to a Scenic.Math.vector_2/0. If the value is non numeric, the vector {0, 0} will be returned.

Obtain the inner value from a t:Scenic.Scrollable.Direction.t/0.

Link to this section Types

Specs

direction() :: :horizontal | :vertical

The directions a value can be associated with.

Specs

t() :: {:horizontal, term()} | {:vertical, term()}

The Direction type. A value can be either associated with the horizontal or the vertical direction, by pairing the :horizontal or :vertical atoms with the value in a tuple.

Specs

v2() :: Scenic.Scrollable.v2()

Data structure representing a vector 2, in the form of an {x, y} tuple.

Link to this section Functions

Specs

add(t(), t()) :: t()

Add two t:Scenic.Scrollable.Direction.t/0 values. Only values associated with the same direction will be added. Non numeric values are ignored.

Examples

iex> five = Scenic.Scrollable.Direction.as_horizontal(5)
...> six = Scenic.Scrollable.Direction.as_horizontal(6)
...> Scenic.Scrollable.Direction.add(five, six)
{:horizontal, 11}

iex> three = Scenic.Scrollable.Direction.as_vertical(3)
...> seven = Scenic.Scrollable.Direction.as_vertical(7)
...> Scenic.Scrollable.Direction.add(three, seven)
{:vertical, 10}

iex> five = Scenic.Scrollable.Direction.as_horizontal(5)
...> six = Scenic.Scrollable.Direction.as_vertical(6)
...> Scenic.Scrollable.Direction.add(five, six)
{:horizontal, 5}

iex> non_numeric_value = Scenic.Scrollable.Direction.as_horizontal(:non_numeric_value)
...> six = Scenic.Scrollable.Direction.as_vertical(6)
...> Scenic.Scrollable.Direction.add(non_numeric_value, six)
{:horizontal, :non_numeric_value}

Specs

as_horizontal(term()) :: t()

Associate a value with the horizontal direction.

Examples

iex> Scenic.Scrollable.Direction.as_horizontal(5)
{:horizontal, 5}

Specs

as_vertical(term()) :: t()

Associate a value with the vertical direction.

Examples

iex> Scenic.Scrollable.Direction.as_vertical(6)
{:vertical, 6}

Specs

divide(t(), t()) :: t()

Divide two t:Scenic.Scrollable.Direction.t/0 values. Only values associated with the same direction will be divided. Non numeric values are ignored.

Examples

iex> fifty = Scenic.Scrollable.Direction.as_horizontal(50)
...> ten = Scenic.Scrollable.Direction.as_horizontal(10)
...> Scenic.Scrollable.Direction.divide(fifty, ten)
{:horizontal, 5.0}

iex> nine = Scenic.Scrollable.Direction.as_vertical(9)
...> three = Scenic.Scrollable.Direction.as_vertical(3)
...> Scenic.Scrollable.Direction.divide(nine, three)
{:vertical, 3.0}

iex> six = Scenic.Scrollable.Direction.as_horizontal(6)
...> two = Scenic.Scrollable.Direction.as_vertical(2)
...> Scenic.Scrollable.Direction.divide(six, two)
{:horizontal, 6}

iex> non_numeric_value = Scenic.Scrollable.Direction.as_horizontal(:non_numeric_value)
...> six = Scenic.Scrollable.Direction.as_vertical(6)
...> Scenic.Scrollable.Direction.divide(non_numeric_value, six)
{:horizontal, :non_numeric_value}
Link to this function

from_vector_2(arg, atom)

View Source

Specs

from_vector_2(v2(), direction()) :: t()

Create a t:Scenic.Scrollable.Direction.t/0 from a Scenic.Math.vector_2/0.

Examples

iex> Scenic.Scrollable.Direction.from_vector_2({3, 5}, :horizontal)
{:horizontal, 3}

iex> Scenic.Scrollable.Direction.from_vector_2({3, 5}, :vertical)
{:vertical, 5}

Specs

invert(t()) :: t()

Convert a horizontal t:Scenic.Scrollable.Direction.t/0 to a vertical one, and vice versa.

Examples

iex> Scenic.Scrollable.Direction.as_horizontal(5)
...> |> Scenic.Scrollable.Direction.invert
{:vertical, 5}

Specs

map(t(), (term() -> term())) :: t()

Apply a function to the t:Scenic.Scrollable.Direction.t inner value. Returns a new t:Scenic.Scrollable.Direction.t.

Examples

iex> Scenic.Scrollable.Direction.map({:horizontal, 5}, & &1 * 2)
{:horizontal, 10}

iex> Scenic.Scrollable.Direction.map({:vertical, 5}, & &1 * 2)
{:vertical, 10}

Specs

map_horizontal(t(), (term() -> term())) :: t()

Apply a function only if the t:Scenic.Scrollable.Direction.t is associated with the horizontal direction. Returns a new t:Scenic.Scrollable.Direction.t.

Examples

iex> Scenic.Scrollable.Direction.map_horizontal({:horizontal, 5}, & &1 * 2)
{:horizontal, 10}

iex> Scenic.Scrollable.Direction.map_horizontal({:vertical, 5}, & &1 * 2)
{:vertical, 5}

Specs

map_vertical(t(), (term() -> term())) :: t()

Apply a function only if the t:Scenic.Scrollable.Direction.t is associated with the vertical direction. Returns a new t:Scenic.Scrollable.Direction.t.

Examples

iex> Scenic.Scrollable.Direction.map_vertical({:vertical, 5}, & &1 * 2)
{:vertical, 10}

iex> Scenic.Scrollable.Direction.map_vertical({:horizontal, 5}, & &1 * 2)
{:horizontal, 5}

Specs

multiply(t(), t()) :: t()

Multiply two t:Scenic.Scrollable.Direction.t/0 values. Only values associated with the same direction will be multiplied. Non numeric values are ignored.

Examples

iex> five = Scenic.Scrollable.Direction.as_horizontal(5)
...> six = Scenic.Scrollable.Direction.as_horizontal(6)
...> Scenic.Scrollable.Direction.multiply(five, six)
{:horizontal, 30}

iex> three = Scenic.Scrollable.Direction.as_vertical(3)
...> seven = Scenic.Scrollable.Direction.as_vertical(7)
...> Scenic.Scrollable.Direction.multiply(three, seven)
{:vertical, 21}

iex> five = Scenic.Scrollable.Direction.as_horizontal(5)
...> six = Scenic.Scrollable.Direction.as_vertical(6)
...> Scenic.Scrollable.Direction.multiply(five, six)
{:horizontal, 5}

iex> non_numeric_value = Scenic.Scrollable.Direction.as_horizontal(:non_numeric_value)
...> six = Scenic.Scrollable.Direction.as_vertical(6)
...> Scenic.Scrollable.Direction.multiply(non_numeric_value, six)
{:horizontal, :non_numeric_value}

Specs

return(term(), direction()) :: t()

Associate a value with a direction.

Examples

iex> Scenic.Scrollable.Direction.return(5, :horizontal)
{:horizontal, 5}

iex> Scenic.Scrollable.Direction.return(6, :vertical)
{:vertical, 6}

Specs

subtract(t(), t()) :: t()

Subtract two t:Scenic.Scrollable.Direction.t/0 values. Only values associated with the same direction will be subtracted. Non numeric values are ignored.

Examples

iex> five = Scenic.Scrollable.Direction.as_horizontal(5)
...> six = Scenic.Scrollable.Direction.as_horizontal(6)
...> Scenic.Scrollable.Direction.subtract(five, six)
{:horizontal, -1}

iex> three = Scenic.Scrollable.Direction.as_vertical(3)
...> seven = Scenic.Scrollable.Direction.as_vertical(7)
...> Scenic.Scrollable.Direction.subtract(three, seven)
{:vertical, -4}

iex> five = Scenic.Scrollable.Direction.as_horizontal(5)
...> six = Scenic.Scrollable.Direction.as_vertical(6)
...> Scenic.Scrollable.Direction.subtract(five, six)
{:horizontal, 5}

iex> non_numeric_value = Scenic.Scrollable.Direction.as_horizontal(:non_numeric_value)
...> six = Scenic.Scrollable.Direction.as_vertical(6)
...> Scenic.Scrollable.Direction.subtract(non_numeric_value, six)
{:horizontal, :non_numeric_value}

Specs

to_vector_2(t()) :: v2()

Convert a t:Scenic.Scrollable.Direction.t/0 to a Scenic.Math.vector_2/0. If the value is non numeric, the vector {0, 0} will be returned.

Examples

iex> Scenic.Scrollable.Direction.as_horizontal(5)
...> |> Scenic.Scrollable.Direction.to_vector_2
{5, 0}

iex> Scenic.Scrollable.Direction.as_vertical(5)
...> |> Scenic.Scrollable.Direction.to_vector_2
{0, 5}

iex> Scenic.Scrollable.Direction.as_horizontal(:non_numeric_value)
...> |> Scenic.Scrollable.Direction.to_vector_2
{0, 0}

Specs

unwrap(t()) :: term()

Obtain the inner value from a t:Scenic.Scrollable.Direction.t/0.

Examples

iex> Scenic.Scrollable.Direction.as_horizontal(5)
...> |> Scenic.Scrollable.Direction.unwrap
5