mirror of
https://github.com/Insality/druid
synced 2025-06-26 18:07:46 +02:00
6.3 KiB
6.3 KiB
druid.layout API
at /druid/extended/layout.lua
Druid component to manage the layout of nodes, placing them inside the node size with respect to the size and pivot of each node.
Setup
Create layout component with druid: layout = druid:new_layout(node, layout_type)
Notes
- Layout can be horizontal, vertical or horizontal with wrapping
- Layout can resize parent node to fit content
- Layout can justify content
- Layout supports margins and padding
- Layout automatically updates when nodes are added or removed
- Layout can be manually updated by calling set_dirty()
Functions
- init
- update
- get_entities
- set_node_index
- set_margin
- set_padding
- set_dirty
- set_justify
- set_type
- set_hug_content
- add
- remove
- get_size
- get_content_size
- refresh_layout
- clear_layout
- get_node_size
- calculate_rows_data
- set_node_position
Fields
- node
- rows_data
- is_dirty
- entities
- margin
- padding
- type
- is_resize_width
- is_resize_height
- is_justify
- on_size_changed
- size
init
layout:init(node_or_node_id, layout_type)
layout_type:
| "horizontal"
| "vertical"
| "horizontal_wrap"
- Parameters:
node_or_node_id
(string|node): The node to manage the layout oflayout_type
("horizontal"|"horizontal_wrap"|"vertical"): The type of layout (horizontal, vertical, horizontal_wrap)
update
layout:update()
get_entities
layout:get_entities()
- Returns:
entities
(node[]): The entities to manage the layout of
set_node_index
layout:set_node_index(node, index)
-
Parameters:
node
(node): The node to set the index ofindex
(number): The index to set the node to
-
Returns:
self
(druid.layout): for chaining
set_margin
layout:set_margin([margin_x], [margin_y])
Set the margin of the layout
-
Parameters:
[margin_x]
(number|nil): The margin x[margin_y]
(number|nil): The margin y
-
Returns:
self
(druid.layout): Current layout instance
set_padding
layout:set_padding([padding_x], [padding_y], [padding_z], [padding_w])
-
Parameters:
[padding_x]
(number|nil): The padding x[padding_y]
(number|nil): The padding y[padding_z]
(number|nil): The padding z[padding_w]
(number|nil): The padding w
-
Returns:
self
(druid.layout): Current layout instance
set_dirty
layout:set_dirty()
- Returns:
self
(druid.layout): Current layout instance
set_justify
layout:set_justify(is_justify)
-
Parameters:
is_justify
(boolean):
-
Returns:
self
(druid.layout): Current layout instance
set_type
layout:set_type(layout_type)
layout_type:
| "horizontal"
| "vertical"
| "horizontal_wrap"
-
Parameters:
layout_type
("horizontal"|"horizontal_wrap"|"vertical"):
-
Returns:
self
(druid.layout): Current layout instance
set_hug_content
layout:set_hug_content(is_hug_width, is_hug_height)
-
Parameters:
is_hug_width
(boolean):is_hug_height
(boolean):
-
Returns:
self
(druid.layout): Current layout instance
add
layout:add(node_or_node_id)
Add node to layout
-
Parameters:
node_or_node_id
(string|node): node_or_node_id
-
Returns:
self
(druid.layout): Current layout instance
remove
layout:remove(node_or_node_id)
Remove node from layout
-
Parameters:
node_or_node_id
(string|node): node_or_node_id
-
Returns:
self
(druid.layout): for chaining
get_size
layout:get_size()
- Returns:
- `` (vector3):
get_content_size
layout:get_content_size()
- Returns:
- `` (number):
- `` (number):
refresh_layout
layout:refresh_layout()
- Returns:
self
(druid.layout): Current layout instance
clear_layout
layout:clear_layout()
- Returns:
self
(druid.layout): Current layout instance
get_node_size
layout:get_node_size(node)
-
Parameters:
node
(node):
-
Returns:
width
(number): The width of the nodeheight
(number): The height of the node
calculate_rows_data
layout:calculate_rows_data()
Calculate rows data for layout. Contains total width, height and rows info (width, height, count of elements in row)
- Returns:
- `` (druid.layout.rows_data):
set_node_position
layout:set_node_position(node, x, y)
-
Parameters:
node
(node):x
(number):y
(number):
-
Returns:
- `` (node):
Fields
- node (node): The node to manage the layout of
- rows_data (druid.layout.rows_data): Last calculated rows data
- is_dirty (boolean): True if layout needs to be updated
- entities (node[]): The entities to manage the layout of
- margin ({ x: number, y: number }): The margin of the layout
- padding (vector4): The padding of the layout
- type (string): The type of the layout
- is_resize_width (boolean): True if the layout should resize the width of the node
- is_resize_height (boolean): True if the layout should resize the height of the node
- is_justify (boolean): True if the layout should justify the nodes
- on_size_changed (event.on_size_changed): fun(self: druid.layout, size: vector3) The event triggered when the size of the layout is changed
- size (unknown)