mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
Add example docs for LDoc
This commit is contained in:
parent
4d424a34c2
commit
b72e7451e1
@ -1,3 +1,6 @@
|
|||||||
|
--- Component to handle back key
|
||||||
|
-- @module base.back_handler
|
||||||
|
|
||||||
local data = require("druid.data")
|
local data = require("druid.data")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@ -5,21 +8,25 @@ M.interest = {
|
|||||||
data.ON_INPUT
|
data.ON_INPUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--- Component init function
|
||||||
|
-- @tparam table self component instance
|
||||||
|
-- @tparam callback callback on back button
|
||||||
|
-- @tparam[opt] params callback argument
|
||||||
function M.init(self, callback, params)
|
function M.init(self, callback, params)
|
||||||
self.event = data.A_ANDR_BACK
|
self.event = data.ACTION_BACK
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.params = params
|
self.params = params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- input handler
|
--- Input handler for component
|
||||||
-- @param action_id - input action id
|
-- @tparam string action_id on_input action id
|
||||||
-- @param action - input action
|
-- @tparam table action on_input action
|
||||||
function M.on_input(self, action_id, action)
|
function M.on_input(self, action_id, action)
|
||||||
if action[data.RELEASED] then
|
if action[data.RELEASED] then
|
||||||
self.callback(self.parent.parent, self.params)
|
self.callback(self.parent.parent, self.params)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
--- Component to handle basic GUI button
|
||||||
|
-- @module base.button
|
||||||
|
|
||||||
local data = require("druid.data")
|
local data = require("druid.data")
|
||||||
local ui_animate = require("druid.helper.druid_animate")
|
local ui_animate = require("druid.helper.druid_animate")
|
||||||
local settings = require("druid.settings")
|
local settings = require("druid.settings")
|
||||||
@ -17,7 +20,7 @@ M.DEFAUL_ACTIVATION_TIME = 0.2
|
|||||||
|
|
||||||
function M.init(self, node, callback, params, anim_node, event)
|
function M.init(self, node, callback, params, anim_node, event)
|
||||||
self.node = helper.get_node(node)
|
self.node = helper.get_node(node)
|
||||||
self.event = data.A_TOUCH
|
self.event = data.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
|
||||||
self.scale_from = gui.get_scale(self.anim_node)
|
self.scale_from = gui.get_scale(self.anim_node)
|
||||||
self.scale_to = self.scale_from + b_settings.SCALE_CHANGE
|
self.scale_to = self.scale_from + b_settings.SCALE_CHANGE
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
--- Component to handle placing components by row and columns.
|
||||||
|
-- Grid can anchor your elements, get content size and other
|
||||||
|
-- @module base.grid
|
||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
--- Sort and placing nodes
|
|
||||||
-- Plans: placing by max width, placing with max in_row
|
|
||||||
-- Allow different node sizes, allow animation with node insert
|
|
||||||
|
|
||||||
|
|
||||||
function M.init(self, parent, element, in_row)
|
function M.init(self, parent, element, in_row)
|
||||||
self.parent = helper.get_node(parent)
|
self.parent = helper.get_node(parent)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
--- Component to handle progress bars
|
||||||
|
-- @module base.progress
|
||||||
|
|
||||||
local data = require("druid.data")
|
local data = require("druid.data")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local settings = require("druid.settings")
|
local settings = require("druid.settings")
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
--- Component to handle scroll content
|
||||||
|
-- @module base.scroll
|
||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local data = require("druid.data")
|
local data = require("druid.data")
|
||||||
local settings = require("druid.settings").scroll
|
local settings = require("druid.settings").scroll
|
||||||
@ -310,7 +313,11 @@ function M.on_input(self, action_id, action)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Start scroll to point (x, y, z)
|
--- Start scroll to target point
|
||||||
|
-- @tparam point vector3 target point
|
||||||
|
-- @tparam[opt] bool is_instant instant scroll flag
|
||||||
|
-- @usage scroll:scroll_to(vmath.vector3(0, 50, 0))
|
||||||
|
-- @usage scroll:scroll_to(vmath.vector3(0), true)
|
||||||
function M.scroll_to(self, point, is_instant)
|
function M.scroll_to(self, point, is_instant)
|
||||||
local b = self.border
|
local b = self.border
|
||||||
local target = vmath.vector3(point)
|
local target = vmath.vector3(point)
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
--- Component to handle all GUI texts
|
||||||
|
-- Good working with localization system
|
||||||
|
-- @module base.text
|
||||||
|
|
||||||
local data = require("druid.data")
|
local data = require("druid.data")
|
||||||
local settings = require("druid.settings")
|
local settings = require("druid.settings")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
--- Component to handle GUI timers
|
||||||
|
-- @module base.timer
|
||||||
|
|
||||||
local data = require("druid.data")
|
local data = require("druid.data")
|
||||||
local formats = require("druid.helper.formats")
|
local formats = require("druid.helper.formats")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
@ -9,6 +12,7 @@ M.interest = {
|
|||||||
|
|
||||||
local empty = function() end
|
local empty = function() end
|
||||||
|
|
||||||
|
|
||||||
function M.init(self, node, seconds_from, seconds_to, callback)
|
function M.init(self, node, seconds_from, seconds_to, callback)
|
||||||
self.node = helper.get_node(node)
|
self.node = helper.get_node(node)
|
||||||
seconds_from = math.max(seconds_from, 0)
|
seconds_from = math.max(seconds_from, 0)
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
|
--- Druid constants
|
||||||
|
-- @module constants
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- Actions
|
-- Actions
|
||||||
M.A_TOUCH = hash("touch")
|
M.ACTION_TOUCH = hash("touch")
|
||||||
M.A_TEXT = hash("text")
|
M.ACTION_TEXT = hash("text")
|
||||||
M.A_BACKSPACE = hash("backspace")
|
M.ACTION_BACKSPACE = hash("backspace")
|
||||||
M.A_ENTER = hash("enter")
|
M.ACTION_ENTER = hash("enter")
|
||||||
M.A_ANDR_BACK = hash("back")
|
M.ACTION_BACK = hash("back")
|
||||||
|
|
||||||
M.RELEASED = "released"
|
M.RELEASED = "released"
|
||||||
M.PRESSED = "pressed"
|
M.PRESSED = "pressed"
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
--- Druid UI Library.
|
||||||
|
-- Component based UI library to make your life easier.
|
||||||
|
-- Contains a lot of base components and give API
|
||||||
|
-- to create your own rich components.
|
||||||
|
-- @module druid
|
||||||
|
|
||||||
local data = require("druid.data")
|
local data = require("druid.data")
|
||||||
local druid_input = require("druid.helper.druid_input")
|
local druid_input = require("druid.helper.druid_input")
|
||||||
local settings = require("druid.settings")
|
local settings = require("druid.settings")
|
||||||
@ -7,6 +13,7 @@ local M = {}
|
|||||||
local log = settings.log
|
local log = settings.log
|
||||||
local _fct_metatable = {}
|
local _fct_metatable = {}
|
||||||
|
|
||||||
|
--- Basic components
|
||||||
M.comps = {
|
M.comps = {
|
||||||
button = require("druid.base.button"),
|
button = require("druid.base.button"),
|
||||||
back_handler = require("druid.base.back_handler"),
|
back_handler = require("druid.base.back_handler"),
|
||||||
@ -31,6 +38,9 @@ local function register_basic_components()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Register external module
|
||||||
|
-- @tparam string name module name
|
||||||
|
-- @tparam table module lua table with module
|
||||||
function M.register(name, module)
|
function M.register(name, module)
|
||||||
-- TODO: Find better solution to creating elements?
|
-- TODO: Find better solution to creating elements?
|
||||||
_fct_metatable["new_" .. name] = function(self, ...)
|
_fct_metatable["new_" .. name] = function(self, ...)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
--- Druid helper module
|
||||||
|
-- @module helper
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
--- Text node or icon node can be nil
|
--- Text node or icon node can be nil
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
--- Druid helper module for animating GUI nodes
|
||||||
|
-- @module helper.animate
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local PROP_SCALE = gui.PROP_SCALE
|
local PROP_SCALE = gui.PROP_SCALE
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
--- Druid inner module to acquire/release input
|
||||||
|
-- @module helper.input
|
||||||
|
-- @local
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local ADD_FOCUS = hash("acquire_input_focus")
|
local ADD_FOCUS = hash("acquire_input_focus")
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
|
--- Druid module with utils on string formats
|
||||||
|
-- @module helper.formats
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local ZERO = "0"
|
local ZERO = "0"
|
||||||
|
|
||||||
-- Return number with zero number prefix
|
--- Return number with zero number prefix
|
||||||
-- @param num - number for conversion
|
-- @param num number for conversion
|
||||||
-- @param count - count of numerals
|
-- @param count count of numerals
|
||||||
-- @return string with need count of zero (1,3) -> 001
|
-- @return string with need count of zero (1,3) -> 001
|
||||||
function M.add_prefix_zeros(num, count)
|
function M.add_prefix_zeros(num, count)
|
||||||
local result = tostring(num)
|
local result = tostring(num)
|
||||||
@ -15,8 +18,8 @@ function M.add_prefix_zeros(num, count)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Convert seconds to string minutes:seconds
|
--- Convert seconds to string minutes:seconds
|
||||||
-- @param num - number of seconds
|
-- @param num number of seconds
|
||||||
-- @return string minutes:seconds
|
-- @return string minutes:seconds
|
||||||
function M.second_string_min(sec)
|
function M.second_string_min(sec)
|
||||||
local mins = math.floor(sec / 60)
|
local mins = math.floor(sec / 60)
|
||||||
@ -25,11 +28,11 @@ function M.second_string_min(sec)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Interpolate string with named Parameters in Table
|
--- Interpolate string with named Parameters in Table
|
||||||
-- @param s - string for interpolate
|
-- @param s string for interpolate
|
||||||
-- @param tab - table with parameters
|
-- @param tab table with parameters
|
||||||
-- @return string with replaced parameters
|
-- @return string with replaced parameters
|
||||||
function M.interpolate_strinng(s, tab)
|
function M.interpolate_string(s, tab)
|
||||||
return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
|
return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
--- Druid settings file
|
||||||
|
-- @module settings
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
-- TODO: to JSON?
|
||||||
M.is_debug = false
|
M.is_debug = false
|
||||||
|
|
||||||
M.button = {
|
M.button = {
|
||||||
IS_HOVER = true,
|
IS_HOVER = true,
|
||||||
IS_HOLD = true,
|
IS_HOLD = true,
|
||||||
@ -34,7 +37,7 @@ M.scroll = {
|
|||||||
|
|
||||||
function M.get_text(name)
|
function M.get_text(name)
|
||||||
-- override to get text for localized text
|
-- override to get text for localized text
|
||||||
return "locales not inited"
|
return "[Druid]: locales not inited"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user