mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Update docs, update custom component templates
This commit is contained in:
parent
f801bb6862
commit
dc76d3b3d4
@ -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)
|
||||
|
@ -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])
|
||||
|
25
druid/templates/component.template.lua
Normal file
25
druid/templates/component.template.lua
Normal file
@ -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
|
@ -1,15 +1,27 @@
|
||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. 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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user