Module Element

This is a description of what is expected in an element class.

IMPORTANT: Your class should inherit from the element class. This means that any methods defined on that class need to be compatible with or overridden by your class!

Note: The event handling functions only know about children of pop.screen or children of an element you have called Pop.Box's event handlers on.

Functions

load (pop) Optional: Called during pop.load() with a reference to Pop.Box.
wrap (pop) Optional: Called during pop.load() to allow a custom wrapper function to be created for your element class.
update (dt) Optional: Called from pop.update() if data.update.
draw () Optional: Called from pop.draw() if data.draw.
mousemoved (x, y, dx, dy) Optional: Called from pop.mousemoved() if in LOVE >= 0.10.0 and your element is focused.
mousepressed (x, y, button) Optional: Called from pop.mousepressed() if a mouse button was pressed over your element.
clicked (x, y, button) Optional: Called from pop.mousereleased() if a mouse button was pressed and then released over your element.
mousereleased (x, y, button) Optional: Called from pop.mousereleased() if a mouse button was released over your element.

Tables

data Every object has a data field with pre-defined values.

Fields

parent The parent element of this element.
child The child element(s) of this element.


Functions

load (pop)
Optional: Called during pop.load() with a reference to Pop.Box.

Parameters:

  • pop module The Pop.Box module.
wrap (pop)
Optional: Called during pop.load() to allow a custom wrapper function to be created for your element class.

Parameters:

  • pop module The Pop.Box module.

Returns:

    function wrapper A function to be called to create an element of this class instead of using pop.create().
update (dt)
Optional: Called from pop.update() if data.update. Use it for any time-based updates your element may need.

Parameters:

  • dt number The amount of time elapsed since update was last called.
draw ()
Optional: Called from pop.draw() if data.draw. Use it to draw your element.
mousemoved (x, y, dx, dy)
Optional: Called from pop.mousemoved() if in LOVE >= 0.10.0 and your element is focused.

Parameters:

  • x integer The x coordinate of the mouse relative to the element.
  • y integer The y coordinate of the mouse relative to the element.
  • dx number The distance on the x axis the mouse was moved.
  • dy number The distance on the y axis the mouse was moved.

Returns:

    boolean Was the event handled?
mousepressed (x, y, button)
Optional: Called from pop.mousepressed() if a mouse button was pressed over your element.

Note: Your element must be visible (data.draw is true) for this method to be called.

Parameters:

  • x integer The x coordinate of the mouse press relative to the element.
  • y integer The y coordinate of the mouse press relative to the element.
  • button string or integer The mouse button pressed. (Type varies by LÖVE version.)

Returns:

    boolean Was the event handled?
clicked (x, y, button)
Optional: Called from pop.mousereleased() if a mouse button was pressed and then released over your element.

Note: Your element must be visible (data.draw is true) for this method to be called.

Parameters:

  • x integer The x coordinate of the mouse click relative to the element.
  • y integer The y coordinate of the mouse click relative to the element.
  • button string or integer The mouse button clicked. (Type varies by LÖVE version.)

Returns:

    boolean Was the event handled?
mousereleased (x, y, button)
Optional: Called from pop.mousereleased() if a mouse button was released over your element.

Parameters:

  • x integer The x coordinate of the mouse release relative to the element.
  • y integer The y coordinate of the mouse release relative to the element.
  • button string or integer The mouse button released. (Type varies by LÖVE version.)

Returns:

    boolean Was the event handled?

Tables

data
Every object has a data field with pre-defined values. Any serializable data should be saved in this field. Ideally, any Pop.Box element can be reconstructed from its data field.

Fields:

  • parent table, false or nil The parent of this element's data field. This will not be serialized. This is the only exception to all data being serialized.
  • child table All child elements' data fields.
  • x integer The left edge of your element.
  • y integer The top edge of your element.
  • w integer The width of your element.
  • h integer The height of your element.
  • update boolean Whether or not to update this element (and its children).
  • draw boolean Whether or not to draw this element (and its children).

Fields

parent
The parent element of this element.
  • parent Element or false Parent element.
child
The child element(s) of this element.
  • child table All child elements.
generated by LDoc 1.4.3 Last updated 2016-10-30 23:39:49