Extension-Druid/api/components/base/component_api.md
2025-03-18 21:23:30 +02:00

7.1 KiB
Raw Blame History

druid.component API

at /druid/component.lua

Functions

Fields

create


component.create([name], [input_priority])

Сreate a new component class, which will inherit from the base Druid component.

  • Parameters:

    • [name] (string|nil): The name of the component
    • [input_priority] (number|nil): The input priority. The bigger number processed first. Default value: 10
  • Returns:

    • `` (druid.component):

create_widget


component.create_widget(self, widget_class, context)

Create the Druid component instance

  • Parameters:

    • self (druid.instance): The Druid Factory used to create components
    • widget_class (druid.widget):
    • context (table):
  • Returns:

    • `` (druid.widget):

init


component:init()

Called when component is created

update


component:update()

Called every frame

on_remove


component:on_remove()

Called when component is removed

on_input


component:on_input()

Called when input event is triggered

on_input_interrupt


component:on_input_interrupt()

Called when input event is consumed before

on_message


component:on_message()

Called when message is received

on_late_init


component:on_late_init()

Called before update once time after GUI init

on_focus_lost


component:on_focus_lost()

Called when app lost focus

on_focus_gained


component:on_focus_gained()

Called when app gained focus

on_style_change


component:on_style_change()

Called when style is changed

on_layout_change


component:on_layout_change()

Called when GUI layout is changed

on_window_resized


component:on_window_resized()

Called when window is resized

on_language_change


component:on_language_change()

Called when language is changed

set_style


component:set_style([druid_style])

Set component style. Pass nil to clear style

  • Parameters:

    • [druid_style] (table|nil):
  • Returns:

    • self (): The component itself for chaining

set_template


component:set_template([template])

Set component template name. Pass nil to clear template. This template id used to access nodes inside the template on GUI scene. Parent template will be added automatically if exist.

  • Parameters:

    • [template] (string|nil):
  • Returns:

    • self (): The component itself for chaining

get_template


component:get_template()

Get full template name.

  • Returns:
    • `` (string):

set_nodes


component:set_nodes(nodes)

Set current component nodes, returned from gui.clone_tree function.

  • Parameters:

    • nodes (table<hash, node>):
  • Returns:

    • `` (druid.component):

get_context


component:get_context()

Return current component context

  • Returns:
    • context (any): Usually it's self of script but can be any other Druid component

get_node


component:get_node(node_id)

Get component node by node_id. Respect to current template and nodes.

  • Parameters:

    • node_id (string|node):
  • Returns:

    • `` (node):

get_druid


component:get_druid([template], [nodes])

Get Druid instance for inner component creation.

  • Parameters:

    • [template] (string|nil):
    • [nodes] (table<hash, node>|nil):
  • Returns:

    • `` (druid.instance):

get_name


component:get_name()

Get component name

  • Returns:
    • name (string): The component name + uid

get_parent_name


component:get_parent_name()

Get parent component name

  • Returns:
    • parent_name (string|nil): The parent component name if exist or nil

get_input_priority


component:get_input_priority()

Get component input priority, the bigger number processed first. Default value: 10

  • Returns:
    • `` (number):

set_input_priority


component:set_input_priority(value, [is_temporary])

Set component input priority, the bigger number processed first. Default value: 10

  • Parameters:

    • value (number):
    • [is_temporary] (boolean|nil): If true, the reset input priority will return to previous value
  • Returns:

    • self (druid.component): The component itself for chaining

reset_input_priority


component:reset_input_priority()

Reset component input priority to it's default value, that was set in create function or set_input_priority

  • Returns:
    • self (druid.component): The component itself for chaining

get_uid


component:get_uid()

Get component UID, unique identifier created in component creation order.

  • Returns:
    • uid (number): The component uid

set_input_enabled


component:set_input_enabled(state)

Set component input state. By default it's enabled. If input is disabled, the component will not receive input events. Recursive for all children components.

  • Parameters:

    • state (boolean):
  • Returns:

    • self (druid.component): The component itself for chaining

get_input_enabled


component:get_input_enabled()

Get component input state. By default it's enabled. Can be disabled by set_input_enabled function.

  • Returns:
    • `` (boolean):

get_parent_component


component:get_parent_component()

Get parent component

  • Returns:
    • parent_component (druid.component|nil): The parent component if exist or nil

get_nodes


component:get_nodes()

Get current component nodes

  • Returns:
    • `` (table<hash, node>|nil):

get_childrens


component:get_childrens()

Return all children components, recursive

  • Returns:
    • Array (table): of childrens if the Druid component instance

Fields

  • druid (druid.instance): Druid instance to create inner components