Module StaticGrid
Component to handle placing components by row and columns.
Grid can anchor your elements, get content size and other
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[, is_instance=false]]]) |
Add new item to the grid |
remove(self, index[, shift_policy=SHIFT.RIGHT[, is_instance=false]]) |
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. |
style |
Component style params. |
-
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[, is_instance=false]]])
-
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)
- is_instance
boolean
If true, update node positions instantly
(default false)
-
remove(self, index[, shift_policy=SHIFT.RIGHT[, is_instance=false]])
-
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)
- is_instance
boolean
If true, update node positions instantly
(default false)
Returns:
Node
The deleted gui node from grid
-
get_size(self)
-
Return grid content size
Parameters:
Returns:
vector3
The grid content size
-
get_borders(self)
-
Return grid content borders
Parameters:
Returns:
vector3
The grid content borders
-
get_all_pos(self)
-
Return array of all node positions
Parameters:
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:
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
-
style
-
Component style params.
You can override this component styles params in druid styles table
or create your own style
Fields:
- IS_DYNAMIC_NODE_POSES
bool
If true, always center grid content as grid pivot sets
(default false)
-
on_add_item
-
On item add callback(self, node, index)
-
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_update_positions
-
On update item positions callback(self)
- on_update_positions
druid_event
-
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