# Module `BaseComponent`

Basic class for all Druid components.

To create you custom component, use static function `component.create`

### Usage:

    -- Create your component:
    local component = require("druid.component")

    local AwesomeComponent = component.create("awesome_component")

    function AwesomeComponent:init(template, nodes)
        self:set_template(template)
        self:set_nodes(nodes)
        self.druid = self:get_druid()
    end

    return AwesomeComponent

## Functions

component:get_childrens(self) | Return all children components, recursive
component:get_context(self) | Context used as first arg in all Druid events
component:get_druid(self) | Get Druid instance for inner component creation.
component:get_input_priority(self) | Return component input priority
component:get_name(self) | Return component name
component:get_node(self, node_or_name) | Get component node by name.
component:get_parent_component(self) | Return the parent component if exist
component:get_parent_name(self) | Return parent component name
component:get_template(self) | Get current component template name.
component:get_uid(self) | Return component UID.
component:reset_input_priority(self) | Reset component input priority to default value
component:set_input_enabled(self, state) | Set component input state.
component:set_input_priority(self, value, is_temporary) | Set component input priority
component:set_nodes(self, nodes) | Set current component nodes
component:set_style(self, druid_style) | Set current component style table.
component:set_template(self, template) | Set component template name.

## Functions

component:get_childrens(self)
  Return all children components, recursive

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  table Array of childrens if the Druid component instance
component:get_context(self)
  Context used as first arg in all Druid events Context is usually self of gui_script.

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  table BaseComponent context
component:get_druid(self)
  Get Druid instance for inner component creation.

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  Druid Druid instance with component context
component:get_input_priority(self)
  Return component input priority

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  number The component input priority
component:get_name(self)
  Return component name

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  string The component name
component:get_node(self, node_or_name)
  Get component node by name.

  If component has nodes, node_or_name should be string It autopick node by template name or from nodes by gui.clone_tree if they was setup via component:set_nodes, component:set_template. If node is not found, the exception will fired

  ### Parameters:

  - self BaseComponent BaseComponent
  - node_or_name string or node Node name or node itself

  ### Returns:

  node Gui node
component:get_parent_component(self)
  Return the parent component if exist

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  BaseComponent or nil The druid component instance or nil
component:get_parent_name(self)
  Return parent component name

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  string or nil The parent component name if exist or bil
component:get_template(self)
  Get current component template name.

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  string Component full template name
component:get_uid(self)
  Return component UID.

  UID generated in component creation order.

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  number The component uid
component:reset_input_priority(self)
  Reset component input priority to default value

  ### Parameters:

  - self BaseComponent BaseComponent

  ### Returns:

  number The component input priority
component:set_input_enabled(self, state)
  Set component input state. By default it enabled

  If input is disabled, the component will not receive input events

  ### Parameters:

  - self BaseComponent BaseComponent
  - state bool The component input state

  ### Returns:

  BaseComponent BaseComponent itself
component:set_input_priority(self, value, is_temporary)
  Set component input priority Default value: 10

  ### Parameters:

  - self BaseComponent BaseComponent
  - value number The new input priority value
  - is_temporary boolean If true, the reset input priority will return to previous value

  ### Returns:

  number The component input priority
component:set_nodes(self, nodes)
  Set current component nodes Use if your component nodes was cloned with `gui.clone_tree` and you got the node tree.

  ### Parameters:

  - self BaseComponent BaseComponent
  - nodes table BaseComponent nodes table

  ### Returns:

  BaseComponent BaseComponent

  ### Usage:

      local nodes = gui.clone_tree(self.prefab)
      ... In your component:
      self:set_nodes(nodes)

component:set_style(self, druid_style)
  Set current component style table.

  Invoke `on_style_change` on component, if exist. Component should handle their style changing and store all style params

  ### Parameters:

  - self BaseComponent BaseComponent
  - druid_style table Druid style module

  ### Returns:

  BaseComponent BaseComponent
component:set_template(self, template)
  Set component template name.

  Use on all your custom components with GUI layouts used as templates. It will check parent template name to build full template name in self:get_node()

  ### Parameters:

  - self BaseComponent BaseComponent
  - template string BaseComponent template name

  ### Returns:

  BaseComponent BaseComponent

generated by LDoc TESTING Last updated 2015-01-01 12:00:00