Module Helper

Helper module with various usefull GUI functions.

Usage:

    local helper = require("druid.helper")
    helper.centrate_nodes(0, node_1, node_2)
    

Functions

helper.add_array(target, source) Add all elements from source array to the target array
helper.centrate_nodes(margin, ...) Centerate nodes by x position with margin.
helper.clamp(a, min, max) Clamp value between min and max
helper.contains(t, value) Check if value is in array and return index of it
helper.deepcopy(orig_table) Make a copy table with all nested tables
helper.distance(x1, y1, x2, y2) Calculate distance between two points
helper.get_border(node, offset) Distance from node position to his borders
helper.get_closest_stencil_node(node) Return closest non inverted clipping parent node for given node
helper.get_gui_scale() Get current GUI scale for each side
helper.get_pivot_offset(pivot) Get node offset for given GUI pivot.
helper.get_scaled_size(node) Get node size adjusted by scale
helper.get_scene_scale(node, include_passed_node_scale) Get cumulative parent's node scale
helper.get_screen_aspect_koef() Get current screen stretch multiplier for each side
helper.get_text_metrics_from_node(text_node) Get text metric from GUI node.
helper.insert_with_shift(array, any, index, shift_policy) Add value to array with shift policy
helper.is_mobile() Check if device is native mobile (Android or iOS)
helper.is_multitouch_supported() Check if device is mobile and can support multitouch
helper.is_web() Check if device is HTML5
helper.is_web_mobile() Check if device is HTML5 mobile
helper.lerp(a, b, t) Lerp between two values
helper.remove_with_shift(array, index, shift_policy) Remove value from array with shift policy
helper.round(num, num_decimal_places) Round number to specified decimal places
helper.sign(val) Return sign of value (-1, 0, 1)
helper.step(current, target, step) Move value from current to target value with step amount
helper.table_to_string(t) Simple table to one-line string converter


Functions

helper.add_array(target, source)
Add all elements from source array to the target array

Parameters:

  • target any[] Array to put elements from source
  • source any[] or nil The source array to get elements from

Returns:

    any[] The target array
helper.centrate_nodes(margin, ...)
Centerate nodes by x position with margin.

This functions calculate total width of nodes and set position for each node. The centrate will be around 0 x position.

Parameters:

  • margin number or nil Offset between nodes
  • ... Gui nodes
helper.clamp(a, min, max)
Clamp value between min and max

Parameters:

  • a number Value
  • min number Min value
  • max number Max value

Returns:

    number Clamped value
helper.contains(t, value)
Check if value is in array and return index of it

Parameters:

  • t table Array
  • value Value

Returns:

    number or nil Index of value or nil
helper.deepcopy(orig_table)
Make a copy table with all nested tables

Parameters:

  • orig_table table Original table

Returns:

    table Copy of original table
helper.distance(x1, y1, x2, y2)
Calculate distance between two points

Parameters:

  • x1 number First point x
  • y1 number First point y
  • x2 number Second point x
  • y2 number Second point y

Returns:

    number Distance
helper.get_border(node, offset)
Distance from node position to his borders

Parameters:

  • node node GUI node
  • offset vector3 or nil Offset from node position. Pass current node position to get non relative border values

Returns:

    vector4 Vector4 with border values (left, top, right, down)
helper.get_closest_stencil_node(node)
Return closest non inverted clipping parent node for given node

Parameters:

  • node node GUI node

Returns:

    node or nil The closest stencil node or nil
helper.get_gui_scale()
Get current GUI scale for each side

Returns:

  1. number scale_x
  2. number scale_y
helper.get_pivot_offset(pivot)
Get node offset for given GUI pivot.

Offset shown in [-0.5 .. 0.5] range, where -0.5 is left or bottom, 0.5 is right or top.

Parameters:

  • pivot number The gui.PIVOT_* constant

Returns:

    vector3 Vector offset with [-0.5..0.5] values
helper.get_scaled_size(node)
Get node size adjusted by scale

Parameters:

  • node node GUI node

Returns:

    vector3 Scaled size
helper.get_scene_scale(node, include_passed_node_scale)
Get cumulative parent's node scale

Parameters:

  • node node Gui node
  • include_passed_node_scale boolean or nil True if add current node scale to result

Returns:

    vector3 The scene node scale
helper.get_screen_aspect_koef()
Get current screen stretch multiplier for each side

Returns:

  1. number stretch_x
  2. number stretch_y
helper.get_text_metrics_from_node(text_node)
Get text metric from GUI node.

Parameters:

  • text_node node

Returns:

    GUITextMetrics

Usage:

    type GUITextMetrics = {
      width: number,
      height: number,
      max_ascent: number,
      max_descent: number
    }
helper.insert_with_shift(array, any, index, shift_policy)
Add value to array with shift policy Shift policy can be: left, right, no_shift

Parameters:

  • array table Array
  • any Item to insert
  • index number or nil Index to insert. If nil, item will be inserted at the end of array
  • shift_policy number or nil The druid_const.SHIFT.* constant

Returns:

    any Inserted item
helper.is_mobile()
Check if device is native mobile (Android or iOS)

Returns:

    boolean Is mobile
helper.is_multitouch_supported()
Check if device is mobile and can support multitouch

Returns:

    boolean Is multitouch supported
helper.is_web()
Check if device is HTML5

Returns:

    boolean Is web
helper.is_web_mobile()
Check if device is HTML5 mobile

Returns:

    boolean Is web mobile
helper.lerp(a, b, t)
Lerp between two values

Parameters:

  • a number First value
  • b number Second value
  • t number Lerp amount

Returns:

    number Lerped value
helper.remove_with_shift(array, index, shift_policy)
Remove value from array with shift policy Shift policy can be: left, right, no_shift

Parameters:

  • array table Array
  • index number or nil Index to remove. If nil, item will be removed from the end of array
  • shift_policy number or nil The druid_const.SHIFT.* constant

Returns:

    any Removed item
helper.round(num, num_decimal_places)
Round number to specified decimal places

Parameters:

  • num number Number
  • num_decimal_places number or nil Decimal places

Returns:

    number Rounded number
helper.sign(val)
Return sign of value (-1, 0, 1)

Parameters:

  • val number Value

Returns:

    number Sign
helper.step(current, target, step)
Move value from current to target value with step amount

Parameters:

  • current number Current value
  • target number Target value
  • step number Step amount

Returns:

    number New value
helper.table_to_string(t)
Simple table to one-line string converter

Parameters:

Returns:

    string
generated by LDoc TESTING Last updated 2015-01-01 12:00:00