# Defold Druid UI Library

# Module `StaticGrid`

Component to handle placing components by row and columns.

Grid can anchor your elements, get content size and other

## Functions

init(self, parent, element[, in_row=1]) | Component init function
get_pos(self, index) | Return pos for grid node index
get_index(self, pos) | Return index for grid pos
get_index_by_node(self, node) | Return grid index by node
set_anchor(self, anchor) | Set grid anchor.
add(self, item[, index[, shift_policy=SHIFT.RIGHT]]) | Add new item to the grid
remove(self, index[, shift_policy=SHIFT.RIGHT]) | Remove the item from the grid.
get_size(self) | Return grid content size
get_borders(self) | Return grid content borders
get_all_pos(self) | Return array of all node positions
set_position_function(self, callback) | Change set position function for grid nodes.
clear(self) | Clear grid nodes array.
get_offset(self) | Return StaticGrid offset, where StaticGrid content starts.

## Fields

on_add_item | On item add callback(self, node, index)
on_remove_item | On item remove callback(self, index)
on_change_items | On item add or remove callback(self, index)
on_clear | On grid clear callback(self)
on_update_positions | On update item positions callback(self)
parent | Parent gui node
nodes | List of all grid nodes
first_index | The first index of node in grid
last_index | The last index of node in grid
anchor | Item anchor
node_size | Item size
border | The size of item content

## Functions

init(self, parent, element[, in_row=1])
  Component init function

  ### Parameters:

  - self StaticGrid
  - parent node The gui node parent, where items will be placed
  - element node Element prefab. Need to get it size
  - in_row number How many nodes in row can be placed (default 1)
get_pos(self, index)
  Return pos for grid node index

  ### Parameters:

  - self StaticGrid
  - index number The grid element index

  ### Returns:

  vector3 Node position
get_index(self, pos)
  Return index for grid pos

  ### Parameters:

  - self StaticGrid
  - pos vector3 The node position in the grid

  ### Returns:

  number The node index
get_index_by_node(self, node)
  Return grid index by node

  ### Parameters:

  - self StaticGrid
  - node node The gui node in the grid

  ### Returns:

  number The node index
set_anchor(self, anchor)
  Set grid anchor. Default anchor is equal to anchor of grid parent node

  ### Parameters:

  - self StaticGrid
  - anchor vector3 Anchor
add(self, item[, index[, shift_policy=SHIFT.RIGHT]])
  Add new item to the grid

  ### Parameters:

  - self StaticGrid
  - item node Gui node
  - index number The item position. By default add as last item (optional)
  - shift_policy number How shift nodes, if required. See const.SHIFT (default SHIFT.RIGHT)
remove(self, index[, shift_policy=SHIFT.RIGHT])
  Remove the item from the grid. Note that gui node will be not deleted

  ### Parameters:

  - self StaticGrid
  - index number The grid node index to remove
  - shift_policy number How shift nodes, if required. See const.SHIFT (default SHIFT.RIGHT)

  ### Returns:

  Node The deleted gui node from grid
get_size(self)
  Return grid content size

  ### Parameters:

  - self StaticGrid

  ### Returns:

  vector3 The grid content size
get_borders(self)
  Return grid content borders

  ### Parameters:

  - self StaticGrid

  ### Returns:

  vector3 The grid content borders
get_all_pos(self)
  Return array of all node positions

  ### Parameters:

  - self StaticGrid

  ### Returns:

  vector3[] All grid node positions
set_position_function(self, callback)
  Change set position function for grid nodes. It will call on update poses on grid elements. Default: gui.set_position

  ### Parameters:

  - self StaticGrid
  - callback function Function on node set position

  ### Returns:

  druid.static_grid Current grid instance
clear(self)
  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

  ### Parameters:

  - self StaticGrid

  ### Returns:

  druid.static_grid Current grid instance
get_offset(self)
  Return StaticGrid offset, where StaticGrid content starts.

  ### Parameters:

  - self StaticGrid The StaticGrid instance

  ### Returns:

  vector3 The StaticGrid offset

## Fields

on_add_item
  On item add callback(self, node, index)
  - on_add_item druid_event
on_remove_item
  On item remove callback(self, index)
  - on_remove_item druid_event
on_change_items
  On item add or remove callback(self, index)
  - on_change_items druid_event
on_clear
  On grid clear callback(self)
  - on_clear druid_event
on_update_positions
  On update item positions callback(self)
  - on_update_positions druid_event
parent
  Parent gui node
  - parent node
nodes
  List of all grid nodes
  - nodes node[]
first_index
  The first index of node in grid
  - first_index number
last_index
  The last index of node in grid
  - last_index number
anchor
  Item anchor
  - anchor vector3
node_size
  Item size
  - node_size vector3
border
  The size of item content
  - border vector4

generated by LDoc 1.4.6 Last updated 2021-04-06 00:03:14