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
|
2016-01-22 13:33:46 +00:00
|
|
|
set alignment.
|
2016-01-21 22:18:28 +00:00
|
|
|
- Elements are drawn from the top down (meaning child elements will always draw
|
2016-01-22 13:33:46 +00:00
|
|
|
on top of their parents).
|
2016-01-21 22:18:28 +00:00
|
|
|
|
|
|
|
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-22 13:33:46 +00:00
|
|
|
- `adjustSize(x, y)` - Adjusts element size by `x`/`y`.
|
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
|
|
|
|
2016-01-26 00:13:05 +00:00
|
|
|
Events:
|
|
|
|
|
|
|
|
If any of these is set as a function, they will be called when the appropriate
|
|
|
|
event happens.
|
|
|
|
|
|
|
|
- `mousepressed(button, x, y)` - Called the moment a mouse click starts, uses
|
|
|
|
the same values for `button` as [love.mousepressed][4], but the `x`/`y` are
|
|
|
|
relative to the element.
|
|
|
|
- `mousereleased(button, x, y)` - Called the moment a mouse click stops, uses
|
|
|
|
the same values for `button` as [love.mousepressed][4], but the `x`/`y` are
|
|
|
|
relative to the element.
|
|
|
|
- `clicked(button, x, y)` - Called when a mouse click stops if it started on the
|
|
|
|
same element. Uses the same values for `button` as [love.mousepressed][4], but
|
|
|
|
the `x`/`y` are relative to the element.
|
|
|
|
|
2016-01-20 22:34:25 +00:00
|
|
|
**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
|
|
|
|
2016-01-22 13:33:46 +00:00
|
|
|
(Elements are loaded from the `elements` directory, so place any custom ones in
|
|
|
|
there.)
|
|
|
|
|
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
|
|
|
|
2016-01-22 13:33:46 +00:00
|
|
|
`pop.box(parent, background)`
|
2016-01-20 22:34:25 +00:00
|
|
|
If `parent` not specified, uses `pop.window` (the top level element).
|
2016-01-22 13:33:46 +00:00
|
|
|
If `background` is not specified, doesn't draw anything.
|
|
|
|
|
|
|
|
Additional methods:
|
|
|
|
|
|
|
|
- `setBackground()` - Sets background, you can use any [supported Drawable][3].
|
|
|
|
- `getBackground()` - Returns current background, which may be any
|
|
|
|
[supported Drawable][3].
|
|
|
|
- `setColor(r, g, b, a)` - Sets background based on colors (`a` is alpha, and
|
|
|
|
optional).
|
|
|
|
- `getColor()` - Returns background color, or errors if the background is not a
|
|
|
|
color.
|
2016-01-20 22:34:25 +00:00
|
|
|
|
2016-01-25 21:46:21 +00:00
|
|
|
TODO Make it possible to just specify background?
|
2016-01-20 22:34:25 +00:00
|
|
|
|
2016-01-22 13:33:46 +00:00
|
|
|
## Text Element
|
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
|
|
|
|
2016-01-22 13:33:46 +00:00
|
|
|
`pop.text(parent, text, color)`
|
2016-01-20 22:34:25 +00:00
|
|
|
If `parent` not specified, uses `pop.window` (the top level element).
|
2016-01-22 13:33:46 +00:00
|
|
|
If `color` is not specified, uses white.
|
|
|
|
|
2016-01-25 21:46:21 +00:00
|
|
|
Overwritten methods:
|
2016-01-22 13:33:46 +00:00
|
|
|
|
|
|
|
- `setSize()` - Does not allow you to set the size, instead, it fixes the size
|
|
|
|
if it is incorrect (mostly for internal use).
|
2016-01-25 21:46:21 +00:00
|
|
|
|
|
|
|
Additional methods:
|
|
|
|
|
2016-01-22 13:33:46 +00:00
|
|
|
- `setText(text)` - Sets text and modifies size to fit.
|
|
|
|
- `getText()` - Returns text.
|
|
|
|
- `setFont()` - Sets [Font][2] and modifies size to fit. Note: Empty text will
|
|
|
|
have the height of the font (and presumably, a 0 width, size is based on
|
|
|
|
[Font][2] objects).
|
|
|
|
- `getFont()` - Returns the [Font][2] in use.
|
|
|
|
- `setColor(r, g, b, a)` - Sets text color (`a` is alpha, and optional).
|
|
|
|
- `getColor()` - Returns text color.
|
2016-01-20 22:34:25 +00:00
|
|
|
|
2016-01-25 21:46:21 +00:00
|
|
|
TODO Make it possible to just specify text, or just text and color?
|
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.
|
|
|
|
|
2016-01-25 21:46:21 +00:00
|
|
|
If you set `excludeUpdating` to `true` on any element, it and its children will
|
|
|
|
not be rendered.
|
|
|
|
|
2016-01-20 22:34:25 +00:00
|
|
|
[1]: ./Skins.md
|
2016-01-22 13:33:46 +00:00
|
|
|
[2]: https://love2d.org/wiki/Font
|
|
|
|
[3]: ./Drawables.md
|
2016-01-26 00:13:05 +00:00
|
|
|
[4]: https://love2d.org/wiki/love.mousepressed
|