From 62384f36b32a427782d4be6359944dbbabc65790 Mon Sep 17 00:00:00 2001 From: Insality Date: Wed, 23 Oct 2024 00:43:03 +0300 Subject: [PATCH] Add generics annotations to component set_style/nodes/template --- docs/modules/BaseComponent.html | 116 -------------------------------- druid/annotations.lua | 47 +++++++------ druid/component.lua | 3 + utils/annotations_manual.lua | 26 ++++++- 4 files changed, 53 insertions(+), 139 deletions(-) diff --git a/docs/modules/BaseComponent.html b/docs/modules/BaseComponent.html index ab54602..39eb118 100644 --- a/docs/modules/BaseComponent.html +++ b/docs/modules/BaseComponent.html @@ -145,18 +145,6 @@ return AwesomeComponent set_input_priority(self, value, is_temporary) Set component input priority - - set_nodes(self, nodes) - Set current component nodes. - - - set_style(self, druid_style) - Set current component style table. - - - set_template(self, template) - Set component template name. -
@@ -546,110 +534,6 @@ return AwesomeComponent - -
- - set_nodes(self, nodes) -
-
- Set current component nodes. - Use if your component nodes was cloned with `gui.clone_tree` and you got the node tree. - - -

Parameters:

- - -

Returns:

-
    - - BaseComponent - BaseComponent -
- - - -

Usage:

- - -
-
- - set_style(self, druid_style) -
-
- Set current component style table. -

Invoke `on_style_change` on component, if exist. Component should handle - their style changing and store all style params - - -

Parameters:

- - -

Returns:

-
    - - BaseComponent - BaseComponent -
- - - - -
-
- - set_template(self, template) -
-
- Set component template name. -

Use on all your custom components with GUI layouts used as templates. - It will check parent template name to build full template name in self:get_node() - - -

Parameters:

- - -

Returns:

-
    - - BaseComponent - BaseComponent -
- - - -
diff --git a/druid/annotations.lua b/druid/annotations.lua index f883f5e..9ccff3c 100644 --- a/druid/annotations.lua +++ b/druid/annotations.lua @@ -126,27 +126,6 @@ function druid__base_component.set_input_enabled(self, state) end ---@return number The component input priority function druid__base_component.set_input_priority(self, value, is_temporary) end ---- Set current component nodes. ---- Use if your component nodes was cloned with `gui.clone_tree` and you got the node tree. ----@param self druid.base_component @{BaseComponent} ----@param nodes table BaseComponent nodes table ----@return druid.base_component @{BaseComponent} -function druid__base_component.set_nodes(self, nodes) end - ---- Set current component style table. ---- Invoke `on_style_change` on component, if exist. Component should handle their style changing and store all style params ----@param self druid.base_component @{BaseComponent} ----@param druid_style table|nil Druid style module ----@return druid.base_component @{BaseComponent} -function druid__base_component.set_style(self, druid_style) end - ---- Set component template name. ---- Use on all your custom components with GUI layouts used as templates. It will check parent template name to build full template name in self:get_node() ----@param self druid.base_component @{BaseComponent} ----@param template string BaseComponent template name ----@return druid.base_component @{BaseComponent} -function druid__base_component.set_template(self, template) end - ---@class druid.blocker : druid.base_component ---@field node node Blocker node @@ -1896,4 +1875,28 @@ function helper.table_to_string(t) end ---@param component T Component module ---@param ... any Other component params to pass it to component:init function ---@return T Component instance -function druid_instance.new(self, component, ...) end \ No newline at end of file +function druid_instance.new(self, component, ...) end + +--- Set current component style table. +--- Invoke `on_style_change` on component, if exist. Component should handle their style changing and store all style params +---@generic T: druid.base_component +---@param self T @{BaseComponent} +---@param druid_style table|nil Druid style module +---@return T @{BaseComponent} +function druid__base_component.set_style(self, druid_style) end + +--- Set component template name. +--- Use on all your custom components with GUI layouts used as templates. It will check parent template name to build full template name in self:get_node() +---@generic T: druid.base_component +---@param self T @{BaseComponent} +---@param template string BaseComponent template name +---@return T @{BaseComponent} +function druid__base_component.set_template(self, template) end + +--- Set current component nodes. +--- Use if your component nodes was cloned with `gui.clone_tree` and you got the node tree. +---@generic T: druid.base_component +---@param self T @{BaseComponent} +---@param nodes table BaseComponent nodes table +---@return T @{BaseComponent} +function druid__base_component.set_nodes(self, nodes) end diff --git a/druid/component.lua b/druid/component.lua index 1bd76c9..0672303 100644 --- a/druid/component.lua +++ b/druid/component.lua @@ -76,6 +76,7 @@ end -- @tparam BaseComponent self @{BaseComponent} -- @tparam table|nil druid_style Druid style module -- @treturn BaseComponent @{BaseComponent} +-- @local function BaseComponent.set_style(self, druid_style) self._meta.style = druid_style or {} local component_style = self._meta.style[self._component.name] or {} @@ -95,6 +96,7 @@ end -- @tparam BaseComponent self @{BaseComponent} -- @tparam string template BaseComponent template name -- @treturn BaseComponent @{BaseComponent} +-- @local function BaseComponent.set_template(self, template) template = template or "" @@ -131,6 +133,7 @@ end -- local nodes = gui.clone_tree(self.prefab) -- ... In your component: -- self:set_nodes(nodes) +-- @local function BaseComponent.set_nodes(self, nodes) self._meta.nodes = nodes diff --git a/utils/annotations_manual.lua b/utils/annotations_manual.lua index ab4169d..46b8284 100644 --- a/utils/annotations_manual.lua +++ b/utils/annotations_manual.lua @@ -99,4 +99,28 @@ ---@param component T Component module ---@param ... any Other component params to pass it to component:init function ---@return T Component instance -function druid_instance.new(self, component, ...) end \ No newline at end of file +function druid_instance.new(self, component, ...) end + +--- Set current component style table. +--- Invoke `on_style_change` on component, if exist. Component should handle their style changing and store all style params +---@generic T: druid.base_component +---@param self T @{BaseComponent} +---@param druid_style table|nil Druid style module +---@return T @{BaseComponent} +function druid__base_component.set_style(self, druid_style) end + +--- Set component template name. +--- Use on all your custom components with GUI layouts used as templates. It will check parent template name to build full template name in self:get_node() +---@generic T: druid.base_component +---@param self T @{BaseComponent} +---@param template string BaseComponent template name +---@return T @{BaseComponent} +function druid__base_component.set_template(self, template) end + +--- Set current component nodes. +--- Use if your component nodes was cloned with `gui.clone_tree` and you got the node tree. +---@generic T: druid.base_component +---@param self T @{BaseComponent} +---@param nodes table BaseComponent nodes table +---@return T @{BaseComponent} +function druid__base_component.set_nodes(self, nodes) end