Update ldoc code comments

This commit is contained in:
Insality 2020-02-05 02:44:09 +03:00
parent 92098052e3
commit 544fd8d736
18 changed files with 98 additions and 20 deletions

View File

@ -1,5 +1,5 @@
--- Component to handle back key (android, backspace) --- Component to handle back key (android, backspace)
-- @module base.back_handler -- @module druid.back_handler
local const = require("druid.const") local const = require("druid.const")
local component = require("druid.system.component") local component = require("druid.system.component")

View File

@ -1,5 +1,5 @@
--- Component to block input on specify zone (node) --- Component to block input on specify zone (node)
-- @module base.blocker -- @module druid.blocker
local const = require("druid.const") local const = require("druid.const")
local helper = require("druid.helper") local helper = require("druid.helper")

View File

@ -1,5 +1,5 @@
--- Component to handle basic GUI button --- Component to handle basic GUI button
-- @module base.button -- @module druid.button
-- TODO: Add button mode: -- TODO: Add button mode:
-- Long tap -- Long tap
@ -26,8 +26,10 @@ function M.init(self, node, callback, params, anim_node, event)
self.style = self:get_style() self.style = self:get_style()
self.node = helper.get_node(node) self.node = helper.get_node(node)
-- TODO: match event inside on_input?
self.event = const.ACTION_TOUCH self.event = const.ACTION_TOUCH
self.anim_node = anim_node and helper.get_node(anim_node) or self.node self.anim_node = anim_node and helper.get_node(anim_node) or self.node
-- TODO: rename to start_scale
self.scale_from = gui.get_scale(self.anim_node) self.scale_from = gui.get_scale(self.anim_node)
self.pos = gui.get_position(self.anim_node) self.pos = gui.get_position(self.anim_node)
self.callback = callback self.callback = callback

View File

@ -1,5 +1,5 @@
--- Druid checkbox component --- Druid checkbox component
-- @module base.checkbox -- @module druid.checkbox
local helper = require("druid.helper") local helper = require("druid.helper")
local component = require("druid.system.component") local component = require("druid.system.component")

View File

@ -1,5 +1,5 @@
--- Checkboux group module --- Checkboux group module
-- @module base.checkbox_group -- @module druid.checkbox_group
local component = require("druid.system.component") local component = require("druid.system.component")

View File

@ -1,6 +1,6 @@
--- Component to handle placing components by row and columns. --- Component to handle placing components by row and columns.
-- Grid can anchor your elements, get content size and other -- Grid can anchor your elements, get content size and other
-- @module base.grid -- @module druid.grid
local helper = require("druid.helper") local helper = require("druid.helper")
local component = require("druid.system.component") local component = require("druid.system.component")

View File

@ -1,6 +1,6 @@
--- Component to handle all GUI texts --- Component to handle all GUI texts
-- Good working with localization system -- Good working with localization system
-- @module base.text -- @module druid.locale
local const = require("druid.const") local const = require("druid.const")
local settings = require("druid.system.settings") local settings = require("druid.system.settings")

View File

@ -1,5 +1,5 @@
--- Basic progress bar component --- Basic progress bar component
-- @module base.progress -- @module druid.progress
local const = require("druid.const") local const = require("druid.const")
local helper = require("druid.helper") local helper = require("druid.helper")

View File

@ -1,5 +1,5 @@
--- Radio group module --- Radio group module
-- @module base.checkbox_group -- @module druid.radio_group
local component = require("druid.system.component") local component = require("druid.system.component")

View File

@ -1,5 +1,5 @@
--- Component to handle scroll content --- Component to handle scroll content
-- @module base.scroll -- @module druid.scroll
local helper = require("druid.helper") local helper = require("druid.helper")
local const = require("druid.const") local const = require("druid.const")

View File

@ -1,5 +1,5 @@
--- Druid slider component --- Druid slider component
-- @module base.slider -- @module druid.slider
local helper = require("druid.helper") local helper = require("druid.helper")
local const = require("druid.const") local const = require("druid.const")

View File

@ -1,6 +1,6 @@
--- Component to handle all GUI texts --- Component to handle all GUI texts
-- Good working with localization system -- Good working with localization system
-- @module base.text -- @module druid.text
local const = require("druid.const") local const = require("druid.const")
local helper = require("druid.helper") local helper = require("druid.helper")

View File

@ -1,5 +1,5 @@
--- Component to handle GUI timers --- Component to handle GUI timers
-- @module base.timer -- @module druid.timer
local const = require("druid.const") local const = require("druid.const")
local formats = require("druid.helper.formats") local formats = require("druid.helper.formats")

View File

@ -1,8 +1,9 @@
--- Druid constants --- Druid constants
-- @module constants -- @module const
local M = {} local M = {}
-- Actions -- Actions
M.ACTION_TOUCH = hash("touch") M.ACTION_TOUCH = hash("touch")
M.ACTION_TEXT = hash("text") M.ACTION_TEXT = hash("text")
@ -10,22 +11,25 @@ M.ACTION_BACKSPACE = hash("backspace")
M.ACTION_ENTER = hash("enter") M.ACTION_ENTER = hash("enter")
M.ACTION_BACK = hash("back") M.ACTION_BACK = hash("back")
M.RELEASED = "released" M.RELEASED = "released"
M.PRESSED = "pressed" M.PRESSED = "pressed"
M.STRING = "string" M.STRING = "string"
M.TABLE = "table" M.TABLE = "table"
M.ZERO = "0" M.ZERO = "0"
M.ALL = "all" M.ALL = "all"
--- Interests --- Interests
M.ON_MESSAGE = hash("on_message") M.ON_MESSAGE = hash("on_message")
M.ON_UPDATE = hash("on_update") M.ON_UPDATE = hash("on_update")
-- Input -- Input
M.ON_SWIPE = hash("on_swipe") M.ON_SWIPE = hash("on_swipe")
M.ON_INPUT = hash("on_input") M.ON_INPUT = hash("on_input")
M.PIVOTS = { M.PIVOTS = {
[gui.PIVOT_CENTER] = vmath.vector3(0), [gui.PIVOT_CENTER] = vmath.vector3(0),
[gui.PIVOT_N] = vmath.vector3(0, 0.5, 0), [gui.PIVOT_N] = vmath.vector3(0, 0.5, 0),
@ -38,11 +42,13 @@ M.PIVOTS = {
[gui.PIVOT_NW] = vmath.vector3(-0.5, 0.5, 0), [gui.PIVOT_NW] = vmath.vector3(-0.5, 0.5, 0),
} }
M.SIDE = { M.SIDE = {
X = "x", X = "x",
Y = "y" Y = "y"
} }
M.UI_INPUT = { M.UI_INPUT = {
[M.ON_SWIPE] = true, [M.ON_SWIPE] = true,
[M.ON_INPUT] = true [M.ON_INPUT] = true
@ -52,13 +58,34 @@ M.UI_INPUT = {
M.ON_CHANGE_LANGUAGE = hash("on_change_language") M.ON_CHANGE_LANGUAGE = hash("on_change_language")
M.ON_LAYOUT_CHANGED = hash("on_layout_changed") M.ON_LAYOUT_CHANGED = hash("on_layout_changed")
M.SPECIFIC_UI_MESSAGES = { M.SPECIFIC_UI_MESSAGES = {
[M.ON_CHANGE_LANGUAGE] = "on_change_language", [M.ON_CHANGE_LANGUAGE] = "on_change_language",
[M.ON_LAYOUT_CHANGED] = "on_layout_changed" [M.ON_LAYOUT_CHANGED] = "on_layout_changed"
} }
-- Basic druid components
M.COMPONENTS = {
BUTTON = "button",
BLOCKER = "blocker",
BACK_HANDLER = "back_handler",
TEXT = "text",
LOCALE = "locale",
TIMER = "timer",
PROGRESS = "progress",
GRID = "grid",
SCROLL = "scroll",
SLIDER = "slider",
CHECKBOX = "checkbox",
CHECKBOX_GROUP = "checkbox_group",
RADIO_GROUP = "radio_group",
}
M.EMPTY_FUNCTION = function() end M.EMPTY_FUNCTION = function() end
M.EMPTY_STRING = "" M.EMPTY_STRING = ""
M.EMPTY_TABLE = {} M.EMPTY_TABLE = {}
return M return M

View File

@ -1,4 +1,4 @@
--- Druid helper module -- Druid helper module
-- @module helper -- @module helper
local const = require("druid.const") local const = require("druid.const")

View File

@ -1,4 +1,4 @@
--- Druid helper module for animating GUI nodes -- Druid helper module for animating GUI nodes
-- @module helper.animate -- @module helper.animate
local M = {} local M = {}

View File

@ -1,5 +1,5 @@
--- Component for rich progress component --- Component for rich progress component
-- @module rich.progress_rich -- @module druid.progress_rich
local component = require("druid.system.component") local component = require("druid.system.component")

View File

@ -1,12 +1,19 @@
--- General component class --- Basic class for all Druid components.
--@class component -- To create you component, use `component.create`
-- @module component
local const = require("druid.const") local const = require("druid.const")
local class = require("druid.system.middleclass") local class = require("druid.system.middleclass")
-- @classmod Component
local Component = class("druid.component") local Component = class("druid.component")
--- Setup component context and his style table
-- @function component:setup_component
-- @tparam context table Druid context. Usually it is self of script
-- @tparam style table Druid style module
-- @treturn Component Component itself
function Component.setup_component(self, context, style) function Component.setup_component(self, context, style)
self._meta = { self._meta = {
template = nil, template = nil,
@ -22,6 +29,9 @@ function Component.setup_component(self, context, style)
end end
--- Get current component style table
-- @function component:get_style
-- @treturn table Component style table
function Component.get_style(self) function Component.get_style(self)
if not self._meta.style then if not self._meta.style then
return const.EMPTY_TABLE return const.EMPTY_TABLE
@ -31,41 +41,65 @@ function Component.get_style(self)
end end
--- Set current component style table
-- @function component:set_style
-- @tparam table style Druid style module
function Component.set_style(self, druid_style) function Component.set_style(self, druid_style)
self._meta.style = druid_style self._meta.style = druid_style
end end
--- Get current component template name
-- @function component:get_template
-- @treturn string Component template name
function Component.get_template(self) function Component.get_template(self)
return self._meta.template return self._meta.template
end end
--- Set current component template name
-- @function component:set_template
-- @tparam string template Component template name
function Component.set_template(self, template) function Component.set_template(self, template)
self._meta.template = template self._meta.template = template
end end
--- Get current component nodes
-- @function component:get_nodes
-- @treturn table Component nodes table
function Component.get_nodes(self) function Component.get_nodes(self)
return self._meta.nodes return self._meta.nodes
end end
--- Set current component nodes
-- @function component:set_nodes
-- @tparam table nodes Component nodes table
function Component.set_nodes(self, nodes) function Component.set_nodes(self, nodes)
self._meta.nodes = nodes self._meta.nodes = nodes
end end
--- Get current component context
-- @function component:get_context
-- @treturn table Component context
function Component.get_context(self, context) function Component.get_context(self, context)
return self._meta.context return self._meta.context
end end
--- Set current component context
-- @function component:set_context
-- @tparam table context Druid context. Usually it is self of script
function Component.set_context(self, context) function Component.set_context(self, context)
self._meta.context = context self._meta.context = context
end end
--- Get current component interests
-- @function component:get_interests
-- @treturn table List of component interests
function Component.get_interests(self) function Component.get_interests(self)
return self._component.interest return self._component.interest
end end
@ -91,12 +125,22 @@ function Component.get_node(self, node_or_name)
end end
--- Return druid with context of calling component.
-- Use it to create component inside of other components.
-- @function component:get_druid
-- @treturn Druid Druid instance with component context
function Component.get_druid(self) function Component.get_druid(self)
local context = { _context = self } local context = { _context = self }
return setmetatable(context, { __index = self:get_context().druid }) return setmetatable(context, { __index = self:get_context().druid })
end end
--- Basic constructor of component. It will call automaticaly
-- by `Component.static.create`
-- @function component:initialize
-- @tparam string name Component name
-- @tparam table interest List of component's interest
-- @local
function Component.initialize(self, name, interest) function Component.initialize(self, name, interest)
self._component = { self._component = {
name = name, name = name,
@ -105,6 +149,11 @@ function Component.initialize(self, name, interest)
end end
--- Create new component. It will inheritance from basic
-- druid component.
-- @function Component.create
-- @tparam string name Component name
-- @tparam table interest List of component's interest
function Component.static.create(name, interest) function Component.static.create(name, interest)
-- Yea, inheritance here -- Yea, inheritance here
local new_class = class(name, Component) local new_class = class(name, Component)