6.4 KiB
druid.grid API
at /druid/base/static_grid.lua
Functions
- init
- on_style_change
- get_pos
- get_index
- get_index_by_node
- on_layout_change
- set_anchor
- refresh
- set_pivot
- add
- set_items
- remove
- get_size
- get_size_for
- get_borders
- get_all_pos
- set_position_function
- clear
- get_offset
- set_in_row
- set_item_size
- sort_nodes
Fields
- on_add_item
- on_remove_item
- on_change_items
- on_clear
- on_update_positions
- parent
- nodes
- first_index
- last_index
- anchor
- pivot
- node_size
- border
- in_row
- style
- node_pivot
init
grid:init(parent, element, [in_row])
- Parameters:
parent
(string|node): The GUI Node container, where grid's items will be placedelement
(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
grid:on_style_change(style)
- Parameters:
style
(druid.grid.style):
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 index for grid pos
-
Parameters:
pos
(vector3): The node position in the grid
-
Returns:
The
(number): 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
on_layout_change
grid:on_layout_change()
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()
Update grid content
set_pivot
grid:set_pivot([pivot])
- Parameters:
[pivot]
(any):
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
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
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:
The
(node): deleted gui node from grid
get_size
grid:get_size()
Return grid content size
- Returns:
The
(vector3): grid content size
get_size_for
grid:get_size_for([count])
- Parameters:
[count]
(any):
get_borders
grid:get_borders()
Return grid content borders
- Returns:
The
(vector4): grid content borders
get_all_pos
grid:get_all_pos()
Return array of all node positions
- Returns:
All
(vector3[]): 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:
Current
(druid.grid): 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:
Current
(druid.grid): grid instance
get_offset
grid:get_offset()
Return StaticGrid offset, where StaticGrid content starts.
- Returns:
The
(vector3): 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:
Current
(druid.grid): 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:
Current
(druid.grid): 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)
- 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)