107107
108108
109109--- Set current component nodes, returned from `gui.clone_tree` function.
110- --- @param nodes table<hash , node>
110+ --- @param nodes table<hash , node> | node | string | nil The nodes table from gui.clone_tree or prefab node to use for clone or node id to clone
111111--- @return druid.component
112112function M :set_nodes (nodes )
113+ if type (nodes ) == " string" then
114+ nodes = self :get_node (nodes )
115+ end
116+ if type (nodes ) == " userdata" then
117+ nodes = gui .clone_tree (nodes ) --[[ @as table<hash, node>]]
118+ end
119+
113120 self ._meta .nodes = nodes
114121 return self
115122end
132139
133140--- Get Druid instance for inner component creation.
134141--- @param template string | nil
135- --- @param nodes table<hash , node> | nil
142+ --- @param nodes table<hash , node> | node | string | nil The nodes table from gui.clone_tree or prefab node to use for clone or node id to clone
136143--- @return druid.instance
137144function M :get_druid (template , nodes )
138145 local druid_instance = setmetatable ({
@@ -396,7 +403,11 @@ function M.create_widget(self, widget_class, context)
396403 default_input_priority = const .PRIORITY_INPUT ,
397404 _is_input_priority_changed = true , -- Default true for sort once time after GUI init
398405 }
399- instance ._meta = {
406+
407+ -- I'll hide a meta fields under metatable to hide this tables from pprint output
408+ -- cause it's leads to recursive pprint's from (druid = self)
409+ -- Wish this to be better, since it can reduce a memory usage
410+ instance ._meta = setmetatable ({}, { __index = {
400411 druid = self ,
401412 template = " " ,
402413 nodes = nil ,
@@ -406,7 +417,7 @@ function M.create_widget(self, widget_class, context)
406417 children = {},
407418 parent = type (context ) ~= " userdata" and context or nil ,
408419 instance_class = widget_class
409- }
420+ }})
410421
411422 -- Register
412423 if instance ._meta .parent then
0 commit comments