Module button

Provides a clickable button.

This acts similar to a hotspot, with the exception you don't specify the size, which is automatically measured from the button text. It provides high flexibility as shown in switch-example.lua

Info:

  • License: GPL v3
  • Author: Wesley Werner

Functions

module:new (args) Creates a new instance.
module_mt:testFocus (x, y) Tests if a point is over the element.
module_mt:draw () Placeholder function.
module_mt:update (dt) Placeholder function.
module_mt:mousemoved (x, y, dx, dy, istouch) Process mouse/touch movement.
module_mt:mousepressed (x, y, button, istouch) Process pressed clicks/touches.
module_mt:mousereleased (x, y, button, istouch) Process click/touch releases.

Tables

args A table of arguments for new instances.
instance Lists properties available on the instance.


Functions

module:new (args)
Creates a new instance.

Parameters:

  • args args A table of arguments.

Returns:

    instance
module_mt:testFocus (x, y)
Tests if a point is over the element. Used internally by mousemoved

Parameters:

  • x number The x position to test against
  • y number The y position to test against

Returns:

    bool true if the point is over the element
module_mt:draw ()
Placeholder function. This element does not draw anything, this is user controlled
module_mt:update (dt)
Placeholder function. This element does not process any updates

Parameters:

  • dt number delta time as given by Love
module_mt:mousemoved (x, y, dx, dy, istouch)
Process mouse/touch movement. Call this from your main loop so the element knows when it has focus, which flags the "focused" property true.

Parameters:

  • x
  • y
  • dx
  • dy
  • istouch
module_mt:mousepressed (x, y, button, istouch)
Process pressed clicks/touches. Call this from your main loop so the element knows when it is pressed on, which flags the "down" property true.

Parameters:

  • x
  • y
  • button
  • istouch
module_mt:mousereleased (x, y, button, istouch)
Process click/touch releases. Call this from your main loop so the element knows when a press is released from it, which flags the "down" property false and fires the "callback" function if it is present.

Parameters:

  • x
  • y
  • button
  • istouch

Tables

args
A table of arguments for new instances. In addition to the mentioned parameters, you can add any other keys you want. All keys are copied to the instance, which allows you to access them later through the instance.

Fields:

  • left number The left screen position.
  • top number The top screen position.
  • callback function The function fired when this control has focus and click/touch is released on it.
  • text string The text of the button. This is measured (with the current font) to determine the element size.
instance
Lists properties available on the instance.

Fields:

  • focused bool true while the focus is over the button. This is determined while you call mousemoved
  • down bool true while a click/touch is pressed on the button. This is determined while you call mousepressed
  • left number The x position
  • top number The y position
  • width number The width of the element as calculated from the measured text
  • height number The height of the element as calculated from the measured text
  • callback function The function fired when this control has focus and click/touch is released on it.
generated by LDoc 1.4.6 Last updated 2018-01-03 16:24:23