View Source RectLayout (rect_layout v0.1.0)

Create and manipulate rectangular objects and groups of them

Use import RectLayout to import everything, or import only the methods you need.

Summary

Functions

Align each item to a given y value Can skip the y value which will pick the bottommost item

Align each item to a given x value to the left Can skip the x value which will pick the leftmost item

Align each item to a given x value to the right Can skip the x value which will pick the rightmost item

Align each item to a given y value Can skip the y value which will pick the topmost item

Get the bottommost y of an item or a list of items

Set the y so the bottommost part of the item is at y

Get the center x attribute of the item.

Set the center x attribute of the item. Position the item so that the new x is now its horizontal center

Get the center y attribute of the item.

Set the center y attribute of the item. Position the item so that the new y is now its vertical center

Set the height and modify the width to keep the aspect ratio For a list, apply the new height to each item in the list

Set the width and modify the height to keep the aspect ratio For a list, apply the new width to each item in the list

Distribute each item in the list horizontally to cover the assigned width with a consistent gap between items

Distribute each item in the list vertically to cover the assigned height with a consistent gap between items

Extrude the edges of a rect outward (or inward) and keeping the position

Distribute each item in the list horizontally with a set gap

Distribute each item in the list vertically with a set gap

Creates an %RectLayout.Group{}, used to work with a group of graphical items. any modification of its x, y, width or height affects all of its children, proportionally.

Get or update the children of a group. When updating it will also will update the bounding rect of the group.

Get the height attribute of the item. Shortcut for RectLayout.Object.height/1

Set the height attribute of the item. Shortcut for RectLayout.Object.height/2

Get the leftmost x of a list of items

Get the maximum height of a list of items

Get the maximum width of a list of items

Creates an %RectLayout.Rect{}, a primitive used to track info about rectangles. It does not have any other attributes except its x, y, width and height

Get the rightmost x of an item or a list of items

Set the x so the rightmost part of the item is at x

Spread out each item in the list horizontally to cover the assigned width Items are spread evenly centered on their vertical axis No overlap is allowed and items push each other to the right

Spread out each item in the list vertically to cover the assigned height Items are spread evenly centered on their horizontal axis No overlap is allowed and items push each other down

Creates an %RectLayout.Sprite{}, which is used to track external data for a rect.

Get or update the content of a sprite.

Create a rectangle that surrounds all the items in the list

Push item to the top of a given line. If the line is before it, don't do anything

Push item to the right of a given line. If the line is before it, don't do anything

Push item to the left of a given line. If the line is before it, don't do anything

Push item to the bottom of a given line. If the line is before it, don't do anything

Get the topmost y of a list of items

Get the width attribute of the item. Shortcut for RectLayout.Object.width/1

Set the width attribute of the item. Shortcut for RectLayout.Object.width/2

Get the x attribute of the item. Shortcut for RectLayout.Object.x/1

Set the x attribute of the item. Shortcut for RectLayout.Object.x/2

Get the y attribute of the item. Shortcut for RectLayout.Object.y/1

Set the y attribute of the item. Shortcut for RectLayout.Object.y/2

Types

Link to this type

flow_horizontal_option()

View Source
@type flow_horizontal_option() :: {:x, number()} | {:gap, number()}
Link to this type

flow_vertical_option()

View Source
@type flow_vertical_option() :: {:x, number()} | {:gap, number()}
Link to this type

spread_horizontal_option()

View Source
@type spread_horizontal_option() ::
  {:x, number()} | {:gap, number()} | {:cols, number()}
Link to this type

spread_vertical_option()

View Source
@type spread_vertical_option() ::
  {:x, number()} | {:gap, number()} | {:cols, number()}

Functions

@spec align_bottom([RectLayout.Object.t()]) :: [RectLayout.Object.t()]

Align each item to a given y value Can skip the y value which will pick the bottommost item

Visual

*--*
|  |
*--*         ->
      *---*
      |   |      *--* *---*
      *---*      |  | |   |
------------    -*--*-*---*-

Examples

iex(1)> align_bottom([rect(2, 2), rect(3, 3, 2, 2)], 6)
[
  %RectLayout.Rect{x: 0, y: 4, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 3, width: 3, height: 3}
]

iex(2)> align_bottom([rect(2, 2), rect(3, 3, 2, 2)])
[
  %RectLayout.Rect{x: 0, y: 3, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 2, width: 3, height: 3}
]
@spec align_bottom([RectLayout.Object.t()], number()) :: [RectLayout.Object.t()]
@spec align_left([RectLayout.Object.t()]) :: [RectLayout.Object.t()]

Align each item to a given x value to the left Can skip the x value which will pick the leftmost item

Visual

|                    |
| *--*               *--*
| |  |               |  |
| *--*               *--*
|      *---*   ->    *---*
|      |   |         |   |
|      *---*         *---*
|                    |

Examples

iex(1)> align_left([rect(2, 2), rect(3, 3, 2, 2)], -2)
[
  %RectLayout.Rect{x: -2, y: 0, width: 2, height: 2},
  %RectLayout.Rect{x: -2, y: 2, width: 3, height: 3}
]

iex(2)> align_left([rect(2, 2), rect(3, 3, 2, 2)])
[
  %RectLayout.Rect{x: 0, y: 0, width: 2, height: 2},
  %RectLayout.Rect{x: 0, y: 2, width: 3, height: 3}
]
@spec align_left([RectLayout.Object.t()], number()) :: [RectLayout.Object.t()]
@spec align_right([RectLayout.Object.t()]) :: [RectLayout.Object.t()]

Align each item to a given x value to the right Can skip the x value which will pick the rightmost item

Visual

           |            |
*--*       |         *--*
|  |       |         |  |
*--*       | ->      *--*
     *---* |        *---*
     |   | |        |   |
     *---* |        *---*
           |            |

Examples

iex(1)> align_right([rect(2, 2), rect(3, 3, 2, 2)], 6)
[
  %RectLayout.Rect{x: 4, y: 0, width: 2, height: 2},
  %RectLayout.Rect{x: 3, y: 2, width: 3, height: 3}
]

iex(2)> align_right([rect(2, 2), rect(3, 3, 2, 2)])
[
  %RectLayout.Rect{x: 3, y: 0, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 2, width: 3, height: 3}
]
@spec align_right([RectLayout.Object.t()], number()) :: [RectLayout.Object.t()]
@spec align_top([RectLayout.Object.t()]) :: [RectLayout.Object.t()]

Align each item to a given y value Can skip the y value which will pick the topmost item

Visual

|                    |
| *--*               *--*
| |  |               |  |
| *--*               *--*
|      *---*   ->    *---*
|      |   |         |   |
|      *---*         *---*
|                    |

Examples

iex(1)> align_top([rect(2, 2), rect(3, 3, 2, 2)], -2)
[
  %RectLayout.Rect{x: 0, y: -2, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: -2, width: 3, height: 3}
]

iex(2)> align_top([rect(2, 2), rect(3, 3, 2, 2)])
[
  %RectLayout.Rect{x: 0, y: 0, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 0, width: 3, height: 3}
]
@spec align_top([RectLayout.Object.t()], number()) :: [RectLayout.Object.t()]
@spec bottom(RectLayout.Object.t() | [RectLayout.Object.t()]) :: number()

Get the bottommost y of an item or a list of items

Visual

*---*
|   |
*---*
     *---*
     |   |
-----*---*-

Examples

iex(1)> bottom(rect(2, 2)) 2 iex(2)> bottom(rect(2, 2, 2, 2)) 4 iex(3)> bottom([rect(2, 2), rect(2, 2, 2, 2)]) 4

Set the y so the bottommost part of the item is at y

Examples

iex(1)> bottom(rect(2, 2), 4) %RectLayout.Rect{x: 0, y: 2, width: 2, height: 2}

@spec center_x(RectLayout.Object.t()) :: number()

Get the center x attribute of the item.

Visual

 *---*
-|---|-
 *---*

Examples

iex(1)> center_x(rect(3, 5)) 1.5

@spec center_x(RectLayout.Object.t(), number()) :: RectLayout.Object.t()

Set the center x attribute of the item. Position the item so that the new x is now its horizontal center

Visual

 *---*
-|---|-
 *---*

Examples

iex(1)> center_x(rect(3, 5), 5) %RectLayout.Rect{x: 3.5, y: 0, width: 3, height: 5}

@spec center_y(RectLayout.Object.t()) :: number()

Get the center y attribute of the item.

Visual

*-|-*
| | |
*-|-*

Examples

iex(1)> center_y(rect(3, 5)) 2.5

@spec center_y(RectLayout.Object.t(), number()) :: RectLayout.Object.t()

Set the center y attribute of the item. Position the item so that the new y is now its vertical center

Visual

*-|-*
| | |
*-|-*

Examples

iex(1)> center_y(rect(3, 5), 5) %RectLayout.Rect{x: 0, y: 2.5, width: 3, height: 5}

Link to this function

constrain_height(item, to)

View Source
@spec constrain_height([RectLayout.Object.t()], number()) :: [RectLayout.Object.t()]
@spec constrain_height(RectLayout.Object.t(), number()) :: RectLayout.Object.t()

Set the height and modify the width to keep the aspect ratio For a list, apply the new height to each item in the list

Examples

iex(1)> constrain_height(rect(4, 2), 4)
%RectLayout.Rect{x: 0, y: 0, width: 8.0, height: 4}

iex(2)> constrain_height([rect(4, 2), rect(4, 8)], 4)
[
  %RectLayout.Rect{x: 0, y: 0, width: 8.0, height: 4},
  %RectLayout.Rect{x: 0, y: 0, width: 2.0, height: 4}
]
Link to this function

constrain_width(item, to)

View Source
@spec constrain_width([RectLayout.Object.t()], number()) :: [RectLayout.Object.t()]
@spec constrain_width(RectLayout.Object.t(), number()) :: RectLayout.Object.t()

Set the width and modify the height to keep the aspect ratio For a list, apply the new width to each item in the list

Examples

iex(1)> constrain_width(rect(2, 4), 4)
%RectLayout.Rect{x: 0, y: 0, width: 4, height: 8.0}

iex(2)> constrain_width([rect(2, 4), rect(8, 4)], 4)
[
  %RectLayout.Rect{x: 0, y: 0, width: 4, height: 8.0},
  %RectLayout.Rect{x: 0, y: 0, width: 4, height: 2.0}
]
Link to this function

distribute_horizontal(items, width)

View Source
@spec distribute_horizontal([RectLayout.Object.t()], number()) :: [
  RectLayout.Object.t()
]

Distribute each item in the list horizontally to cover the assigned width with a consistent gap between items

Visual

*---*-*-*         *---*  *-----*  *-------*
|   | | |         |   |  |     |  |       |
*---* | |    ->   *---*  |     |  |       |
*---*-*-*                *---*-*  *---*---*
                  <--------width---------->

Examples

iex(1)> distribute_horizontal([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], 12)
[
  %RectLayout.Rect{x: 0, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 4.0, y: 1, width: 2, height: 2},
  %RectLayout.Rect{x: 9.0, y: 2, width: 3, height: 3}
]
Link to this function

distribute_vertical(items, height)

View Source
@spec distribute_vertical([RectLayout.Object.t()], number()) :: [
  RectLayout.Object.t()
]

Distribute each item in the list vertically to cover the assigned height with a consistent gap between items

Visual

                   *---*      
                   |   |      |
                   *---*      |
                              |
*---*-*-*          *-----*    |
|   | | |          |     |    |
*---* | |    ->    |     |    |
|     | |          |     |  height
*-----* |          *-----*    |
|       |                     |
*-------*          *-------*  |
                   |       |  |
                   |       |  |
                   |       |  |
                   |       |  |
                   |       |  |
                   *-------*  

Examples

iex(1)> distribute_vertical([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], 12)
[
  %RectLayout.Rect{x: 0, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 1, y: 4.0, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 9.0, width: 3, height: 3}
]

Extrude the edges of a rect outward (or inward) and keeping the position

Visual

           *-------*
*---*      |       |
|   |  ->  |       |
*---*      |       |
           *-------*

Examples

iex(1)> extrude(rect(2, 2), 1)
%RectLayout.Rect{x: -1, y: -1, width: 4, height: 4}

iex(2)> extrude(rect(4, 4), -1)
%RectLayout.Rect{x: 1, y: 1, width: 2, height: 2}
Link to this function

flow_horizontal(items, opts \\ [])

View Source
@spec flow_horizontal([RectLayout.Object.t()], [flow_horizontal_option()]) :: [
  RectLayout.Object.t()
]

Distribute each item in the list horizontally with a set gap

Options

  • :x where to start the flow from, default 0
  • :gap the gap between items, default 0

Visual

*---*-*-*         *---**-----**-------*
|   | | |         |   ||     ||       |
*---* | |    ->   *---*|     ||       |
*---*-*-*              *-----**-------*
                  <-------width------->

Examples

iex(1)> flow_horizontal([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)])
[
  %RectLayout.Rect{x: 0, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 1, y: 1, width: 2, height: 2},
  %RectLayout.Rect{x: 3, y: 2, width: 3, height: 3}
]

iex(2)> flow_horizontal([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], gap: 2)
[
  %RectLayout.Rect{x: 0, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 3, y: 1, width: 2, height: 2},
  %RectLayout.Rect{x: 7, y: 2, width: 3, height: 3}
]
Link to this function

flow_vertical(items, opts \\ [])

View Source
@spec flow_vertical([RectLayout.Object.t()], [flow_vertical_option()]) :: [
  RectLayout.Object.t()
]

Distribute each item in the list vertically with a set gap

Options

  • :y where to start the flow from, default 0
  • :gap the gap between items, default 0

Visual

                   *---*      
                   |   |      |
                   *---*      |
*---*-*-*          *-----*    |
|   | | |          |     |    |
*---* | |    ->    |     |    |
|     | |          |     |  height
*-----* |          *-----*    |
|       |          *-------*  |
*-------*          |       |  |
                   |       |  |
                   |       |  |
                   |       |  |
                   |       |  |
                   *-------*  

Examples

iex(1)> flow_vertical([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)])
[
  %RectLayout.Rect{x: 0, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 1, y: 1, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 3, width: 3, height: 3}
]

iex(2)> flow_vertical([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], gap: 2)
[
  %RectLayout.Rect{x: 0, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 1, y: 3, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 7, width: 3, height: 3}
]
@spec group([RectLayout.Object.t()]) :: RectLayout.Group.t()

Creates an %RectLayout.Group{}, used to work with a group of graphical items. any modification of its x, y, width or height affects all of its children, proportionally.

Examples

iex(1)> group([rect(10,20),rect(5,5)])
%RectLayout.Group{
  rect: %RectLayout.Rect{x: 0, y: 0, width: 10, height: 20},
  children: [
    %RectLayout.Rect{x: 0, y: 0, width: 10, height: 20},
    %RectLayout.Rect{x: 0, y: 0, width: 5, height: 5}
  ]
}
@spec group_children(RectLayout.Group.t()) :: [RectLayout.Object.t()]

Get or update the children of a group. When updating it will also will update the bounding rect of the group.

## Examples

iex(1)> g = group([rect(10, 20), rect(5, 5)])
iex(3)> group_children(g)
[
  %RectLayout.Rect{x: 0, y: 0, width: 10, height: 20},
  %RectLayout.Rect{x: 0, y: 0, width: 5, height: 5}
]
iex(1)> group_children(g, [rect(2, 2)])
%RectLayout.Group{
  rect: %RectLayout.Rect{x: 0, y: 0, width: 2, height: 2},
  children: [
    %RectLayout.Rect{x: 0, y: 0, width: 2, height: 2}
  ]
}
Link to this function

group_children(group, children)

View Source
@spec group_children(RectLayout.Group.t(), [RectLayout.Object.t()]) ::
  RectLayout.Group.t()
@spec height(RectLayout.Object.t()) :: number()

Get the height attribute of the item. Shortcut for RectLayout.Object.height/1

Set the height attribute of the item. Shortcut for RectLayout.Object.height/2

@spec left([RectLayout.Object.t()]) :: number()

Get the leftmost x of a list of items

Visual

|
*---*
|   |
*---*
|    *---*
|    |   |
|    *---*

Examples

iex(1)> left([rect(2, 2), rect(2, 2, 2, 2)]) 0

@spec max_height([RectLayout.Object.t()]) :: number()

Get the maximum height of a list of items

Examples

iex(1)> max_height([rect(2, 1), rect(3, 5, 1, 1), rect(4, 4, 1, 1)]) 5

@spec max_width([RectLayout.Object.t()]) :: number()

Get the maximum width of a list of items

Examples

iex(1)> max_width([rect(2, 1), rect(3, 5, 1, 1), rect(4, 4, 1, 1)]) 4

Link to this function

rect(width, height, x \\ 0, y \\ 0)

View Source
@spec rect(width :: number(), height :: number(), x :: number(), y :: number()) ::
  RectLayout.Rect.t()

Creates an %RectLayout.Rect{}, a primitive used to track info about rectangles. It does not have any other attributes except its x, y, width and height

Examples

iex(1)> rect(10, 20, 2, 5)
%RectLayout.Rect{x: 2, y: 5, width: 10, height: 20}

iex(2)> rect(10, 20)
%RectLayout.Rect{x: 0, y: 0, width: 10, height: 20}
@spec right(RectLayout.Object.t() | [RectLayout.Object.t()]) :: number()

Get the rightmost x of an item or a list of items

Visual

--- | | | | --- |

  *---*
  |   |
  *---*
      |

Examples

iex(1)> right(rect(2, 2)) 2 iex(2)> right(rect(2, 2, 2, 2)) 4 iex(3)> right([rect(2, 2), rect(2, 2, 2, 2)]) 4

Set the x so the rightmost part of the item is at x

Examples

iex(1)> right(rect(2, 2), 4) %RectLayout.Rect{x: 2, y: 0, width: 2, height: 2}

Link to this function

spread_horizontal(items, width, opts \\ [])

View Source
@spec spread_horizontal([RectLayout.Object.t()], number(), [
  spread_horizontal_option()
]) :: [
  RectLayout.Object.t()
]

Spread out each item in the list horizontally to cover the assigned width Items are spread evenly centered on their vertical axis No overlap is allowed and items push each other to the right

Options:

  • :x from which x position to start the spread, default 0
  • :gap the minimum gap between items, default 0
  • :cols the number of columns to spread items in, you can select a bigger number than the number of items, default length(items)

Visual

                    |        |        |
*---*-*-*         *-|-*   *--|--* *---|---*
|   | | |         | | |   |  |  | |   |   |
*---* | |    ->   *-|-*   |  |  | |   |   |
*---*-*-*           |     *--|--* *---|---*
                    |        |        |
                    |        |        |
                <----------width---------->

Examples

iex(1)> spread_horizontal([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], 9)
[
  %RectLayout.Rect{x: 1.0, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 3.5, y: 1, width: 2, height: 2},
  %RectLayout.Rect{x: 6.0, y: 2, width: 3, height: 3}
]

iex(2)> spread_horizontal([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], 6, gap: 2)
[
  %RectLayout.Rect{x: 0.5, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 3.5, y: 1, width: 2, height: 2},
  %RectLayout.Rect{x: 7.5, y: 2, width: 3, height: 3}
]

iex(3)> spread_horizontal([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], 9, x: 2)
[
  %RectLayout.Rect{x: 3.0, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 5.5, y: 1, width: 2, height: 2},
  %RectLayout.Rect{x: 8.0, y: 2, width: 3, height: 3}
]

iex(4)> spread_horizontal([rect(1, 1, 0, 0), rect(2, 2, 1, 1)], 9, cols: 3)
[
  %RectLayout.Rect{x: 1.0, y: 0, width: 1, height: 1},
  %RectLayout.Rect{x: 3.5, y: 1, width: 2, height: 2},
]
Link to this function

spread_vertical(items, height, opts \\ [])

View Source
@spec spread_vertical([RectLayout.Object.t()], number(), [spread_vertical_option()]) ::
  [
    RectLayout.Object.t()
  ]

Spread out each item in the list vertically to cover the assigned height Items are spread evenly centered on their horizontal axis No overlap is allowed and items push each other down

Options:

  • :y from which y position to start the spread, default 0
  • :gap the minimum gap between items, default 0
  • :rows the number of rows to spread items in, you can select a bigger number than the number of items, default length(items)

Visual

                                       
                                       |
                        *---*          |
                    ----|   |------    |
                        *---*          |
                                       |
*---*-*-*                              |
|   | | |               *-----*        |
*---* | |    ->         |     |        |
|     | |           ----|     |----  height
*-----* |               |     |        |
|       |               *-----*        |
*-------*               *-------*      |
                        |       |      |
                        |       |      |
                    ----|       |--    |
                        |       |      |
                        |       |      |
                        *-------*      

Examples

iex(1)> spread_vertical([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], 9)
[
  %RectLayout.Rect{x: 0, y: 1.0, width: 1, height: 1},
  %RectLayout.Rect{x: 1, y: 3.5, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 6.0, width: 3, height: 3}
]

iex(2)> spread_vertical([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], 6, gap: 2)
[
  %RectLayout.Rect{x: 0, y: 0.5, width: 1, height: 1},
  %RectLayout.Rect{x: 1, y: 3.5, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 7.5, width: 3, height: 3}
]

iex(3)> spread_vertical([rect(1, 1, 0, 0), rect(2, 2, 1, 1), rect(3, 3, 2, 2)], 9, y: 2)
[
  %RectLayout.Rect{x: 0, y: 3.0, width: 1, height: 1},
  %RectLayout.Rect{x: 1, y: 5.5, width: 2, height: 2},
  %RectLayout.Rect{x: 2, y: 8.0, width: 3, height: 3}
]

iex(4)> spread_vertical([rect(1, 1, 0, 0), rect(2, 2, 1, 1)], 9, rows: 3)
[
  %RectLayout.Rect{x: 0, y: 1.0, width: 1, height: 1},
  %RectLayout.Rect{x: 1, y: 3.5, width: 2, height: 2},
]
@spec sprite(RectLayout.Rect.t(), any()) :: RectLayout.Sprite.t()

Creates an %RectLayout.Sprite{}, which is used to track external data for a rect.

Examples

iex(1)> image = "my image"
"my image"
iex(2)> sprite(rect(10, 20), image)
%RectLayout.Sprite{
  rect: %RectLayout.Rect{x: 0, y: 0, width: 10, height: 20},
  content: "my image"
}
@spec sprite_content(RectLayout.Sprite.t()) :: any()

Get or update the content of a sprite.

## Examples

iex(1)> s = sprite(rect(10, 20), "one")
iex(2)> sprite_content(s)
"one"
iex(3)> sprite_content(s, "two")
%RectLayout.Sprite{
  rect: %RectLayout.Rect{x: 0, y: 0, width: 10, height: 20},
  content: "two"
}
Link to this function

sprite_content(sprite, content)

View Source
@spec sprite_content(RectLayout.Sprite.t(), any()) :: RectLayout.Sprite.t()
@spec surrounding_rect([RectLayout.Object.t()]) :: RectLayout.Rect.t()

Create a rectangle that surrounds all the items in the list

Visual

*---*----*
|   |    |
*---*    |
|    *---*
|    |   |
*----*---*

Examples

iex(1)> surrounding_rect([rect(2, 2), rect(2, 2, 2, 2)])
%RectLayout.Rect{x: 0, y: 0, width: 4, height: 4}
Link to this function

threshold_bottom(item, value)

View Source
@spec threshold_bottom(RectLayout.Object.t(), number()) :: RectLayout.Object.t()

Push item to the top of a given line. If the line is before it, don't do anything

Visual

 *---*      *---*
-|---|- ->  |   |
 *---*     -*---*-

Examples

iex(1)> threshold_bottom(rect(2, 2), 5)
%RectLayout.Rect{x: 0, y: 0, width: 2, height: 2}

iex(2)> threshold_bottom(rect(2, 2, 0, 5), 4)
%RectLayout.Rect{x: 0, y: 2, width: 2, height: 2}
Link to this function

threshold_left(item, value)

View Source
@spec threshold_left(RectLayout.Object.t(), number()) :: RectLayout.Object.t()

Push item to the right of a given line. If the line is before it, don't do anything

Visual

*|--*    |---*
||  | -> |   |
*|--*    |---*

Examples

iex(1)> threshold_left(rect(2, 2), 1)
%RectLayout.Rect{x: 1, y: 0, width: 2, height: 2}

iex(2)> threshold_left(rect(2, 2, 5), 1)
%RectLayout.Rect{x: 5, y: 0, width: 2, height: 2}
Link to this function

threshold_right(item, value)

View Source
@spec threshold_right(RectLayout.Object.t(), number()) :: RectLayout.Object.t()

Push item to the left of a given line. If the line is before it, don't do anything

Visual

   |         |
*--|*    *---*
|  || -> |   |
*--|*    *---*
   |         |

Examples

iex(1)> threshold_right(rect(2, 2), 4)
%RectLayout.Rect{x: 0, y: 0, width: 2, height: 2}

iex(2)> threshold_right(rect(2, 2, 5), 4)
%RectLayout.Rect{x: 2, y: 0, width: 2, height: 2}
Link to this function

threshold_top(item, value)

View Source
@spec threshold_top(RectLayout.Object.t(), number()) :: RectLayout.Object.t()

Push item to the bottom of a given line. If the line is before it, don't do anything

Visual

 *---*     -*---*-
-|---|- ->  |   |
 *---*      *---*

Examples

iex(1)> threshold_top(rect(2, 2), 2)
%RectLayout.Rect{x: 0, y: 2, width: 2, height: 2}

iex(2)> threshold_top(rect(2, 2, 0, 5), 2)
%RectLayout.Rect{x: 0, y: 5, width: 2, height: 2}
@spec top([RectLayout.Object.t()]) :: number()

Get the topmost y of a list of items

Visual

--------- | | ---

     *---*
     |   |
     *---*

Examples

iex(1)> top([rect(2, 2), rect(2, 2, 2, 2)]) 0

@spec width(RectLayout.Object.t()) :: number()

Get the width attribute of the item. Shortcut for RectLayout.Object.width/1

Set the width attribute of the item. Shortcut for RectLayout.Object.width/2

@spec x(RectLayout.Object.t()) :: number()

Get the x attribute of the item. Shortcut for RectLayout.Object.x/1

Set the x attribute of the item. Shortcut for RectLayout.Object.x/2

@spec y(RectLayout.Object.t()) :: number()

Get the y attribute of the item. Shortcut for RectLayout.Object.y/1

Set the y attribute of the item. Shortcut for RectLayout.Object.y/2