From dc76d3b3d474bb6825b149e2a5df40a621608e8e Mon Sep 17 00:00:00 2001 From: Insality Date: Tue, 8 Mar 2022 20:32:10 +0200 Subject: [PATCH] Update docs, update custom component templates --- druid/base/static_grid.lua | 2 -- druid/system/druid_instance.lua | 10 +++---- druid/templates/component.template.lua | 25 ++++++++++++++++++ .../component_full.template.lua} | 26 ++++++++++++++----- 4 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 druid/templates/component.template.lua rename druid/{extended/component.template.lua => templates/component_full.template.lua} (66%) diff --git a/druid/base/static_grid.lua b/druid/base/static_grid.lua index 7428aba..6e228fb 100644 --- a/druid/base/static_grid.lua +++ b/druid/base/static_grid.lua @@ -438,7 +438,6 @@ end --- Return elements offset for correct posing nodes. Correct posing at -- parent pivot node (0:0) with adjusting of node sizes and anchoring --- @function static_grid:_get_zero_offset -- @treturn vector3 The offset vector -- @local function StaticGrid:_get_zero_offset() @@ -456,7 +455,6 @@ end --- Return offset x for last row in grid. Used to align this row accorting to grid's anchor --- @function static:_grid:_get_zero_offset_x -- @treturn number The offset x value -- @local function StaticGrid:_get_zero_offset_x(row_index) diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index e52f191..88c2573 100755 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -195,6 +195,7 @@ end -- @tparam DruidInstance self -- @tparam table context Druid context. Usually it is self of script -- @tparam table style Druid style module +-- @local function DruidInstance.initialize(self, context, style) self._context = context self._style = style or settings.default_style @@ -391,6 +392,7 @@ end --- Druid on focus lost interest function. -- This one called by on_window_callback by global window listener -- @tparam DruidInstance self +-- @local function DruidInstance.on_focus_lost(self) local components = self.components_interest[base_component.ON_FOCUS_LOST] for i = 1, #components do @@ -401,8 +403,8 @@ end --- Druid on focus gained interest function. -- This one called by on_window_callback by global window listener --- @function druid_instance.on_focus_gained -- @tparam DruidInstance self +-- @local function DruidInstance.on_focus_gained(self) local components = self.components_interest[base_component.ON_FOCUS_GAINED] for i = 1, #components do @@ -414,8 +416,8 @@ end --- Druid on language change. -- This one called by global gruid.on_language_change, but can be -- call manualy to update all translations --- @function druid_instance.on_language_change -- @tparam DruidInstance self +-- @local function DruidInstance.on_language_change(self) local components = self.components_interest[base_component.ON_LANGUAGE_CHANGE] for i = 1, #components do @@ -427,7 +429,6 @@ end --- Set whitelist components for input processing. -- If whitelist is not empty and component not contains in this list, -- component will be not processed on input step --- @function druid_instance.set_whitelist -- @tparam DruidInstance self -- @tparam[opt=nil] table|Component whitelist_components The array of component to whitelist function DruidInstance.set_whitelist(self, whitelist_components) @@ -450,7 +451,6 @@ end --- Set blacklist components for input processing. -- If blacklist is not empty and component contains in this list, -- component will be not processed on input step --- @function druid_instance.set_blacklist -- @tparam DruidInstance self -- @tparam[opt=nil] table|Component blacklist_components The array of component to blacklist function DruidInstance.set_blacklist(self, blacklist_components) @@ -648,7 +648,7 @@ end --- Create data list basic component --- @function druid:new_data_list +-- @tparam DruidInstance self -- @tparam Scroll druid_scroll The Scroll instance for Data List component -- @tparam Grid druid_grid The Grid instance for Data List component -- @tparam function create_function The create function callback(self, data, index, data_list). Function should return (node, [component]) diff --git a/druid/templates/component.template.lua b/druid/templates/component.template.lua new file mode 100644 index 0000000..c9ea71b --- /dev/null +++ b/druid/templates/component.template.lua @@ -0,0 +1,25 @@ +local component = require("druid.component") + +local Component = component.create("component_name") + +local SCHEME = { + ROOT = "root", + BUTTON = "button", +} + + +function Component:init(template, nodes) + self:set_template(template) + self:set_nodes(nodes) + self.root = self:get_node(SCHEME.ROOT) + self.druid = self:get_druid() + + self.button = self.druid:new_button(SCHEME.BUTTON, function() end) +end + + +function Component:on_remove() +end + + +return Component diff --git a/druid/extended/component.template.lua b/druid/templates/component_full.template.lua similarity index 66% rename from druid/extended/component.template.lua rename to druid/templates/component_full.template.lua index 66aace7..8209aa9 100644 --- a/druid/extended/component.template.lua +++ b/druid/templates/component_full.template.lua @@ -1,15 +1,27 @@ --- Copyright (c) 2021 Maksim Tuprikov . This code is licensed under MIT license - ---- Druid component template --- @module druid.component --- @local local component = require("druid.component") -local Component = component.create("my_component_name") +local Component = component.create("component_name") + +-- Scheme of component gui nodes +local SCHEME = { + ROOT = "root", + BUTTON = "button", +} -- Component constructor -function Component:init(...) +function Component:init(template, nodes) + -- If your component is gui template, pass the template name and set it + self:set_template(template) + + -- If your component is cloned my gui.clone_tree, pass nodes to component and set it + self:set_nodes(nodes) + + -- self:get_node will auto process component template and nodes + self.root = self:get_node(SCHEME.ROOT) + + -- Use inner druid instance to create components inside this component + self.druid = self:get_druid() end