Hello!
Probably you can check this example:
Live example, code
or custom component documentation
In this example the custom component for data list are used.
Basically, the custom component is your lua
file, that in simplest way will look like this:
local component = require("druid.component")
local ButtonComponent = component.create("button_component")
---@param template string
---@param nodes table<hash, node>
function ButtonComponent:init(template, nodes)
self:set_template(template)
self:set_nodes(nodes)
self.druid = self:get_druid()
self.root = self:get_node("root")
self.button = self.druid:new_button(self.root, self._on_click)
end
function ButtonComponent:_on_click()
self.on_click:trigger(self)
end
return ButtonComponent
And later you will create your component with self.druid:new(ButtonComponent, template, nodes)
Registering components are not required, it’s just to make aliases.
Example:
-- Direct component creation
local ButtonComponent = require("example.examples.data_list.with_component.button_component.button_component")
local button = self.druid:new(ButtonComponent, "button_component", nodes)
----- or ------
-- Register only once:
local druid = require("druid.druid")
local ButtonComponent = require("example.examples.data_list.with_component.button_component.button_component")
druid.register(ButtomComponent, "button_component")
-- And create component in this way
self.druid:new_button_component(template, nodes)