mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Update docs
This commit is contained in:
@@ -1,67 +1,36 @@
|
||||
|
||||
# Druid FAQ
|
||||
|
||||
>_Have questions about Druid? Ask me!_
|
||||
> _Here is questions you might have_
|
||||
Welcome to the Druid FAQ! Here are answers to some common questions you may have:
|
||||
|
||||
### Q: Why I want use Druid?
|
||||
**A:** ---
|
||||
### Q: How do I remove a Druid component instance?
|
||||
**A:** To remove a created Druid component, use the `druid:remove` function. You can find more information in the [API reference](https://insality.github.io/druid/modules/druid_instance.html#druid:remove).
|
||||
|
||||
### Q: How does Druid process input?
|
||||
**A:** Input processing in Druid follows a Last-In-First-Out (LIFO) queue. Buttons added later have higher priority than those added earlier. To ensure correct button behavior, place your buttons from back to front in most cases.
|
||||
|
||||
### Q: How to remove the Druid component instance?
|
||||
**A:** Any created **Druid** component can be removed with _druid:remove_. [API reference link](https://insality.github.io/druid/modules/druid_instance.html#druid:remove).
|
||||
### Q: What is the purpose of the Blocker component?
|
||||
**A:** The Blocker component is used to block input in a specific zone. It is useful for creating unclickable zones within buttons or for creating a panel of buttons on top of another button (e.g., closing windows by clicking on the window background). You can find more information about the Blocker component [here](https://github.com/Insality/druid/blob/master/docs_md/01-components.md#notes-2).
|
||||
|
||||
### Q: What can I do with custom components?
|
||||
**A:** With custom components in Druid, the possibilities are endless! Custom components allow you to separate component placement and game logic from other elements, making them reusable and easier to test and develop. Custom components can be used for scroll elements with buttons, custom GUI widgets, or even components with custom game logic. Templates often accompany custom components, allowing you to create multiple visual variations for a single component module. You can find some examples of custom components [here](https://github.com/Insality/druid-assets).
|
||||
|
||||
### Q: How to make scroll work?
|
||||
**A:** ---
|
||||
### Q: How does `self:get_node()` work?
|
||||
**A:** The `self:get_node()` function in a Druid component searches for nodes in the GUI directly or in cloned nodes created using `gui.clone_tree()`. It also considers nodes placed as templates, with the full node ID composed of the template name and node name (including cloned nodes). To ensure correct usage of `self:get_node()`, set up the component nodes using `self:set_template()` and `self:set_component_nodes()` before calling `self:get_node()`. It's best to pass the string name of the node, rather than the GUI node itself.
|
||||
|
||||
|
||||
### Q: How the input is processing?
|
||||
**A:**
|
||||
*SImply*: the **Druid** has a LIFO queue to check input. Last added buttons have more priority than first. Placing your buttons from behind to the front is correct in most cases.
|
||||
|
||||
|
||||
### Q: For what purpose Blocker component is exist?
|
||||
**A:** Component explanation [here](https://github.com/Insality/druid/blob/master/docs_md/01-components.md#notes-2).
|
||||
With Blocker you can block input in some zone. It is useful for make unclickable zone in buttons or kind of buttons panel on other big button (ex. close windows on window background click)
|
||||
|
||||
|
||||
### Q: Which stuff can I do with custom components?
|
||||
**A:** Any of you can imagine! There is a lot of examples, but in general: custom components allow you place component and some game logic separately from other stuff. It will be reusable, easier for testing and developing.
|
||||
|
||||
For example it can be element in scroll with buttons, your custom GUI widget or even component with your game logic. Usually custom components going with templates. You can do several templates for single component module (for different visuals!)
|
||||
|
||||
Some examples of custom components you can find [here](https://github.com/Insality/druid-assets).
|
||||
|
||||
|
||||
### Q: How *self:get_node()* is working?
|
||||
**A:** The node can be placed in gui directly or can be cloned via *gui.clone_tree()*. Also nodes can be placed as templates, so full node id will be composed from template name and node name (in cloned nodes too).
|
||||
|
||||
**Druid** component *self:get_node()* trying to search in all of this places. Use *self:set_template()* and *self:set_component_nodes()* for correct setup component nodes before any call of *self:get_node()*.
|
||||
|
||||
Remember, usually you should pass *__string name__ of the node*, not gui node itself. It's better and more druid-way.
|
||||
|
||||
|
||||
### Q: My button in scroll is clickable outside the stencil node
|
||||
**A:** Since **Druid** checking click node with _gui.pick_node_, stencil is not prevent this. You can setup additional click zone on your buttons with _button:set_click_zone_.
|
||||
|
||||
The usual Druid way after add button to the scroll do:
|
||||
### Q: My button in a scroll is clickable outside the stencil node. How can I fix this?
|
||||
**A:** When using Druid, the stencil node does not prevent buttons from being clickable outside its bounds. To address this, you can set up an additional click zone on your buttons using the `button:set_click_zone()` function. After adding a button to the scroll, you can use the following code:
|
||||
```lua
|
||||
-- Scroll view node usually is stencil node
|
||||
-- Assuming the scroll view node is the stencil node
|
||||
button:set_click_zone(scroll.view_node)
|
||||
```
|
||||
|
||||
|
||||
### Q: How to use EmmyLua annotations? _(from Druid 0.6.0)_
|
||||
**A:** Since the dependencies can't be processed by external editors, for use generated EmmyLua annotations you should copy the _druid/annotations.lua_ to your project. For EmmyLua it will be enough. Remember you can _restart emmylua server_ for refresh the changes, if something goes wrong.
|
||||
After the annotations is processed, you should point the type of Druid in requires:
|
||||
### Q: How do I use EmmyLua annotations? (from Druid 0.6.0)
|
||||
**A:** EmmyLua annotations are used for better autocompletion and type inference in editors. To use the generated EmmyLua annotations, copy the `druid/annotations.lua` file to your project. After copying, you may need to restart the EmmyLua server to ensure the changes take effect. Once the annotations are processed, you can specify the type of Druid in your code:
|
||||
```lua
|
||||
---@type druid
|
||||
local druid = require("druid.druid")
|
||||
|
||||
-- Now the autocomplete is working
|
||||
-- Autocomplete and type information should now work
|
||||
```
|
||||
|
||||
|
||||
### Q: When I should use *on_layout_change*?
|
||||
**A:** ---
|
||||
Feel free to ask any additional questions you have about Druid!
|
||||
|
Reference in New Issue
Block a user