-
-
Module StaticGrid
-
Component to handle component's position by row and columns.
-
- # Overview #
-
The Static Grid component allows for positioning components in rows and columns.
- It provides a static grid layout with constant node sizes, allowing for pre-calculated
- node positions and the option to include gaps between nodes.
-
# Notes #
-
• In a static grid, the node size remains constant, enabling the calculation of node
- positions before placement. If you want add gaps between nodes, increase the root prefab size,
- including the padding and margin.
-
• The static grid can automatically shift elements when nodes are added or removed.
-
• When a node is added, the grid will set the node's parent to the specified parent_node.
-
• You can obtain an array of positions for each element, which can be used to set
- points of interest in a scroll component.
-
• The size of all elements can be retrieved for setting up the size in a scroll component.
-
• The grid can be bound to a scroll component for automatic resizing of the scroll content size.
-
• The pivot of the parent_node affects the node placement within the grid.
-
• A prefab node is used to determine the node size and anchor.
-
• You can specify a position_function for animations using the
- _static_grid:set_position_function(node, pos) callback. The default position function is gui.set_position().
-
Example Link
-
-
-
-
-
- add(self, item, index, shift_policy, is_instant) |
- Add new item to the grid |
-
-
- clear(self) |
- Clear grid nodes array. |
-
-
- get_all_pos(self) |
- Return array of all node positions |
-
-
- get_borders(self) |
- Return grid content borders |
-
-
- get_index(self, pos) |
- Return index for grid pos |
-
-
- get_index_by_node(self, node) |
- Return grid index by node |
-
-
- get_offset(self) |
- Return StaticGrid offset, where StaticGrid content starts. |
-
-
- get_pos(self, index) |
- Return pos for grid node index |
-
-
- get_size(self) |
- Return grid content size |
-
-
- init(self, parent, element, in_row) |
- The StaticGrid constructor |
-
-
- refresh(self) |
- Update grid content |
-
-
- remove(self, index, shift_policy, is_instant) |
- Remove the item from the grid. |
-
-
- set_anchor(self, anchor) |
- Set grid anchor. |
-
-
- set_in_row(self, in_row) |
- Set new in_row elements for grid |
-
-
- set_item_size(self[, width[, height]]) |
- Set new node size for grid |
-
-
- set_items(self, nodes[, is_instant=false]) |
- Set new items to the grid. |
-
-
- set_position_function(self, callback) |
- Change set position function for grid nodes. |
-
-
- sort_nodes(self, comparator) |
- Sort grid nodes by custom comparator function |
-
-
-
-
-
- style |
- Component style params. |
-
-
-
-
-
- anchor |
- Item anchor [0..1] |
-
-
- border |
- The size of item content |
-
-
- first_index |
- The first index of node in grid |
-
-
- last_index |
- The last index of node in grid |
-
-
- node_size |
- Item size |
-
-
- nodes |
- List of all grid nodes |
-
-
- on_add_item |
- On item add callback(self, node, index) |
-
-
- on_change_items |
- On item add, remove or change in_row callback(self, index|nil) |
-
-
- on_clear |
- On grid clear callback(self) |
-
-
- on_remove_item |
- On item remove callback(self, index) |
-
-
- on_update_positions |
- On update item positions callback(self) |
-
-
- parent |
- Parent gui node |
-
-
- pivot |
- Item pivot [-0.5..0.5] |
-
-
-
-
-
-
-
-
-
-
- -
-
- add(self, item, index, shift_policy, is_instant)
-
- -
- Add new item to the grid
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid
-
- - item
- node
- GUI node
-
- - index
- number or nil
- The item position. By default add as last item
-
- - shift_policy
- number or nil
- How shift nodes, if required. Default: const.SHIFT.RIGHT
-
- - is_instant
- boolean or nil
- If true, update node positions instantly
-
-
-
-
-
-
-
-
- -
-
- 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_all_pos(self)
-
- -
- Return array of all node positions
-
-
-
Parameters:
-
-
- Returns:
-
-
- vector3[]
- All grid node positions
-
-
-
-
-
-
- -
-
- get_borders(self)
-
- -
- Return grid content borders
-
-
-
Parameters:
-
-
- Returns:
-
-
- vector3
- The grid content borders
-
-
-
-
-
-
- -
-
- get_index(self, pos)
-
- -
- Return index for grid pos
-
-
-
Parameters:
-
- - self
- StaticGrid
- 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
- StaticGrid
-
- - node
- node
- The gui node in the grid
-
-
-
- Returns:
-
-
- number
- The node index
-
-
-
-
-
-
- -
-
- get_offset(self)
-
- -
- Return StaticGrid offset, where StaticGrid content starts.
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid The StaticGrid instance
-
-
-
- Returns:
-
-
- vector3
- The StaticGrid offset
-
-
-
-
-
-
- -
-
- get_pos(self, index)
-
- -
- Return pos for grid node index
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid
-
- - index
- number
- The grid element index
-
-
-
- Returns:
-
-
- vector3
- @Node position
-
-
-
-
-
-
- -
-
- get_size(self)
-
- -
- Return grid content size
-
-
-
Parameters:
-
-
- Returns:
-
-
- vector3
- The grid content size
-
-
-
-
-
-
- -
-
- init(self, parent, element, in_row)
-
- -
- The StaticGrid constructor
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid
-
- - parent
- string or node
- The GUI Node container, where grid's items will be placed
-
- - element
- node
- Element prefab. Need to get it size
-
- - in_row
- number or nil
- How many nodes in row can be placed. By default 1
-
-
-
-
-
-
-
-
- -
-
- refresh(self)
-
- -
- Update grid content
-
-
-
Parameters:
-
-
-
-
-
-
-
- -
-
- remove(self, index, shift_policy, is_instant)
-
- -
- Remove the item from the grid. Note that gui node will be not deleted
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid
-
- - index
- number
- The grid node index to remove
-
- - shift_policy
- number or nil
- How shift nodes, if required. Default: const.SHIFT.RIGHT
-
- - is_instant
- boolean or nil
- If true, update node positions instantly
-
-
-
- Returns:
-
-
- node
- The deleted gui node from grid
-
-
-
-
-
-
- -
-
- set_anchor(self, anchor)
-
- -
- Set grid anchor. Default anchor is equal to anchor of grid parent node
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid
-
- - anchor
- vector3
- Anchor
-
-
-
-
-
-
-
-
- -
-
- set_in_row(self, in_row)
-
- -
- Set new in_row elements for grid
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid
-
- - in_row
- number
- The new in_row value
-
-
-
- Returns:
-
-
- druid.static_grid
- Current grid instance
-
-
-
-
-
-
- -
-
- set_item_size(self[, width[, height]])
-
- -
- Set new node size for grid
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid
-
- - width
- number
- The new node width
- (optional)
-
- - height
- number
- The new node height
- (optional)
-
-
-
- Returns:
-
-
- druid.static_grid
- Current grid instance
-
-
-
-
-
-
- -
-
- set_items(self, nodes[, is_instant=false])
-
- -
- Set new items to the grid. All previous items will be removed
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid
-
- - nodes
- node[]
- The new grid nodes
-
- - is_instant
- boolean
- If true, update node positions instantly
- (default false)
-
-
-
-
-
-
-
-
- -
-
- 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
- StaticGrid
-
- - callback
- function
- Function on node set position
-
-
-
- Returns:
-
-
- druid.static_grid
- Current grid instance
-
-
-
-
-
-
- -
-
- sort_nodes(self, comparator)
-
- -
- Sort grid nodes by custom comparator function
-
-
-
Parameters:
-
- - self
- StaticGrid
- StaticGrid
-
- - comparator
- function
- The comparator function. (a, b) -> boolean
-
-
-
- Returns:
-
-
- druid.static_grid
- Current grid instance
-
-
-
-
-
-
-
-
-
-
- -
-
- 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
- boolean or nil
- If true, always center grid content as grid pivot sets. Default: false
-
- - IS_ALIGN_LAST_ROW
- boolean or nil
- If true, always align last row of the grid as grid pivot sets. Default: false
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
- anchor
-
- -
- Item anchor [0..1]
-
-
-
-
-
-
-
-
-
- -
-
- border
-
- -
- The size of item content
-
-
-
-
-
-
-
-
-
- -
-
- first_index
-
- -
- The first index of node in grid
-
-
-
- - first_index
- number
-
-
-
-
-
-
-
-
-
- -
-
- last_index
-
- -
- The last index of node in grid
-
-
-
- - last_index
- number
-
-
-
-
-
-
-
-
-
- -
-
- node_size
-
- -
- Item size
-
-
-
- - node_size
- vector3
-
-
-
-
-
-
-
-
-
- -
-
- nodes
-
- -
- List of all grid nodes
-
-
-
-
-
-
-
-
-
- -
-
- on_add_item
-
- -
- On item add callback(self, node, index)
-
-
-
-
-
-
-
-
-
- -
-
- on_change_items
-
- -
- On item add, remove or change in_row callback(self, index|nil)
-
-
-
-
-
-
-
-
-
- -
-
- on_clear
-
- -
- On grid clear callback(self)
-
-
-
-
-
-
-
-
-
- -
-
- on_remove_item
-
- -
- On item remove callback(self, index)
-
-
-
-
-
-
-
-
-
- -
-
- on_update_positions
-
- -
- On update item positions callback(self)
-
-
-
- - on_update_positions
- DruidEvent
- DruidEvent
-
-
-
-
-
-
-
-
- -
-
- parent
-
- -
- Parent gui node
-
-
-
-
-
-
-
-
-
- -
-
- pivot
-
- -
- Item pivot [-0.5..0.5]
-
-
-
-
-
-
-
-
-
-
-
-
-