Skip to content

Latest commit

 

History

History
387 lines (269 loc) · 7.16 KB

static_grid_api.md

File metadata and controls

387 lines (269 loc) · 7.16 KB

druid.grid API

at /druid/base/static_grid.lua

The component for manage the nodes position in the grid with various options

Functions

Fields

init


grid:init(parent, element, [in_row])

The constructor for the grid component

  • Parameters:
    • parent (string|node): The GUI Node container, where grid's items will be placed
    • element (node): Element prefab. Need to get it size
    • [in_row] (number|nil): How many nodes in row can be placed. By default 1

get_pos


grid:get_pos(index)

Return pos for grid node index

  • Parameters:

    • index (number): The grid element index
  • Returns:

    • position (vector3): Node position

get_index


grid:get_index(pos)

Return grid index by position

  • Parameters:

    • pos (vector3): The node position in the grid
  • Returns:

    • index (number): The node index

get_index_by_node


grid:get_index_by_node(node)

Return grid index by node

  • Parameters:

    • node (node): The gui node in the grid
  • Returns:

    • index (number|nil): The node index

set_anchor


grid:set_anchor(anchor)

Set grid anchor. Default anchor is equal to anchor of grid parent node

  • Parameters:
    • anchor (vector3): Anchor

refresh


grid:refresh()

Instantly update the grid content

  • Returns:
    • self (druid.grid): Current grid instance

set_pivot


grid:set_pivot(pivot)

Set grid pivot

  • Parameters:

    • pivot (constant): The new pivot
  • Returns:

    • self (druid.grid): Current grid instance

add


grid:add(item, [index], [shift_policy], [is_instant])

Add new item to the grid

  • Parameters:

    • item (node): GUI node
    • [index] (number|nil): The item position. By default add as last item
    • [shift_policy] (number|nil): How shift nodes, if required. Default: const.SHIFT.RIGHT
    • [is_instant] (boolean|nil): If true, update node positions instantly
  • Returns:

    • self (druid.grid): Current grid instance

set_items


grid:set_items(nodes, [is_instant])

Set new items to the grid. All previous items will be removed

  • Parameters:

    • nodes (node[]): The new grid nodes
    • [is_instant] (boolean|nil): If true, update node positions instantly
  • Returns:

    • self (druid.grid): Current grid instance

remove


grid:remove(index, [shift_policy], [is_instant])

Remove the item from the grid. Note that gui node will be not deleted

  • Parameters:

    • index (number): The grid node index to remove
    • [shift_policy] (number|nil): How shift nodes, if required. Default: const.SHIFT.RIGHT
    • [is_instant] (boolean|nil): If true, update node positions instantly
  • Returns:

    • node (node): The deleted gui node from grid

get_size


grid:get_size()

Return grid content size

  • Returns:
    • size (vector3): The grid content size

get_size_for


grid:get_size_for(count)

Return grid content size for given count of nodes

  • Parameters:

    • count (number): The count of nodes
  • Returns:

    • size (vector3): The grid content size

get_borders


grid:get_borders()

Return grid content borders

  • Returns:
    • borders (vector4): The grid content borders

get_all_pos


grid:get_all_pos()

Return array of all node positions

  • Returns:
    • positions (vector3[]): All grid node positions

set_position_function


grid:set_position_function(callback)

Change set position function for grid nodes. It will call on update poses on grid elements. Default: gui.set_position

  • Parameters:

    • callback (function): Function on node set position
  • Returns:

    • self (druid.grid): Current grid instance

clear


grid:clear()

Clear grid nodes array. GUI nodes will be not deleted! If you want to delete GUI nodes, use static_grid.nodes array before grid:clear

  • Returns:
    • self (druid.grid): Current grid instance

get_offset


grid:get_offset()

Return StaticGrid offset, where StaticGrid content starts.

  • Returns:
    • offset (vector3): The StaticGrid offset

set_in_row


grid:set_in_row(in_row)

Set new in_row elements for grid

  • Parameters:

    • in_row (number): The new in_row value
  • Returns:

    • self (druid.grid): Current grid instance

set_item_size


grid:set_item_size([width], [height])

Set new node size for grid

  • Parameters:

    • [width] (number|nil): The new node width
    • [height] (number|nil): The new node height
  • Returns:

    • self (druid.grid): Current grid instance

sort_nodes


grid:sort_nodes(comparator)

Sort grid nodes by custom comparator function

  • Parameters:

    • comparator (function): The comparator function. (a, b) -> boolean
  • Returns:

    • self (druid.grid): Current grid instance

Fields

  • on_add_item (event): fun(self: druid.grid, item: node, index: number) Trigger on add item event

  • on_remove_item (event): fun(self: druid.grid, index: number) Trigger on remove item event

  • on_change_items (event): fun(self: druid.grid, index: number) Trigger on change items event

  • on_clear (event): fun(self: druid.grid) Trigger on clear event

  • on_update_positions (event): fun(self: druid.grid) Trigger on update positions event

  • parent (node): Parent node

  • nodes (node[]): Nodes array

  • first_index (number): First index

  • last_index (number): Last index

  • anchor (vector3): Anchor

  • pivot (vector3): Pivot

  • node_size (vector3): Node size

  • border (vector4): Border

  • in_row (number): In row

  • style (druid.grid.style): Style

  • node_pivot (unknown)