Skip to content
Crutiatix edited this page Apr 29, 2017 · 4 revisions

A table containing attributes defining a behavior of the element when a mouse is holding it and moving.

By setting active to true in the drag attribute turn dragging on.

From there, you have many different possibilities for you to set up your own draggable element. In case you'd like to make a simple slider, for example, just create a draggable element with a fixed movement axis and two bounds. You can then retrieve the value of your slider/element using element:getHorizontalRange() and element:getVerticalRange(), which return normalized numbers (between 0 and 1). Make sure you've properly set up bounds before calling these methods. Please not that you can also (re)define bounds later with element:setDragBounds(bounds).

  • Attribute of:

  • Attributes:

    • active = [bool] (false) - Enable dragging.
    • fixed = [table] ({x=false,y=false}) - define if should be dragging in a given axis fixed or not
      • x = [bool] (false)
      • y = [bool] (false)
    • bounds = [table] (element position) - set dimensions of a line/box, in which is dragging allowed
      • x = [table]
        • [1] = [number] (element.x) - minimal / from horizontal position
        • [2] = [number] (element.x) - maximal / to horizontal position
      • y = [table]
        • [1] = [number] (element.y) - minimal / from vertical position
        • [2] = [number] (element.y) - maximal / to vertical position
      • relative = [bool] (false) - if true so bound's dimensions are translated acording to actual anchored element position
  • Functions:

    • element:horizontalRange
      • if arguments - set position of element between horizontal bounds defined as normalized number (0-1)
      • no arguments - return normalized number (0-1) of position of element between horizontal bounds
      • arguments:
        • [number] = in range 0 - 1
      • return:
        • [number] = in range 0 - 1
    • element:verticalRange
      • if arguments - set position of element between vertical bounds defined as normalized number (0-1)
      • no arguments - return normalized number (0-1) of position of element between vertical bounds
      • arguments:
        • [number] = in range 0 - 1
      • return:
        • [number] = in range 0 - 1
    • element:dragBounds
      • set boundaries of dragging. Same as attribute drag
      • arguments:
        • [table] = {x={min,max},y={min,max}}

Modifications:

  • v0.7.0
    • merged setHorizontalRange and getHorizontalRange to horizontalRange
    • merged setVerticalRange and getVerticalRange to verticalRange
    • renamed setDragBounds to dragBounds
  • v0.6.0
    • renamed enabled to active
Clone this wiki locally