Element functions
The following functions are defined within an element. Neither is called explicitly.
element = Gspot[elementtype](this, Gspot, label, pos, parent)Element constructor. See Elements
element:draw(pos)Draws element
this
.
Called by Gspot:draw()
The following functions are inherited from Gspot.util
element:setshape(shape)Sets
element.shape = shape or 'rect'
and sets element.pos.r
if not set.
element:drawshape(pos)Draws element's shape based on
element.shape
and pos
element:rect(mode) element.rect(pos, mode)A shortcut to
love.graphics.rectangle(mode, element.pos.x, element.pos.y, element.pos.w, element.pos.h)
or love.graphics.rectangle(mode, pos.x, pos.y, pos.w, pos.h)
element:setimage(img) element:setimage()Loads image
img or element.img
using love.graphics.newImage(img)
and returns the resulting image.
Called by Gspot:element()
element:drawimage()Draws the element's image, positioned relative to the element, preserving colour and transparency.
element:setfont(font, size) element:setfont(size) element:setfont()Loads font
font or element.style.font
using love.graphics.newFont(font, size)
or love.graphics.newFont(size)
and sets element.style.font.
If no parameters are set, clones Called by <code>Gspot.text.load()
element:getpos()Returns a new pos representing
element
's absolute position.
element:withinrect(rect) element.withinrect(pos, rect) element.withinrect(element, rect)Returns
True
if point pos.x, pos.y
or element.pos.x, element.pos.y
lies within the bounds of rect or rect.pos.
Returns False
otherwise.
element:containstpoint(point)Where point is a table containing at least x, y.
Returns true if point falls within the bounds of element's shape.
element:withinrect(point)
Where rect is a table containing at least x, y, w, h.
Returns true if point falls within the bounds of rectangle rect.
element:getdist(target) element.getdist(pos, target) element.getdist(element, target)Returns the distance between points
pos.x, pos.y
or element.pos.x, element.pos.y
and target.x, target.y
or target.pos.x, target.pos.y
.
element:withinradius(radius) element.withinradius(pos, radius) element.withinradius(element, radius)Returns
True
if point pos.x, pos.y
or element.pos.x, element.pos.y
lies within radius.r
of point radius.x, radius.y or radius.pos.x, radius.pos.y.
Returns False
otherwise.
element:getparent()Returns the topmost element (lowest in draw order) of
element
's heirarchy, or element
if element
has no parent.
element:getmaxh()Returns the accrued height of element's children.
element:getmaxw()Returns the accrued width of element's children.
element:addchild(child, autostack)Adds
child
to element.children
, sets child.parent
to element
, and re-assigns child.style
's inheritance.
If autostack
is a number, stacks child this many across, before starting a new line.
If autostack
is "grid", stacks child across, limiting to element.pos.w before starting a new line.
If autostack
is "horizontal" or "vertical", stacks child beside or below element.children, excluding element.scroller
.
element:remchild(child)Removes
child
from element.children
sets child.parent
to nil
, adjusts child.pos
to maintain its absolute positioning, and re-assigns child.style
's inheritance to Gspot.style
without changing values.
element:replace(replacement)Replaces
element
with replacement
, at the same level in the draw order.
element:getlevel()Returns element's position in the draw order, lower values being drawn first.
element:setlevel(level)Shifts element and it's children to
level
in the draw order.
If not level
, brings element
and its children to the top, placing them last in draw order, in their proper order.
element:show()Sets
element.display
to True
, so it will be drawn and respond to input.
Repeats this process for all elements lower down in the element heirarchy.
element:hide()Sets
element.display
to False
, so it will no longer be drawn or respond to input.
Repeats this process for all elements lower down in the element heirarchy.
element:focus()Gives
element
focus, allowing it to accept keyboard input.
Use Gspot:unfocus()
to unset focus. See Gspot functions