# druid.grid API > at /druid/base/static_grid.lua ## Functions - [init](#init) - [on_style_change](#on_style_change) - [get_pos](#get_pos) - [get_index](#get_index) - [get_index_by_node](#get_index_by_node) - [on_layout_change](#on_layout_change) - [set_anchor](#set_anchor) - [refresh](#refresh) - [set_pivot](#set_pivot) - [add](#add) - [set_items](#set_items) - [remove](#remove) - [get_size](#get_size) - [get_size_for](#get_size_for) - [get_borders](#get_borders) - [get_all_pos](#get_all_pos) - [set_position_function](#set_position_function) - [clear](#clear) - [get_offset](#get_offset) - [set_in_row](#set_in_row) - [set_item_size](#set_item_size) - [sort_nodes](#sort_nodes) ## Fields - [on_add_item](#on_add_item) - [on_remove_item](#on_remove_item) - [on_change_items](#on_change_items) - [on_clear](#on_clear) - [on_update_positions](#on_update_positions) - [parent](#parent) - [nodes](#nodes) - [first_index](#first_index) - [last_index](#last_index) - [anchor](#anchor) - [pivot](#pivot) - [node_size](#node_size) - [border](#border) - [in_row](#in_row) - [style](#style) - [node_pivot](#node_pivot) ### init --- ```lua grid:init(parent, element, [in_row]) ``` - **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 ### on_style_change --- ```lua grid:on_style_change(style) ``` - **Parameters:** - `style` *(druid.grid.style)*: ### get_pos --- ```lua grid:get_pos(index) ``` Return pos for grid node index - **Parameters:** - `index` *(number)*: The grid element index - **Returns:** - `position` *(vector3)*: Node position ### get_index --- ```lua grid:get_index(pos) ``` Return index for grid pos - **Parameters:** - `pos` *(vector3)*: The node position in the grid - **Returns:** - `The` *(number)*: node index ### get_index_by_node --- ```lua 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 ### on_layout_change --- ```lua grid:on_layout_change() ``` ### set_anchor --- ```lua grid:set_anchor(anchor) ``` Set grid anchor. Default anchor is equal to anchor of grid parent node - **Parameters:** - `anchor` *(vector3)*: Anchor ### refresh --- ```lua grid:refresh() ``` Update grid content ### set_pivot --- ```lua grid:set_pivot([pivot]) ``` - **Parameters:** - `[pivot]` *(any)*: ### add --- ```lua 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 ### set_items --- ```lua 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 ### remove --- ```lua 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:** - `The` *(node)*: deleted gui node from grid ### get_size --- ```lua grid:get_size() ``` Return grid content size - **Returns:** - `The` *(vector3)*: grid content size ### get_size_for --- ```lua grid:get_size_for([count]) ``` - **Parameters:** - `[count]` *(any)*: ### get_borders --- ```lua grid:get_borders() ``` Return grid content borders - **Returns:** - `The` *(vector4)*: grid content borders ### get_all_pos --- ```lua grid:get_all_pos() ``` Return array of all node positions - **Returns:** - `All` *(vector3[])*: grid node positions ### set_position_function --- ```lua 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:** - `Current` *(druid.grid)*: grid instance ### clear --- ```lua 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:** - `Current` *(druid.grid)*: grid instance ### get_offset --- ```lua grid:get_offset() ``` Return StaticGrid offset, where StaticGrid content starts. - **Returns:** - `The` *(vector3)*: StaticGrid offset ### set_in_row --- ```lua grid:set_in_row(in_row) ``` Set new in_row elements for grid - **Parameters:** - `in_row` *(number)*: The new in_row value - **Returns:** - `Current` *(druid.grid)*: grid instance ### set_item_size --- ```lua 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:** - `Current` *(druid.grid)*: grid instance ### sort_nodes --- ```lua 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_) - **on_remove_item** (_event_) - **on_change_items** (_event_) - **on_clear** (_event_) - **on_update_positions** (_event_) - **parent** (_node_) - **nodes** (_node[]_) - **first_index** (_number_) - **last_index** (_number_) - **anchor** (_vector3_) - **pivot** (_vector3_) - **node_size** (_vector3_) - **border** (_vector4_) - **in_row** (_number_) - **style** (_table_) - **node_pivot** (_unknown_)