README.md in whirled_peas-0.6.0 vs README.md in whirled_peas-0.7.0
- old
+ new
@@ -170,12 +170,17 @@
`WhirledPeas.configure` takes an optional template factory to build a loading screen. This instance must implement `#build` (taking no arguments). The template returned by that method will be painted while the event loop is waiting for frames. The factory method will be called once per refresh cycle, so it's possible to implement animation.
#### Building Blocks
-A template is created with `WhirledPeas.template`, which yields a `Composer` object for a `Box` and `BoxSettings`. The composer allows for attaching child elements and the settings for setting layout options.
+A template is created with `WhirledPeas.template`, which yields a `Composer` object for a `Box` and `BoxSettings`. The composer allows for attaching child elements and the settings for setting layout options. The following attributes of the template's settings will be overridden before it is rendered to ensure that it fills the screen exactly
+- `margin` - all margin will be set to 0
+- `width` - will be set to the screen's width
+- `height` - will be set to the screen's height
+- `sizing` - will be set `:border` to ensure the entire box fits on the screen and fills it entirely.
+
A `Composer` provides the following methods to add child elements, each of these takes an optional string argument that is set as the name of the element (which can be useful when debugging).
- `add_box` - yields a `Composer` for a `Box` and a `BoxSettings`, which will be added to the parent's children
- `add_grid` - yields a `Composer` for a `Grid` and a `GridSettings`, which will be added to the parent's children
- `add_text` - yields `nil` and a `TextSettings`, which will be added to the parent's children
@@ -237,62 +242,311 @@
#### Settings
Each element type has an associated settings type, which provide a custom set of options to format the output. Child settings will inherit from the parent, where applicable
The available settigs are
-| Setting | Description | Default | Availability | Inherited |
-| ------------ | ------------------------------------------------------------------------------- | ------- | --------------------- | -------------------- |
-| `align` | Justifies the content (allowed values: `:left`, `:center`, `:right`) | `:left` | `Box`, `Grid` | Yes |
-| `bg_color` | Background color (see [Colors](#colors)) | | `Box`, `Grid`, `Text` | Yes |
-| `bold` | `true` makes the font bold | `false` | `Box`, `Grid`, `Text` | Yes |
-| `border` | Set the border for the lements | none | `Box`, `Grid`, | Only style and color |
-| `color` | Foreground text color (see [Colors](#colors)) | | `Box`, `Grid`, `Text` | Yes |
-| `flow` | Flow to display child elements (see [Display Flow](#display-flow)) | `:l2r` | `Box`, `Grid` | Yes |
-| `height` | Override the calculated height of an element's content area | | `Box`, `Grid` | No |
-| `margin` | Set the (left, top, right, bottom) margin of the element | `0` | `Box`, `Grid` | No |
-| `num_cols` | Number of columns in the grid (must be set!) | | `Grid` | No |
-| `padding` | Set the (left, top, right, bottom) padding of the element | `0` | `Box`, `Grid` | No |
-| `position` | Set the (left, top) position of the element relative to parent content area | `0` | `Box`, `Grid` | No |
-| `scrollbar` | Display a scroll bar for vertical or horizontal scrolling | | `Box` | No |
-| `title_font` | Font used for "large" text (see [Large Text](#large-text), ignores `underline`) | | `Text` | No |
-| `underline` | `true` underlines the font | `false` | `Box`, `Grid`, `Text` | Yes |
-| `width` | Override the calculated width of an element's content area | | `Box`, `Grid` | No |
+| Setting | Description | Default | Availability | Inherited |
+| ------------ | -------------------------------------------------------------------------------- | ---------- | --------------------- | -------------------- |
+| `align` | Justifies the content in the horizontal direction | `:left` | `Box`, `Grid` | No |
+| `bg_color` | Background color (see [Colors](#colors)) | | `Box`, `Grid`, `Text` | Yes |
+| `bold` | `true` makes the font bold | `false` | `Box`, `Grid`, `Text` | Yes |
+| `border` | Set the border for the lements | none | `Box`, `Grid`, | Only style and color |
+| `color` | Foreground text color (see [Colors](#colors)) | | `Box`, `Grid`, `Text` | Yes |
+| `flow` | Flow to display child elements (see [Display Flow](#display-flow)) | `:l2r` | `Box`, `Grid` | No |
+| `height` | Override the calculated height of an element's content area | | `Box`, `Grid` | No |
+| `margin` | Set the (left, top, right, bottom) margin of the element | `0` | `Box`, `Grid` | No |
+| `num_cols` | Number of columns in the grid (must be set!) | | `Grid` | No |
+| `padding` | Set the (left, top, right, bottom) padding of the element | `0` | `Box`, `Grid` | No |
+| `position` | Set the (left, top) position of the element relative to parent content area | `0` | `Box`, `Grid` | No |
+| `scrollbar` | Display a scroll bar for vertical or horizontal scrolling | | `Box` | No |
+| `sizing` | Sizing model (`:content` or `:border`) used in conjunction with `width`/`hieght` | `:content` | `Box` | No |
+| `title_font` | Font used for "large" text (see [Large Text](#large-text), ignores `underline`) | | `Text` | No |
+| `underline` | `true` underlines the font | `false` | `Box`, `Grid`, `Text` | Yes |
+| `width` | Override the calculated width of an element's content area | | `Box`, `Grid` | No |
+| `valign` | Justifies the content in the vertical direction | `:top` | `Box`, `Grid` | No |
+##### Alignment
+
+The `align` setting takes one of several values
+
+- `:left` - align content starting at the leftmost edge of the container's content area
+
+```
+┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+┃[child 1][child 2][child 3] ┃
+┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
+```
+
+- `:right` - align content starting at the rightmost edge of the container's content area
+
+```
+┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+┃ [child 1][child 2][child 3]┃
+┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
+```
+
+- `:center` - align content starting in the horizontal center of the container's content area
+
+```
+┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+┃ [child 1][child 2][child 3] ┃
+┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
+```
+
+- `:between` - distribute children so there is equal space between children no space outside of the children
+
+```
+┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+┃[child 1] [child 2] [child 3]┃
+┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
+```
+
+- `:around` - distribute children so that they have equal spacing around them, space between two children is twice the space between an edge and a child.
+
+```
+┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+┃ [child 1] [child 2] [child 3] ┃
+┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
+```
+
+- `:evenly` - distribute children so there is even spacing between any two children (or space to the edge)
+
+```
+┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+┃ [child 1] [child 2] [child 3] ┃
+┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
+```
+
+The `valign` setting takes one of several values
+
+- `:top` - align content starting at the top of the container's content area
+
+```
+┏━━━━━━━━━┓
+┃[child 1]┃
+┃[child 2]┃
+┃[child 3]┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┗━━━━━━━━━┛
+```
+
+- `:bottom` - align content starting at the bottom of the container's content area
+
+```
+┏━━━━━━━━━┓
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃[child 1]┃
+┃[child 2]┃
+┃[child 3]┃
+┗━━━━━━━━━┛
+```
+
+- `:middle` - align content starting in the vertical middle of the container's content area
+
+```
+┏━━━━━━━━━┓
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃[child 1]┃
+┃[child 2]┃
+┃[child 3]┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┗━━━━━━━━━┛
+```
+
+- `:between` - distribute children so there is equal space between children no space outside of the children
+
+```
+┏━━━━━━━━━┓
+┃[child 1]┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃[child 2]┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃[child 3]┃
+┗━━━━━━━━━┛
+```
+
+- `:around` - distribute children so that they have equal spacing around them, space between two children is twice the space between an edge and a child.
+
+```
+┏━━━━━━━━━┓
+┃ ┃
+┃ ┃
+┃[child 1]┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃[child 2]┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃[child 3]┃
+┃ ┃
+┃ ┃
+┗━━━━━━━━━┛
+```
+
+- `:evenly` - distribute children so there is even spacing between any two children (or space to the edge)
+
+```
+┏━━━━━━━━━┓
+┃ ┃
+┃ ┃
+┃ ┃
+┃[child 1]┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃[child 2]┃
+┃ ┃
+┃ ┃
+┃ ┃
+┃[child 3]┃
+┃ ┃
+┃ ┃
+┃ ┃
+┗━━━━━━━━━┛
+```
+
##### Position
Position settings dictate the relative position from where the painter would have preferred to place the container. Negative numbers move the container left/up and positive numbers move it right/down. To set these values, use
- `set_position(left:, top:)`
+##### Sizing Model
+
+The sizing model determines how to interpret the `width` and `height` settings. The default sizing model is `:content`, which sets the width and height of the cotent area, whereas `:border` sets the width and height of the element inlcuding the padding and border and scroll bars.
+
+###### Examples
+
+In the examples below, the `~` character represents padding and would not be displayed in the acutal rendered screen.
+
+```ruby
+settings.width = 10
+settings.height = 3
+settings.set_padding(left: 3, top: 1, right: 3, bottom: 1)
+settings.full_border
+
+## Content sizing
+settings.sizing = :content
+
+# Results in the box
+#
+# ┏━━━━━━━━━━━━━━━━┓
+# ┃~~~~~~~~~~~~~~~~┃
+# ┃~~~1234567890~~~┃
+# ┃~~~1234567890~~~┃
+# ┃~~~1234567890~~~┃
+# ┃~~~~~~~~~~~~~~~~┃
+# ┗━━━━━━━━━━━━━━━━┛
+
+## Border sizing
+settings.sizing = :border
+
+# Results in the box
+#
+# ┏━━━━━━━━┓
+# ┃~~~12~~~┃
+# ┗━━━━━━━━┛
+```
+
+Notice that a box rendered with `:border` sizing would fit exactly in the content area of a box with the same `width` and `height` that is rendered with `:content` sizing. For containers with no padding and no border, the resulting size is the same for either sizing model.
+
##### Margin
Margin settings dictate the spacing on the outside (i.e. outside of the border) of each of the 4 sides of the container independently. To set these values, use
-- `set_margin(left:, top:, right:, bottom:)`
+- `set_margin(left:, top:, right:, bottom:, horiz:, vert:)` - set any combination of margin (note: setting `horiz` and `left`/`right` or setting `vert` and `top`/`bottom` is not allowed)
+- `margin.left=(value)` - set left margin
+- `margin.top=(value)` - set top margin
+- `margin.right=(value)` - set right margin
+- `margin.bottom=(value)` - set bottom margin
+- `margin.horiz=(value)` - set left and right margin to the same value
+- `margin.vert=(value)` - set top and bottom margin to the same value
Note: values cannot be negative
##### Padding
Padding settings dictate the spacing on the inside (i.e. inside of the border) of each of the 4 sides of the container independently. To set these values, use
-- `set_padding(left:, top:, right:, bottom:)`
+- `set_padding(left:, top:, right:, bottom:, horiz:, vert:)` - set any combination of padding (note: setting `horiz` and `left`/`right` or setting `vert` and `top`/`bottom` is not allowed)
+- `padding.left=(value)` - set left padding
+- `padding.top=(value)` - set top padding
+- `padding.right=(value)` - set right padding
+- `padding.bottom=(value)` - set bottom padding
+- `padding.horiz=(value)` - set left and right padding to the same value
+- `padding.vert=(value)` - set top and bottom padding to the same value
Note: values cannot be negative
##### Scrollbar
Scroll settings dictate whether the scrollbar will be shown when child content is larger the the container's viewport. A scrollbar adds a unit to the dimensions of a container (as opposed to overwriting the leftmost/bottommost padding)
-- `set_padding(horiz:, vert:)`
+- `set_scrollbar(horiz:, vert:)` - set both scrollbar settings
+- `scrollbar.horiz=(flag)` - show/hide the horizontal scrollbar
+- `scrollbar.vert=(flag)` - show/hide the vertical scrollbar
##### Border
The border settings consist of 6 boolean values (border are either width 1 or not shown), the 4 obvious values (`left`, `top`, `right`, and `bottom`) along with 2 other values for inner borders (`inner_horiz` and `inner_vert`) in a grid. A border also has a foreground color (defaults to `:white`) and a style. The background color is determined by the `bg_color` of the element. Border values can be set with
-- `set_border(left:, top:, right:, bottom:, inner_horiz:, inner_vert:, color:, style:)`
-- `full_border(style:, color:)`
+- `set_border(left:, top:, right:, bottom:, inner_horiz:, inner_vert:, color:, style:)` - set any combination of border settings
+- `full_border(style:, color:)` - set all borders to true and optionally set the style or color
+- `border.left=(flag)` - show/hide left border
+- `border.top=(flag)` - show/hide top border
+- `border.right=(flag)` - show/hide right border
+- `border.bottom=(flag)` - show/hide bottom border
+- `border.inner_horiz=(flag)` - show/hide inner horizontal border (dividing grid rows)
+- `border.inner_vert=(flag)` - show/hide inner vertical border (dividing grid columns)
+- `border.color=(flag)` - set the border color
+- `border.style=(flag)` - set the border style
Available border styles are
- `:bold` (default)
@@ -330,55 +584,73 @@
- `:l2r` left-to-right
```
# In a Box
-[child 1] [child 2] ... [child N]
+┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+┃[child 1] [child 2] ... [child N]┃
+┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
# In a Grid
-[child 1] [child 2] [child 3]
-[chiid 4] [child 5]
+┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
+┃[child 1]┃[child 2]┃[child 3]┃
+┣━━━━━━━━━╋━━━━━━━━━╋━━━━━━━━━┫
+┃[chiid 4]┃[child 5]┃ ┃
+┗━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┛
```
- `:r2l` right-to-left
```
# In a Box
-[child N] [child N - 1] ... [child 1]
+┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+┃[child N] [child N - 1] ... [child 1]┃
+┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
# In a Grid
-[child 3] [child 2] [child 1]
- [chiid 5] [child 4]
+┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
+┃[child 3]┃[child 2]┃[child 1]┃
+┣━━━━━━━━━╋━━━━━━━━━╋━━━━━━━━━┫
+┃ ┃[chiid 5]┃[child 4]┃
+┗━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┛
```
- `:t2b` top-to-bottom
```
# In a Box
-[child 1]
-[child 2]
- ...
-[child N]
+┏━━━━━━━━━┓
+┃[child 1]┃
+┃[child 2]┃
+┃ ... ┃
+┃[child N]┃
+┗━━━━━━━━━┛
# In a Grid
-[child 1] [child 4]
-[child 2] [child 5]
-[child 3]
+┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
+┃[child 1]┃[child 3]┃[child 5]┃
+┣━━━━━━━━━╋━━━━━━━━━╋━━━━━━━━━┫
+┃[child 2]┃[child 4]┃ ┃
+┗━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┛
```
- `:b2t` bottom-to-top
```
# In a Box
-[child N]
-[child N - 1]
- ...
-[child 1]
+┏━━━━━━━━━━━━━┓
+┃[child N] ┃
+┃[child N - 1]┃
+┃ ... ┃
+┃[child 1] ┃
+┗━━━━━━━━━━━━━┛
# In a Grid
-[child 3]
-[child 2] [child 5]
-[child 1] [child 4]
+┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
+┃[child 2]┃[child 4]┃ ┃
+┣━━━━━━━━━╋━━━━━━━━━╋━━━━━━━━━┫
+┃[child 1]┃[child 3]┃[child 5]┃
+┗━━━━━━━━━┻━━━━━━━━━┻━━━━━━━━━┛
```
##### Colors
Below is the list of available colors (for both foreground and background)