mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Update docs
This commit is contained in:
@@ -15,18 +15,38 @@ A basic custom component template looks like this (you can copy it from `/druid/
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class component_name: druid.base_component
|
||||
local Component = component.create("component_name")
|
||||
local M = component.create("component_name")
|
||||
|
||||
function Component:init(template, nodes)
|
||||
function M:init(template, nodes)
|
||||
self.druid = self:get_druid(template, nodes)
|
||||
self.root = self:get_node("root")
|
||||
|
||||
self.button = self.druid:new_button("button", function() end)
|
||||
end
|
||||
|
||||
function Component:on_remove() end
|
||||
function M:hello()
|
||||
print("Hello from custom component")
|
||||
end
|
||||
|
||||
return M
|
||||
```
|
||||
|
||||
Then you can create your custom component with Druid:
|
||||
```lua
|
||||
local druid = require("druid.druid")
|
||||
|
||||
local my_component = require("my.amazing.component")
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
|
||||
-- We pass a GUI template "template_name" and skip nodes due it already on the scene
|
||||
self.my_component = self.druid:new(my_component, "template_name")
|
||||
self.my_component:hello() -- Hello from custom component
|
||||
|
||||
|
||||
end
|
||||
|
||||
return Component
|
||||
```
|
||||
|
||||
### Full Component Template
|
||||
@@ -37,36 +57,36 @@ A full custom component template looks like this (you can copy it from `/druid/t
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class component_name: druid.base_component
|
||||
local Component = component.create("component_name")
|
||||
local M = component.create("component_name")
|
||||
|
||||
function Component:init(template, nodes)
|
||||
function M:init(template, nodes)
|
||||
self.druid = self:get_druid(template, nodes)
|
||||
self.root = self:get_node("root")
|
||||
end
|
||||
|
||||
function Component:update(dt) end
|
||||
function M:update(dt) end
|
||||
|
||||
function Component:on_input(action_id, action) return false end
|
||||
function M:on_input(action_id, action) return false end
|
||||
|
||||
function Component:on_style_change(style) end
|
||||
function M:on_style_change(style) end
|
||||
|
||||
function Component:on_message(message_id, message, sender) end
|
||||
function M:on_message(message_id, message, sender) end
|
||||
|
||||
function Component:on_language_change() end
|
||||
function M:on_language_change() end
|
||||
|
||||
function Component:on_layout_change() end
|
||||
function M:on_layout_change() end
|
||||
|
||||
function Component:on_window_resized() end
|
||||
function M:on_window_resized() end
|
||||
|
||||
function Component:on_input_interrupt() end
|
||||
function M:on_input_interrupt() end
|
||||
|
||||
function Component:on_focus_lost() end
|
||||
function M:on_focus_lost() end
|
||||
|
||||
function Component:on_focus_gained() end
|
||||
function M:on_focus_gained() end
|
||||
|
||||
function Component:on_remove() end
|
||||
function M:on_remove() end
|
||||
|
||||
return Component
|
||||
return M
|
||||
```
|
||||
|
||||
### Spawning a Custom Component
|
||||
@@ -117,7 +137,7 @@ Druid provides an editor script to assist you in creating Lua files for your GUI
|
||||
|
||||
The script analyzes the current GUI scene and generates a Lua file with stubs for all Druid components found. The output file is named after the current GUI scene and placed in the same directory. Note that the script does not override any existing *.lua files. If you want to regenerate a file, delete the previous version first.
|
||||
|
||||
The script requires `python3` with `deftree` installed. If `deftree` is not installed, the instructions will be displayed in the console.
|
||||
The script requires `python` with `deftree` installed. If `deftree` is not installed, the instructions will be displayed in the console.
|
||||
|
||||
### Auto-Layout Components
|
||||
|
||||
|
Reference in New Issue
Block a user