Skip to content

Commit 566a3c6

Browse files
committed
Release 1.2.7 Add template argument to druid.get_widget
1 parent fd72f38 commit 566a3c6

6 files changed

Lines changed: 25 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ https://github.com/Insality/defold-event/archive/refs/tags/14.zip
4848
**[Druid](https://github.com/Insality/druid/)**
4949

5050
```
51-
https://github.com/Insality/druid/archive/refs/tags/1.2.6.zip
51+
https://github.com/Insality/druid/archive/refs/tags/1.2.7.zip
5252
```
5353

5454
After that, select `Project ▸ Fetch Libraries` to update [library dependencies]((https://defold.com/manuals/libraries/#setting-up-library-dependencies)). This happens automatically whenever you open a project so you will only need to do this if the dependencies change without re-opening the project.

api/druid_api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ It will notify all Druid instances to update the lang text components.
127127

128128
---
129129
```lua
130-
druid.get_widget(widget_class, gui_url, [params])
130+
druid.get_widget(widget_class, gui_url, [params], [template])
131131
```
132132

133133
Create a widget from the bound Druid GUI instance.
@@ -139,6 +139,7 @@ Widget class here is your lua file for the GUI scene (widgets in Druid)
139139
- `widget_class` *(<T:druid.widget>)*: The class of the widget to return
140140
- `gui_url` *(string|url)*: GUI url or string of component name near current script
141141
- `[params]` *(any)*: Additional parameters to pass to the widget's init function
142+
- `[template]` *(string)*: The GUI template name used by the widget nodes
142143

143144
- **Returns:**
144145
- `widget` *(<T:druid.widget>)*: The new created widget,

druid/druid.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ end
164164
---@param widget_class T The class of the widget to return
165165
---@param gui_url url|string GUI url or string of component name near current script
166166
---@param params any|nil Additional parameters to pass to the widget's init function
167+
---@param template string|nil The GUI template name used by the widget nodes
167168
---@return T widget The new created widget,
168-
function M.get_widget(widget_class, gui_url, params)
169+
function M.get_widget(widget_class, gui_url, params, template)
169170
if type(gui_url) == "string" then
170171
gui_url = msg.url(nil, nil, gui_url)
171172
end
@@ -177,7 +178,7 @@ function M.get_widget(widget_class, gui_url, params)
177178
for index = 1, #registered_druids do
178179
local druid = registered_druids[index]
179180
if druid.fragment == gui_url.fragment and druid.path == gui_url.path then
180-
return druid.new_widget(widget_class, nil, nil, params)
181+
return druid.new_widget(widget_class, template, nil, params)
181182
end
182183
end
183184

game.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ update_frequency = 60
1414

1515
[project]
1616
title = Druid
17-
version = 1.2.6
17+
version = 1.2.7
1818
publisher = Insality
1919
developer = Maksim Tuprikov
2020
custom_resources = /example/locales

wiki/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,3 +843,8 @@ Please support me if you like this project! It will help me keep engaged to upda
843843
- [System] Add `druid_instance:set_style(style)` to set the style of the Druid instance
844844
- The style is applied to the components created after this call, already created components keep their style
845845
- Allows to set the style from a game object script: `druid.get_druid(url):set_style(my_style)`
846+
847+
### Druid 1.2.7
848+
- [System] Add `template` argument to `druid.get_widget(widget_class, gui_url, [params], [template])`
849+
- The template name is passed to the `new_widget` of the bound Druid instance, so widgets placed inside a GUI template can be created from a game object script
850+
- The argument is optional, existing calls are not affected

wiki/widgets.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,16 @@ function M:init(params)
307307
self.show_badges = params.show_badges
308308
end
309309
```
310+
311+
If the widget nodes are placed inside a GUI template, pass the template name as the last argument:
312+
`druid.get_widget(widget, gui_url, [params], [template])`. It is used to resolve the widget nodes, the same way as
313+
in `druid:new_widget(widget_class, template, nodes, params)`.
314+
315+
```lua
316+
function on_message(self, message_id, message, sender)
317+
if message_id == hash("late_init") then
318+
local gui_url = msg.url(nil, nil, "go_widget")
319+
self.go_widget = druid.get_widget(my_widget, gui_url, nil, "my_widget_template")
320+
end
321+
end
322+
```

0 commit comments

Comments
 (0)