2016-01-20 22:34:25 +00:00
|
|
|
# Elements
|
|
|
|
|
2016-01-21 22:18:28 +00:00
|
|
|
Elements are the core of Pop.Box.
|
|
|
|
|
|
|
|
- Elements are arranged hierarchically.
|
|
|
|
- When an element is moved, its child elements move with it.
|
|
|
|
- When an element is resized, it resizes in a way that makes sense based on its
|
|
|
|
alignment.
|
|
|
|
- Elements are drawn from the top down (meaning child elements will always draw
|
|
|
|
on top of their parents.)
|
|
|
|
|
|
|
|
The alignment stuff is much easier explained by experimenting or running the
|
|
|
|
demo, please check it out!
|
|
|
|
|
2016-01-20 22:34:25 +00:00
|
|
|
All elements have the following standard methods:
|
|
|
|
|
2016-01-21 22:18:28 +00:00
|
|
|
- `move(x, y)` - Moves the element by `x`/`y`.
|
2016-01-20 22:34:25 +00:00
|
|
|
- `setPosition(x, y)` - Sets the `x`/`y` position based on current alignment.
|
|
|
|
- `getPosition()` - Returns `x` and `y` position based on current alignment.
|
|
|
|
- `setSize(x, y)` - Sets the witdh/height of the element. Will stretch based on
|
2016-01-21 22:18:28 +00:00
|
|
|
alignment (run the demo to see an example).
|
2016-01-20 22:34:25 +00:00
|
|
|
- `getSize()` - Returns width and height of the element.
|
2016-01-21 22:18:28 +00:00
|
|
|
- `align(horizontal, vertical)` - Sets alignment based on the parent's position
|
|
|
|
and size. Valid `horizontal` strings: `left`, `center`, `right`. Valid
|
|
|
|
`vertical` strings: `top`, `center`, `bottom`.
|
|
|
|
- `alignTo(element, horizontal, vertical)` - Sets alignment based on an
|
|
|
|
element's position and size. Same `horizontal`/`vertical` strings as `align()`
|
|
|
|
- `setAlignment(horizontal, vertical)` - Sets alignment *values* to this, but
|
|
|
|
does not move the element. Same `horizontal`/`vertical` strings as `align()`
|
2016-01-20 22:34:25 +00:00
|
|
|
- `setSkin(skin)` - Sets the skin (see [Skins.md][1]) used for this element.
|
|
|
|
|
|
|
|
**Note**! Calls to `align()`, `alignTo()`, and `setAlignment()` change what
|
2016-01-21 22:18:28 +00:00
|
|
|
positions will be returned, and how positioning and resizing will work. Run the
|
|
|
|
demo to see how these affect things.
|
2016-01-20 22:34:25 +00:00
|
|
|
|
|
|
|
## Box Element
|
|
|
|
|
2016-01-21 22:18:28 +00:00
|
|
|
Box is the simplest element, a rectangular area.
|
2016-01-20 22:34:25 +00:00
|
|
|
|
|
|
|
`pop.box(parent, skin)`
|
|
|
|
If `parent` not specified, uses `pop.window` (the top level element).
|
|
|
|
If `skin` is not specified, uses `pop.currentSkin` (see [Skins.md][1]).
|
|
|
|
|
|
|
|
TODO Make it possible to just specify skin?
|
|
|
|
|
2016-01-21 22:18:28 +00:00
|
|
|
## Text Element (NOT DEFINED YET!)
|
2016-01-20 22:34:25 +00:00
|
|
|
|
2016-01-21 22:18:28 +00:00
|
|
|
Text is used to draw text.
|
2016-01-20 22:34:25 +00:00
|
|
|
|
|
|
|
`pop.text(parent, text, skin)`
|
|
|
|
If `parent` not specified, uses `pop.window` (the top level element).
|
|
|
|
If `skin` is not specified, uses `pop.currentSkin` (see [Skins.md][1]).
|
|
|
|
|
|
|
|
TODO Make it possible to just specify text, or just text and skin?
|
2016-01-21 22:18:28 +00:00
|
|
|
TODO Make it possible to use setting size on text to actually calculate what
|
|
|
|
font size will make that work?
|
2016-01-20 22:34:25 +00:00
|
|
|
|
|
|
|
# Excluding Movement/Rendering
|
|
|
|
|
|
|
|
If you set `excludeMovement` to `true` on any element, it and its children will
|
|
|
|
not be moved unless its own movement methods are used.
|
|
|
|
|
|
|
|
If you set `excludeRendering` to `true` on any element, it and its children will
|
|
|
|
not be rendered.
|
|
|
|
|
|
|
|
[1]: ./Skins.md
|