at /druid/base/static_grid.lua
The component for manage the nodes position in the grid with various options
- init
- get_pos
- get_index_xy
- get_index
- get_index_by_node
- set_anchor
- refresh
- set_pivot
- add
- set_items
- remove
- get_items_count
- get_size
- get_size_for
- get_borders
- get_all_pos
- set_position_function
- clear
- get_offset
- set_in_row
- set_item_size
- sort_nodes
- 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
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 placedelement(node): Element prefab. Need to get it size[in_row](number|nil): How many nodes in row can be placed. By default 1
grid:get_pos(index)Return pos for grid node index
-
Parameters:
index(number): The grid element index
-
Returns:
position(vector3): Node position
grid:get_index_xy(x, y)Return grid index by content-local x, y. Inverse of get_pos + _get_dynamic_offset.
-
Parameters:
x(number):y(number):
-
Returns:
index(number): The node 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
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
grid:set_anchor(anchor)Set grid anchor. Default anchor is equal to anchor of grid parent node
- Parameters:
anchor(vector3): Anchor
grid:refresh()Instantly update the grid content
- Returns:
self(druid.grid): Current grid instance
grid:set_pivot(pivot)Set grid pivot
-
Parameters:
pivot(constant): The new pivot
-
Returns:
self(druid.grid): Current grid instance
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
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
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
grid:get_items_count()Return items count in grid
- Returns:
count(number): The items count in grid
grid:get_size()Return grid content size
- Returns:
size(vector3): The grid content size
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
grid:get_borders()Return grid content borders
- Returns:
borders(vector4): The grid content borders
grid:get_all_pos()Return array of all node positions
- Returns:
positions(vector3[]): All grid node positions
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
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
grid:get_offset()Return StaticGrid offset, where StaticGrid content starts.
- Returns:
offset(vector3): The StaticGrid offset
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
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
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
- 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)