This commit is contained in:
Insality 2025-02-09 22:28:58 +02:00
parent 8407932236
commit 5eaa50552a
13 changed files with 317 additions and 47 deletions

View File

@ -46,8 +46,8 @@ Here is a list of [all releases](https://github.com/Insality/druid/releases).
| Platform | Library Size |
| ---------------- | ------------- |
| HTML5 | **38.00 KB** |
| Desktop / Mobile | **65.74 KB** |
| HTML5 | **84.52 KB** |
| Desktop / Mobile | **141.03 KB** |
### Input Bindings
@ -202,7 +202,7 @@ For a complete overview, see: **_[components.md](docs_md/01-components.md)_**.
## Druid Events
All **Druid** components using [Druid Events](https://insality.github.io/druid/modules/druid.event.html) for components callbacks. In component API ([button example](https://insality.github.io/druid/modules/Button.html#on_click)) pointed list of component events. You can manually subscribe to these events with the following API:
All **Druid** components using [Defold Event](https://github.com/Insality/defold-event) for components callbacks. In component API ([button example](https://insality.github.io/druid/modules/Button.html#on_click)) pointed list of component events. You can manually subscribe to these events with the following API:
- **event:subscribe**(callback)

View File

@ -574,3 +574,44 @@ And all my other supporters! Very appreciated!
Please support me if you like this project! It will help me keep engaged to update **Druid** and make it even better!
[![Github-sponsors](https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/insality) [![Ko-Fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/insality) [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/insality)
### Druid 1.1
Hello! Druid 1.1 is here! It's brings a lot of new features and improvements. Let's dive in!
---
**Milestone**:
**Changelog 1.1**
- Remove external annotations, remove old HTML API page
- Fully annotated code and new API readme page (hope more comfortable to use)
- Widgets here!
- A replacement for `custom_component`. Basically it's the same, but widgets contains no boilerplate code and more convinient to use.
- Now I can include a kind of `widgets` with Druid and you can use it almost instantly in your project.
- Removed `druid.register()`. Now all components are available by default and available with `self.druid:new_*` functions
- This means the druid will be bigger in size, but it's much comfortable to use
- In case you want to delete components you not using, you can do it in fork in `druid.lua` file
- Any additional widgets, color library will be not included until you use it
- Remove `druid.event`, replaced with defold-event library. Now it required to double dependency to use Druid.
- Add Druid UI kit, contains atlas so now you can use Druid GUI files in your projects.
- Contains mostly basic shapes for my UI and can contains several icons. Atlas is a small, only `128x128` size and will be included in build only if you use it.
- [Text]: Add `trim_left` and `scale_then_trim_left` text adjust modes
- [Text]: Add `set_text` function instead `set_to` (now it deprecated)
- Add `druid.bindings` module to handle cross-context widgets
- Add `druid.color` module to work with colors and palettes
- Add `container` component to handle more complex adaptive layouts
- [Shaders] Add repeat, hard image stencil and world gui materials
- [Widget] Add widget `mini_graph`
- [Widget] Add widget `memory_panel`
- [Widget] Add widget `fps_panel`
- [Widget] Add widget `properties_panel`
- Include `property_button` widget
- Include `property_checkbox` widget
- Include `property_input` widget
- Include `property_left_right_selector` widget
- Include `property_slider` widget
- Include `property_text` widget
- Include `property_vector3` widget
- Removed old `druid.no_stencil_check` and `druid.no_auto_template` flags. Now it's always disabled

View File

@ -80,6 +80,7 @@ self.druid:set_whitelist(whitelist_components)
## Components
### Base Component
```lua
component:get_childrens()
component:get_context()
@ -101,14 +102,20 @@ component:set_template([template])
```
### Blocker
```lua
local blocker = self.druid:new_blocker(node)
blocker:is_enabled()
blocker:on_input(action_id, action)
blocker:set_enabled(state)
```
### Button
```lua
local button = self.druid:new_button(node, [callback], [params], [anim_node])
button:get_key_trigger()
button:is_enabled()
button:on_input([action_id], [action])
@ -123,7 +130,10 @@ button:set_web_user_interaction([is_web_mode])
```
### Container
```lua
local container = self.druid:new_container(node, [mode], [callback])
container:add_container(node_or_container, [mode], [on_resize_callback])
container:clear_draggable_corners()
container:create_draggable_corners()
@ -151,7 +161,10 @@ container:update_child_containers()
```
### Data List
```lua
local data_list = self.druid:new_data_list(druid_scroll, druid_grid, create_function)
data_list:add(data, [index], [shift_policy])
data_list:clear()
data_list:get_created_components()
@ -168,7 +181,10 @@ data_list:set_use_cache(is_use_cache)
```
### Drag
```lua
local drag = self.druid:new_drag(node, [on_drag_callback])
drag:init(node_or_node_id, on_drag_callback)
drag:is_enabled()
drag:on_input(action_id, action)
@ -182,8 +198,9 @@ drag:set_enabled(is_enabled)
```
### Grid
```lua
local static_grid = require("druid.base.static_grid")
local grid = self.druid:new_grid(parent_node, item, [in_row])
grid:add(item, [index], [shift_policy], [is_instant])
grid:clear()
@ -210,8 +227,9 @@ grid:sort_nodes(comparator)
```
### Hotkey
```lua
local hotkey = require("druid.extended.hotkey")
local hotkey = self.druid:new_hotkey(keys_array, [callback], [callback_argument])
hotkey:add_hotkey(keys, [callback_argument])
hotkey:init(keys, callback, [callback_argument])
@ -223,8 +241,9 @@ hotkey:set_repeat(is_enabled_repeated)
```
### Hover
```lua
local hover = require("druid.base.hover")
local hover = self.druid:new_hover(node, [on_hover_callback], [on_mouse_hover_callback])
hover:init(node, on_hover_callback, on_mouse_hover)
hover:is_enabled()
@ -241,8 +260,9 @@ hover:set_mouse_hover([state])
```
### Input
```lua
local input = require("druid.extended.input")
local input = self.druid:new_input(click_node, text_node, [keyboard_type])
input:get_text()
input:get_text_selected()
@ -263,7 +283,10 @@ input:unselect()
```
### Lang Text
```lua
local lang_text = self.druid:new_lang_text(node, [locale_id], [adjust_type])
lang_text:format([a], [b], [c], [d], [e], [f], [g])
lang_text:init(node, [locale_id], [adjust_type])
lang_text:on_language_change()
@ -273,8 +296,9 @@ lang_text:translate(locale_id, [a], [b], [c], [d], [e], [f], [g])
```
### Layout
```lua
local layout = require("druid.extended.layout")
local layout = self.druid:new_layout(node, [mode])
layout:add(node_or_node_id)
layout:calculate_rows_data()
@ -298,8 +322,9 @@ layout:update()
```
### Progress
```lua
local progress = require("druid.extended.progress")
local progress = self.druid:new_progress(node, key, [init_value])
progress:empty()
progress:fill()
@ -316,8 +341,9 @@ progress:update([dt])
```
### Rich Input
```lua
local rich_input = require("druid.custom.rich_input.rich_input")
local rich_input = self.druid:new_rich_input(template, [nodes])
rich_input:get_text()
rich_input:init(template, nodes)
@ -330,8 +356,9 @@ rich_input:set_text(text)
```
### Rich Text
```lua
local rich_text = require("druid.custom.rich_text.rich_text")
local rich_text = self.druid:new_rich_text(text_node, [value])
rich_text:characters(word)
rich_text:clear()
@ -347,8 +374,9 @@ rich_text:tagged(tag)
```
### Scroll
```lua
local scroll = require("druid.base.scroll")
local scroll = self.druid:new_scroll(view_node, content_node)
scroll:bind_grid([grid])
scroll:get_percent()
@ -377,8 +405,9 @@ scroll:update_view_size()
```
### Slider
```lua
local slider = require("druid.extended.slider")
local slider = self.druid:new_slider(pin_node, end_pos, [callback])
slider:init(node, end_pos, [callback])
slider:is_enabled()
@ -393,8 +422,9 @@ slider:set_steps(steps)
```
### Swipe
```lua
local swipe = require("druid.extended.swipe")
local swipe = self.druid:new_swipe(node, [on_swipe_callback])
swipe:init(node_or_node_id, on_swipe_callback)
swipe:on_input(action_id, action)
@ -405,8 +435,9 @@ swipe:set_click_zone([zone])
```
### Text
```lua
local text = require("druid.base.text")
local text = self.druid:new_text(node, [value], [no_adjust])
text:get_text()
text:get_text_adjust()
@ -428,8 +459,9 @@ text:set_to(set_to)
```
### Timer
```lua
local timer = require("druid.extended.timer")
local timer = self.druid:new_timer(node, [seconds_from], [seconds_to], [callback])
timer:init(node, [seconds_from], [seconds_to], [callback])
timer:on_layout_change()
@ -439,8 +471,8 @@ timer:set_to(set_to)
timer:update([dt])
```
## Helper
```lua
local helper = require("druid.helper")
@ -475,4 +507,4 @@ helper.round(num, [num_decimal_places])
helper.sign(val)
helper.step(current, target, step)
helper.table_to_string(t)
```
```

View File

@ -309,10 +309,10 @@ end
---Button constructor
---@param node_or_node_id node|string Node name or GUI Node itself.
---@param node_or_node_id node|string Node name or GUI Node itself
---@param callback fun()|nil Callback on button click
---@param custom_args any|nil Custom args for any Button event
---@param anim_node node|string|nil Node to animate instead of trigger node.
---@param anim_node node|string|nil Node to animate instead of trigger node
function M:init(node_or_node_id, callback, custom_args, anim_node)
self.druid = self:get_druid()
self.node = self:get_node(node_or_node_id)

View File

@ -194,7 +194,7 @@ end
function M.load_palette()
local PALETTE_PATH = sys.get_config_string("fluid.palette")
local PALETTE_PATH = sys.get_config_string("druid.palette")
if PALETTE_PATH then
PALETTE_DATA = M.load_json(PALETTE_PATH) --[[@as table<string, table<string, vector4>>]]
end

View File

@ -424,7 +424,7 @@ function M._update_nodes(lines, settings)
gui.set_outline(node, word.outline)
gui.set_shadow(node, word.shadow)
gui.set_text(node, word.text)
gui.set_color(node, word.color)
gui.set_color(node, word.color or word.text_color)
gui.set_font(node, word.font or settings.font)
end
word.node = node

View File

@ -102,6 +102,7 @@ local rich_text = require("druid.custom.rich_text.module.rt")
---@field relative_scale number
---@field source_text string
---@field color vector4
---@field text_color vector4
---@field position vector3
---@field offset vector3
---@field scale vector3

View File

@ -89,35 +89,23 @@ end
--- Translate the text by locale_id
---@param locale_id string Locale id
---@param a string|nil Optional param to string.format
---@param b string|nil Optional param to string.format
---@param c string|nil Optional param to string.format
---@param d string|nil Optional param to string.format
---@param e string|nil Optional param to string.format
---@param f string|nil Optional param to string.format
---@param g string|nil Optional param to string.format
---@param ... string Optional params for string.format
---@return druid.lang_text Current instance
function M:translate(locale_id, a, b, c, d, e, f, g)
self.last_locale_args = { a, b, c, d, e, f, g }
function M:translate(locale_id, ...)
self.last_locale_args = { ... }
self.last_locale = locale_id or self.last_locale
self.text:set_text(settings.get_text(self.last_locale, a, b, c, d, e, f, g) or "")
self.text:set_text(settings.get_text(self.last_locale, ...) or "")
return self
end
--- Format string with new text params on localized text
---@param a string|nil Optional param to string.format
---@param b string|nil Optional param to string.format
---@param c string|nil Optional param to string.format
---@param d string|nil Optional param to string.format
---@param e string|nil Optional param to string.format
---@param f string|nil Optional param to string.format
---@param g string|nil Optional param to string.format
---@param ... string Optional params for string.format
---@return druid.lang_text Current instance
function M:format(a, b, c, d, e, f, g)
self.last_locale_args = { a, b, c, d, e, f, g }
self.text:set_text(settings.get_text(self.last_locale, a, b, c, d, e, f, g) or "")
function M:format(...)
self.last_locale_args = { ... }
self.text:set_text(settings.get_text(self.last_locale, ...) or "")
return self
end

View File

@ -288,14 +288,16 @@ function M:refresh_layout()
local new_row_width = width * (0.5 - layout_pivot_offset.x)
-- Compare with eps due the float loss and element flickering
if current_x + node_width - new_row_width > 0.0001 then
if current_x + node_width - new_row_width > 0.00001 then
current_y = current_y - row.height - margin.y
if row_index < #rows then
row_index = row_index + 1
row = rows[row_index]
end
current_x = -row.width * (0.5 + layout_pivot_offset.x)
current_y = current_y - row.height - margin.y
if is_justify and row.count > 1 then
current_x = -max_width * (0.5 + layout_pivot_offset.x)
end

View File

@ -1,3 +1,5 @@
-- Hello! Wish you a good day!
local events = require("event.events")
local const = require("druid.const")
local helper = require("druid.helper")

View File

@ -4,7 +4,7 @@ local M = {}
M.default_style = nil
---@param text_id string
---@vararg any
---@param ... string Optional params for string.format
function M.get_text(text_id, ...)
return "[Druid]: locales not inited"
end

View File

@ -16,7 +16,7 @@ function M.get_examples()
properties_panel:add_slider("ui_padding", 0, function(value)
local padding = math.floor((value * 64) * 100) / 100
instance.layout:set_padding(vmath.vector4(padding))
instance.layout:set_padding(padding, padding, padding, padding)
end)
properties_panel:add_slider("ui_margin_x", 0, function(value)
@ -88,4 +88,4 @@ function M.get_examples()
end
return M
return M

View File

@ -364,5 +364,209 @@ nodes {
parent: "properties_panel/property_left_right_selector/E_Anchor"
template_node_child: true
}
nodes {
type: TYPE_TEMPLATE
id: "properties_panel/property_vector3"
parent: "properties_panel/propeties"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/root"
parent: "properties_panel/property_vector3"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/text_name"
parent: "properties_panel/property_vector3/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/E_Anchor"
parent: "properties_panel/property_vector3/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/field_x"
parent: "properties_panel/property_vector3/E_Anchor"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/text_x"
parent: "properties_panel/property_vector3/field_x"
template_node_child: true
}
nodes {
type: TYPE_TEMPLATE
id: "properties_panel/property_vector3/rich_input_x"
parent: "properties_panel/property_vector3/field_x"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/rich_input_x/root"
parent: "properties_panel/property_vector3/rich_input_x"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/rich_input_x/button"
parent: "properties_panel/property_vector3/rich_input_x/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/rich_input_x/placeholder_text"
parent: "properties_panel/property_vector3/rich_input_x/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/rich_input_x/input_text"
parent: "properties_panel/property_vector3/rich_input_x/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/rich_input_x/cursor_node"
parent: "properties_panel/property_vector3/rich_input_x/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/rich_input_x/cursor_text"
parent: "properties_panel/property_vector3/rich_input_x/cursor_node"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/selected_x"
parent: "properties_panel/property_vector3/field_x"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/field_y"
parent: "properties_panel/property_vector3/E_Anchor"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/text_y"
parent: "properties_panel/property_vector3/field_y"
template_node_child: true
}
nodes {
type: TYPE_TEMPLATE
id: "properties_panel/property_vector3/rich_input_y"
parent: "properties_panel/property_vector3/field_y"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/rich_input_y/root"
parent: "properties_panel/property_vector3/rich_input_y"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/rich_input_y/button"
parent: "properties_panel/property_vector3/rich_input_y/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/rich_input_y/placeholder_text"
parent: "properties_panel/property_vector3/rich_input_y/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/rich_input_y/input_text"
parent: "properties_panel/property_vector3/rich_input_y/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/rich_input_y/cursor_node"
parent: "properties_panel/property_vector3/rich_input_y/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/rich_input_y/cursor_text"
parent: "properties_panel/property_vector3/rich_input_y/cursor_node"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/selected_y"
parent: "properties_panel/property_vector3/field_y"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/field_z"
parent: "properties_panel/property_vector3/E_Anchor"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/text_z"
parent: "properties_panel/property_vector3/field_z"
template_node_child: true
}
nodes {
type: TYPE_TEMPLATE
id: "properties_panel/property_vector3/rich_input_z"
parent: "properties_panel/property_vector3/field_z"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/rich_input_z/root"
parent: "properties_panel/property_vector3/rich_input_z"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/rich_input_z/button"
parent: "properties_panel/property_vector3/rich_input_z/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/rich_input_z/placeholder_text"
parent: "properties_panel/property_vector3/rich_input_z/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/rich_input_z/input_text"
parent: "properties_panel/property_vector3/rich_input_z/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/rich_input_z/cursor_node"
parent: "properties_panel/property_vector3/rich_input_z/root"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "properties_panel/property_vector3/rich_input_z/cursor_text"
parent: "properties_panel/property_vector3/rich_input_z/cursor_node"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "properties_panel/property_vector3/selected_z"
parent: "properties_panel/property_vector3/field_z"
template_node_child: true
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT