From e45dce150d3b76c693eb636c982a9c2ce5b67541 Mon Sep 17 00:00:00 2001
From: Insality
Date: Thu, 5 Dec 2019 21:34:16 +0300
Subject: [PATCH 1/4] Rename helper.get_node -> helper.node
---
druid/base/blocker.lua | 2 +-
druid/base/button.lua | 6 +++---
druid/base/checkbox.lua | 4 ++--
druid/base/grid.lua | 4 ++--
druid/base/progress.lua | 2 +-
druid/base/scroll.lua | 4 ++--
druid/base/slider.lua | 2 +-
druid/base/text.lua | 2 +-
druid/base/timer.lua | 2 +-
druid/helper.lua | 6 ++++--
10 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/druid/base/blocker.lua b/druid/base/blocker.lua
index 14f3fc2..4212ec4 100644
--- a/druid/base/blocker.lua
+++ b/druid/base/blocker.lua
@@ -12,7 +12,7 @@ M.interest = {
function M.init(self, node)
- self.node = helper.get_node(node)
+ self.node = helper.node(node)
self.event = const.ACTION_TOUCH
end
diff --git a/druid/base/button.lua b/druid/base/button.lua
index 2f87afd..80b519d 100644
--- a/druid/base/button.lua
+++ b/druid/base/button.lua
@@ -23,9 +23,9 @@ M.DEFAULT_ACTIVATION_TIME = 0.2
function M.init(self, node, callback, params, anim_node, event)
- self.node = helper.get_node(node)
+ self.node = helper.node(node)
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.node(anim_node) or self.node
self.scale_from = gui.get_scale(self.anim_node)
self.scale_to = self.scale_from + b_settings.SCALE_CHANGE
self.scale_hover_to = self.scale_from + b_settings.HOVER_SCALE
@@ -207,7 +207,7 @@ end
--- Set additional node, what need to be clicked on button click
-- Used, if need setup, what button can be clicked only in special zone
function M.set_click_zone(self, zone)
- self.click_zone = helper.get_node(zone)
+ self.click_zone = helper.node(zone)
end
diff --git a/druid/base/checkbox.lua b/druid/base/checkbox.lua
index 0b3dbb2..d7290d2 100644
--- a/druid/base/checkbox.lua
+++ b/druid/base/checkbox.lua
@@ -38,8 +38,8 @@ end
function M.init(self, node, callback, click_node)
- self.node = helper.get_node(node)
- self.click_node = helper.get_node(click_node)
+ self.node = helper.node(node)
+ self.click_node = helper.node(click_node)
self.callback = callback
self.button = self.parent:new_button(self.click_node or self.node, on_click, self)
diff --git a/druid/base/grid.lua b/druid/base/grid.lua
index acdfcbd..e47e69e 100644
--- a/druid/base/grid.lua
+++ b/druid/base/grid.lua
@@ -8,13 +8,13 @@ local M = {}
function M.init(self, parent, element, in_row)
- self.parent = helper.get_node(parent)
+ self.parent = helper.node(parent)
self.nodes = {}
self.offset = vmath.vector3(0)
self.anchor = vmath.vector3(0.5, 0, 0)
self.in_row = in_row or 1
- self.node_size = gui.get_size(helper.get_node(element))
+ self.node_size = gui.get_size(helper.node(element))
self.border = vmath.vector4(0)
self.border_offset = vmath.vector3(0)
end
diff --git a/druid/base/progress.lua b/druid/base/progress.lua
index d8cc122..b574350 100644
--- a/druid/base/progress.lua
+++ b/druid/base/progress.lua
@@ -25,7 +25,7 @@ function M.init(self, name, key, init_value)
self.prop = hash("scale."..key)
self.key = key
- self.node = helper.get_node(name)
+ self.node = helper.node(name)
self.scale = gui.get_scale(self.node)
self.size = gui.get_size(self.node)
self.max_size = self.size[self.key]
diff --git a/druid/base/scroll.lua b/druid/base/scroll.lua
index 622b18d..f4c4bf7 100644
--- a/druid/base/scroll.lua
+++ b/druid/base/scroll.lua
@@ -20,8 +20,8 @@ M.current_scroll = nil
function M.init(self, scroll_parent, input_zone, border)
- self.node = helper.get_node(scroll_parent)
- self.input_zone = helper.get_node(input_zone)
+ self.node = helper.node(scroll_parent)
+ self.input_zone = helper.node(input_zone)
self.zone_size = gui.get_size(self.input_zone)
self.soft_size = settings.SOFT_ZONE_SIZE
diff --git a/druid/base/slider.lua b/druid/base/slider.lua
index ff2881f..29f25c0 100644
--- a/druid/base/slider.lua
+++ b/druid/base/slider.lua
@@ -18,7 +18,7 @@ end
function M.init(self, node, end_pos, callback)
- self.node = helper.get_node(node)
+ self.node = helper.node(node)
self.start_pos = gui.get_position(self.node)
self.pos = gui.get_position(self.node)
diff --git a/druid/base/text.lua b/druid/base/text.lua
index b3fbe0a..7405b67 100644
--- a/druid/base/text.lua
+++ b/druid/base/text.lua
@@ -14,7 +14,7 @@ M.interest = {
function M.init(self, node, value, is_locale, max_width)
self.max_width = max_width
- self.node = helper.get_node(node)
+ self.node = helper.node(node)
self.start_scale = gui.get_scale(self.node)
self.scale = self.start_scale
self.last_color = gui.get_color(self.node)
diff --git a/druid/base/timer.lua b/druid/base/timer.lua
index 2ab6cb7..9f7210e 100644
--- a/druid/base/timer.lua
+++ b/druid/base/timer.lua
@@ -14,7 +14,7 @@ local empty = function() end
function M.init(self, node, seconds_from, seconds_to, callback)
- self.node = helper.get_node(node)
+ self.node = helper.node(node)
seconds_from = math.max(seconds_from, 0)
seconds_to = math.max(seconds_to or 0, 0)
callback = callback or empty
diff --git a/druid/helper.lua b/druid/helper.lua
index 1ef342f..2aaea67 100644
--- a/druid/helper.lua
+++ b/druid/helper.lua
@@ -1,6 +1,8 @@
--- Druid helper module
-- @module helper
+local const = require("druid.const")
+
local M = {}
--- Text node or icon node can be nil
@@ -80,8 +82,8 @@ end
local STRING = "string"
-function M.get_node(node_or_name)
- if type(node_or_name) == STRING then
+function M.node(node_or_name)
+ if type(node_or_name) == const.STRING then
return gui.get_node(node_or_name)
end
return node_or_name
From f8a3b6f632eb734bae6bd07ec5759d8bede26339 Mon Sep 17 00:00:00 2001
From: Insality
Date: Thu, 5 Dec 2019 21:34:26 +0300
Subject: [PATCH 2/4] Move const to const.lua
---
druid/const.lua | 15 ++++++++++++++-
druid/druid.lua | 4 ++--
druid/helper.lua | 14 +-------------
3 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/druid/const.lua b/druid/const.lua
index eb870dd..be3968b 100644
--- a/druid/const.lua
+++ b/druid/const.lua
@@ -12,6 +12,7 @@ M.ACTION_BACK = hash("back")
M.RELEASED = "released"
M.PRESSED = "pressed"
+M.STRING = "string"
--- Interests
M.ON_MESSAGE = hash("on_message")
@@ -21,6 +22,18 @@ M.ON_UPDATE = hash("on_update")
M.ON_SWIPE = hash("on_swipe")
M.ON_INPUT = hash("on_input")
+M.PIVOTS = {
+ [gui.PIVOT_CENTER] = vmath.vector3(0),
+ [gui.PIVOT_N] = vmath.vector3(0, 0.5, 0),
+ [gui.PIVOT_NE] = vmath.vector3(0.5, 0.5, 0),
+ [gui.PIVOT_E] = vmath.vector3(0.5, 0, 0),
+ [gui.PIVOT_SE] = vmath.vector3(0.5, -0.5, 0),
+ [gui.PIVOT_S] = vmath.vector3(0, -0.5, 0),
+ [gui.PIVOT_SW] = vmath.vector3(-0.5, -0.5, 0),
+ [gui.PIVOT_W] = vmath.vector3(-0.5, 0, 0),
+ [gui.PIVOT_NW] = vmath.vector3(-0.5, -0.5, 0),
+}
+
M.ui_input = {
[M.ON_SWIPE] = true,
[M.ON_INPUT] = true
@@ -30,7 +43,7 @@ M.ui_input = {
M.ON_CHANGE_LANGUAGE = hash("on_change_language")
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_LAYOUT_CHANGED] = "on_layout_changed"
}
diff --git a/druid/druid.lua b/druid/druid.lua
index f5b7c87..d0170f7 100644
--- a/druid/druid.lua
+++ b/druid/druid.lua
@@ -91,7 +91,7 @@ local function create(self, module)
end
self[v][#self[v] + 1] = instance
- if const.ui_input[v] then
+ if const.UI_INPUT[v] then
input_init(self)
end
end
@@ -135,7 +135,7 @@ end
--- Called on_message
function _fct_metatable.on_message(self, message_id, message, sender)
- local specific_ui_message = const.specific_ui_messages[message_id]
+ local specific_ui_message = const.SPECIFIC_UI_MESSAGES[message_id]
if specific_ui_message then
local array = self[message_id]
if array then
diff --git a/druid/helper.lua b/druid/helper.lua
index 2aaea67..c7c7a36 100644
--- a/druid/helper.lua
+++ b/druid/helper.lua
@@ -81,7 +81,6 @@ function M.after(count, callback)
end
-local STRING = "string"
function M.node(node_or_name)
if type(node_or_name) == const.STRING then
return gui.get_node(node_or_name)
@@ -144,19 +143,8 @@ function M.is_enabled(node)
end
-local pivots = {
- [gui.PIVOT_CENTER] = vmath.vector3(0),
- [gui.PIVOT_N] = vmath.vector3(0, 0.5, 0),
- [gui.PIVOT_NE] = vmath.vector3(0.5, 0.5, 0),
- [gui.PIVOT_E] = vmath.vector3(0.5, 0, 0),
- [gui.PIVOT_SE] = vmath.vector3(0.5, -0.5, 0),
- [gui.PIVOT_S] = vmath.vector3(0, -0.5, 0),
- [gui.PIVOT_SW] = vmath.vector3(-0.5, -0.5, 0),
- [gui.PIVOT_W] = vmath.vector3(-0.5, 0, 0),
- [gui.PIVOT_NW] = vmath.vector3(-0.5, -0.5, 0),
-}
function M.get_pivot_offset(pivot)
- return pivots[pivot]
+ return const.PIVOTS[pivot]
end
From 88a37f77af7ba8621ce026b0f9b79850f1de2c77 Mon Sep 17 00:00:00 2001
From: Insality
Date: Thu, 5 Dec 2019 22:05:06 +0300
Subject: [PATCH 3/4] Update ldoc comments
---
druid/base/back_handler.lua | 10 +++--
druid/base/button.lua | 21 +++++++---
druid/base/progress.lua | 51 +++++++++++++++++--------
druid/base/scroll.lua | 39 ++++++++++++-------
druid/base/text.lua | 20 ++++++++--
druid/base/timer.lua | 16 +++++---
druid/const.lua | 8 +++-
druid/helper/formats.lua | 19 +++++----
druid/rich/progress_rich.lua | 74 ++++++++++++++++++++++--------------
9 files changed, 172 insertions(+), 86 deletions(-)
diff --git a/druid/base/back_handler.lua b/druid/base/back_handler.lua
index 4f82c86..dffe1ed 100644
--- a/druid/base/back_handler.lua
+++ b/druid/base/back_handler.lua
@@ -1,4 +1,4 @@
---- Component to handle back key
+--- Component to handle back key (android, backspace)
-- @module base.back_handler
local const = require("druid.const")
@@ -9,9 +9,10 @@ M.interest = {
}
--- Component init function
--- @tparam table self component instance
--- @tparam callback callback on back button
--- @tparam[opt] params callback argument
+-- @function back_handler:init
+-- @tparam table self Component instance
+-- @tparam callback callback On back button
+-- @tparam[opt] params Callback argument
function M.init(self, callback, params)
self.event = const.ACTION_BACK
self.callback = callback
@@ -20,6 +21,7 @@ end
--- Input handler for component
+-- @function back_handler:on_input
-- @tparam string action_id on_input action id
-- @tparam table action on_input action
function M.on_input(self, action_id, action)
diff --git a/druid/base/button.lua b/druid/base/button.lua
index 80b519d..dd80aec 100644
--- a/druid/base/button.lua
+++ b/druid/base/button.lua
@@ -22,6 +22,14 @@ M.DEFAULT_ACTIVATE_SCALE = vmath.vector3(1, 1, 1)
M.DEFAULT_ACTIVATION_TIME = 0.2
+--- Component init function
+-- @function button:init
+-- @tparam table self Component instance
+-- @tparam node node Gui node
+-- @tparam function callback Button callback
+-- @tparam[opt] table params Button callback params
+-- @tparam[opt] node anim_node Button anim node (node, if not provided)
+-- @tparam[opt] string event Button react event, const.ACTION_TOUCH by default
function M.init(self, node, callback, params, anim_node, event)
self.node = helper.node(node)
self.event = const.ACTION_TOUCH
@@ -79,9 +87,6 @@ local function on_button_release(self)
end
---- Set text to text field
--- @param action_id - input action id
--- @param action - input action
function M.on_input(self, action_id, action)
if not helper.is_enabled(self.node) then
return false
@@ -197,6 +202,9 @@ function M.activate(self, is_animate, callback)
end
+--- Disable all button animations
+-- @function button:disable_animation
+-- @tparam table self Component instance
function M.disable_animation(self)
self.hover_anim = false
self.tap_anim = nil
@@ -204,8 +212,11 @@ function M.disable_animation(self)
end
---- Set additional node, what need to be clicked on button click
--- Used, if need setup, what button can be clicked only in special zone
+--- Strict button click area. Useful for
+-- no click events outside stencil node
+-- @function button:set_click_zone
+-- @tparam table self Component instance
+-- @tparam node zone Gui node
function M.set_click_zone(self, zone)
self.click_zone = helper.node(zone)
end
diff --git a/druid/base/progress.lua b/druid/base/progress.lua
index b574350..5f631b7 100644
--- a/druid/base/progress.lua
+++ b/druid/base/progress.lua
@@ -1,4 +1,4 @@
---- Component to handle progress bars
+--- Basic progress bar component
-- @module base.progress
local const = require("druid.const")
@@ -12,25 +12,28 @@ M.interest = {
const.ON_UPDATE,
}
-local PROP_Y = "y"
-local PROP_X = "x"
-
-function M.init(self, name, key, init_value)
- if key ~= PROP_X and key ~= PROP_Y then
+--- Component init function
+-- @function progress:init
+-- @tparam table self Component instance
+-- @tparam string|node node Progress bar fill node or node name
+-- @tparam string key Progress bar direction (x or y)
+-- @tparam number init_value Initial value of progress bar
+function M.init(self, node, key, init_value)
+ if key ~= const.SIDE.X and key ~= const.SIDE.Y then
settings.log("progress component: key must be 'x' or 'y'. Passed:", key)
- key = PROP_X
+ key = const.SIDE.X
end
self.prop = hash("scale."..key)
self.key = key
- self.node = helper.node(name)
+ self.node = helper.node(node)
self.scale = gui.get_scale(self.node)
self.size = gui.get_size(self.node)
self.max_size = self.size[self.key]
self.slice = gui.get_slice9(self.node)
- if key == PROP_X then
+ if key == const.SIDE.X then
self.slice_size = self.slice.x + self.slice.z
else
self.slice_size = self.slice.y + self.slice.w
@@ -83,38 +86,54 @@ end
--- Fill a progress bar and stop progress animation
+-- @function progress:empty
+-- @tparam table self Component instance
function M.fill(self)
set_bar_to(self, 1, true)
end
---- To empty a progress bar
+--- Empty a progress bar
+-- @function progress:empty
+-- @tparam table self Component instance
function M.empty(self)
set_bar_to(self, 0, true)
end
---- Set fill a progress bar to value
--- @param to - value between 0..1
+--- Instant fill progress bar to value
+-- @function progress:set_to
+-- @tparam table self Component instance
+-- @tparam number to Progress bar value, from 0 to 1
function M.set_to(self, to)
set_bar_to(self, to)
end
+--- Return current progress bar value
+-- @function progress:get
+-- @tparam table self Component instance
function M.get(self)
return self.last_value
end
-function M.set_steps(self, steps, step_callback)
+--- Set points on progress bar to fire the callback
+-- @function progress:set_steps
+-- @tparam table self Component instance
+-- @tparam table steps Array of progress bar values
+-- @tparam function callback Callback on intersect step value
+function M.set_steps(self, steps, callback)
self.steps = steps
- self.step_callback = step_callback
+ self.step_callback = callback
end
--- Start animation of a progress bar
--- @param to - value between 0..1
--- @param callback - callback when progress ended if need
+-- @function progress:to
+-- @tparam table self Component instance
+-- @tparam number to value between 0..1
+-- @tparam[opt] function callback Callback on animation ends
function M.to(self, to, callback)
to = helper.clamp(to, 0, 1)
-- cause of float error
diff --git a/druid/base/scroll.lua b/druid/base/scroll.lua
index f4c4bf7..2fbd8bc 100644
--- a/druid/base/scroll.lua
+++ b/druid/base/scroll.lua
@@ -7,15 +7,13 @@ local settings = require("druid.settings").scroll
local M = {}
-local SIDE_X = "x"
-local SIDE_Y = "y"
-
M.interest = {
const.ON_UPDATE,
const.ON_SWIPE,
}
-- Global on all scrolls
+-- TODO: remove it
M.current_scroll = nil
@@ -280,14 +278,11 @@ function M.on_input(self, action_id, action)
if not M.current_scroll and dist >= settings.DEADZONE then
local dx = math.abs(inp.start_x - action.x)
local dy = math.abs(inp.start_y - action.y)
- if dx > dy then
- inp.side = SIDE_X
- else
- inp.side = SIDE_Y
- end
+ inp.side = (dx > dy) and const.SIDE.X or const.SIDE.Y
+
-- Check scroll side if we can scroll
- if (self.can_x and inp.side == SIDE_X or
- self.can_y and inp.side == SIDE_Y) then
+ if (self.can_x and inp.side == const.SIDE.X or
+ self.can_y and inp.side == const.SIDE.Y) then
M.current_scroll = self
end
end
@@ -308,6 +303,7 @@ function M.on_input(self, action_id, action)
M.current_scroll = nil
result = true
end
+
check_threshold(self)
end
@@ -316,6 +312,7 @@ end
--- Start scroll to target point
+-- @function scroll:scroll_to
-- @tparam point vector3 target point
-- @tparam[opt] bool is_instant instant scroll flag
-- @usage scroll:scroll_to(vmath.vector3(0, 50, 0))
@@ -343,7 +340,11 @@ function M.scroll_to(self, point, is_instant)
end
---- Scroll to item in scroll by points index
+--- Scroll to item in scroll by point index
+-- @function scroll:init
+-- @tparam table self Component instance
+-- @tparam number index Point index
+-- @tparam[opt] boolean skip_cb If true, skip the point callback
function M.scroll_to_index(self, index, skip_cb)
index = helper.clamp(index, 1, #self.points)
@@ -359,8 +360,11 @@ function M.scroll_to_index(self, index, skip_cb)
end
---- Set points of interest
+--- Set points of interest.
-- Scroll will always centered on closer points
+-- @function scroll:set_points
+-- @tparam table self Component instance
+-- @tparam table points Array of vector3 points
function M.set_points(self, points)
self.points = points
-- cause of parent move in other side by y
@@ -375,21 +379,30 @@ function M.set_points(self, points)
end
---- Enable or disable scroll inert
+--- Enable or disable scroll inert.
-- If disabled, scroll through points (if exist)
-- If no points, just simple drag without inertion
+-- @function scroll:set_inert
+-- @tparam table self Component instance
+-- @tparam boolean state Inert scroll state
function M.set_inert(self, state)
self.is_inert = state
end
--- Set the callback on scrolling to point (if exist)
+-- @function scroll:on_point_move
+-- @tparam table self Component instance
+-- @tparam function callback Callback on scroll to point of interest
function M.on_point_move(self, callback)
self.on_point_callback = callback
end
--- Set the scroll possibly area
+-- @function scroll:set_border
+-- @tparam table self Component instance
+-- @tparam vmath.vector3 border Size of scrolling area
function M.set_border(self, border)
self.border = border
diff --git a/druid/base/text.lua b/druid/base/text.lua
index 7405b67..f04bbf7 100644
--- a/druid/base/text.lua
+++ b/druid/base/text.lua
@@ -29,6 +29,10 @@ function M.init(self, node, value, is_locale, max_width)
end
+--- Translate the text by locale_id
+-- @function text:translate
+-- @tparam table self Component instance
+-- @tparam string locale_id Locale id
function M.translate(self, locale_id)
self.last_locale = locale_id or self.last_locale
self:set_to(settings.get_text(self.last_locale))
@@ -56,7 +60,9 @@ end
--- Set text to text field
--- @param set_to - set value to text field
+-- @function text:set_to
+-- @tparam table self Component instance
+-- @tparam string set_to Text for node
function M.set_to(self, set_to)
self.last_value = set_to
gui.set_text(self.node, set_to)
@@ -68,7 +74,9 @@ end
--- Set color
--- @param color
+-- @function text:set_color
+-- @tparam table self Component instance
+-- @tparam vmath.vector4 color Color for node
function M.set_color(self, color)
self.last_color = color
gui.set_color(self.node, color)
@@ -76,7 +84,9 @@ end
--- Set alpha
--- @param alpha, number [0-1]
+-- @function text:set_alpha
+-- @tparam table self Component instance
+-- @tparam number alpha Alpha for node
function M.set_alpha(self, alpha)
self.last_color.w = alpha
gui.set_color(self.node, self.last_color)
@@ -84,7 +94,9 @@ end
--- Set scale
--- @param scale
+-- @function text:set_scale
+-- @tparam table self Component instance
+-- @tparam vmath.vector3 scale Scale for node
function M.set_scale(self, scale)
self.last_scale = scale
gui.set_scale(self.node, scale)
diff --git a/druid/base/timer.lua b/druid/base/timer.lua
index 9f7210e..af22d1f 100644
--- a/druid/base/timer.lua
+++ b/druid/base/timer.lua
@@ -32,7 +32,9 @@ end
--- Set text to text field
--- @param set_to - set value in seconds
+-- @function timer:set_to
+-- @tparam table self Component instance
+-- @tparam number set_to Value in seconds
function M.set_to(self, set_to)
self.last_value = set_to
gui.set_text(self.node, formats.second_string_min(set_to))
@@ -40,15 +42,19 @@ end
--- Called when update
--- @param is_on - boolean is timer on
+-- @function timer:set_state
+-- @tparam table self Component instance
+-- @tparam boolean is_on Timer enable state
function M.set_state(self, is_on)
self.is_on = is_on
end
--- Set time interval
--- @param from - "from" time in seconds
--- @param to - "to" time in seconds
+-- @function timer:set_interval
+-- @tparam table self Component instance
+-- @tparam number from Start time in seconds
+-- @tparam number to Target time in seconds
function M.set_interval(self, from, to)
self.from = from
self.value = from
@@ -59,8 +65,6 @@ function M.set_interval(self, from, to)
end
---- Called when update
--- @param dt - delta time
function M.update(self, dt)
if self.is_on then
self.temp = self.temp + dt
diff --git a/druid/const.lua b/druid/const.lua
index be3968b..e199b59 100644
--- a/druid/const.lua
+++ b/druid/const.lua
@@ -13,6 +13,7 @@ M.ACTION_BACK = hash("back")
M.RELEASED = "released"
M.PRESSED = "pressed"
M.STRING = "string"
+M.ZERO = "0"
--- Interests
M.ON_MESSAGE = hash("on_message")
@@ -34,7 +35,12 @@ M.PIVOTS = {
[gui.PIVOT_NW] = vmath.vector3(-0.5, -0.5, 0),
}
-M.ui_input = {
+M.SIDE = {
+ X = "x",
+ Y = "y"
+}
+
+M.UI_INPUT = {
[M.ON_SWIPE] = true,
[M.ON_INPUT] = true
}
diff --git a/druid/helper/formats.lua b/druid/helper/formats.lua
index 96aa487..9c38861 100644
--- a/druid/helper/formats.lua
+++ b/druid/helper/formats.lua
@@ -1,25 +1,27 @@
--- Druid module with utils on string formats
-- @module helper.formats
+local const = require("druid.const")
+
local M = {}
-local ZERO = "0"
-
--- Return number with zero number prefix
--- @param num number for conversion
--- @param count count of numerals
+-- @function formats.add_prefix_zeros
+-- @tparam number num Number for conversion
+-- @tparam number count Count of numerals
-- @return string with need count of zero (1,3) -> 001
function M.add_prefix_zeros(num, count)
local result = tostring(num)
for i = string.len(result), count - 1 do
- result = ZERO..result
+ result = const.ZERO..result
end
return result
end
--- Convert seconds to string minutes:seconds
--- @param num number of seconds
+-- @function formats.second_string_min
+-- @tparam number sec Seconds
-- @return string minutes:seconds
function M.second_string_min(sec)
local mins = math.floor(sec / 60)
@@ -29,8 +31,9 @@ end
--- Interpolate string with named Parameters in Table
--- @param s string for interpolate
--- @param tab table with parameters
+-- @function formats.second_string_min
+-- @tparam string s Target string
+-- @tparam table tab Table with parameters
-- @return string with replaced parameters
function M.interpolate_string(s, tab)
return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
diff --git a/druid/rich/progress_rich.lua b/druid/rich/progress_rich.lua
index 8785794..87c9b10 100644
--- a/druid/rich/progress_rich.lua
+++ b/druid/rich/progress_rich.lua
@@ -1,55 +1,71 @@
+--- Component for rich progress component
+-- @module rich.progress_rich
+
local settings = require("druid.settings")
local pr_settings = settings.progress_rich
local M = {}
-function M.init(instance, name, red, green, key)
- instance.red = instance.parent:new_progress(red, key)
- instance.green = instance.parent:new_progress(green, key)
- instance.fill = instance.parent:new_progress(name, key)
+
+function M.init(self, name, red, green, key)
+ self.red = self.parent:new_progress(red, key)
+ self.green = self.parent:new_progress(green, key)
+ self.fill = self.parent:new_progress(name, key)
end
-function M.set_to(instance, value)
- instance.red:set_to(value)
- instance.green:set_to(value)
- instance.fill:set_to(value)
+--- Instant fill progress bar to value
+-- @function progress_rich:set_to
+-- @tparam table self Component instance
+-- @tparam number value Progress bar value, from 0 to 1
+function M.set_to(self, value)
+ self.red:set_to(value)
+ self.green:set_to(value)
+ self.fill:set_to(value)
end
-function M.empty(instance)
- instance.red:empty()
- instance.green:empty()
- instance.fill:empty()
+--- Empty a progress bar
+-- @function progress_rich:empty
+-- @tparam table self Component instance
+function M.empty(self)
+ self.red:empty()
+ self.green:empty()
+ self.fill:empty()
end
-function M.to(instance, to, callback)
- if instance.timer then
- timer.cancel(instance.timer)
- instance.timer = nil
+--- Start animation of a progress bar
+-- @function progress_rich:to
+-- @tparam table self Component instance
+-- @tparam number to value between 0..1
+-- @tparam[opt] function callback Callback on animation ends
+function M.to(self, to, callback)
+ if self.timer then
+ timer.cancel(self.timer)
+ self.timer = nil
end
- if instance.fill.last_value < to then
- instance.red:to(instance.fill.last_value)
- instance.green:to(to, function()
- instance.timer = timer.delay(pr_settings.DELAY, false, function()
- instance.red:to(to)
- instance.fill:to(to, callback)
+ if self.fill.last_value < to then
+ self.red:to(self.fill.last_value)
+ self.green:to(to, function()
+ self.timer = timer.delay(pr_settings.DELAY, false, function()
+ self.red:to(to)
+ self.fill:to(to, callback)
end)
end)
end
- if instance.fill.last_value > to then
- instance.green:to(instance.red.last_value)
- instance.fill:to(to, function()
- instance.timer = timer.delay(pr_settings.DELAY, false, function()
- instance.green:to(to)
- instance.red:to(to, callback)
+ if self.fill.last_value > to then
+ self.green:to(self.red.last_value)
+ self.fill:to(to, function()
+ self.timer = timer.delay(pr_settings.DELAY, false, function()
+ self.green:to(to)
+ self.red:to(to, callback)
end)
end)
end
end
-return M
\ No newline at end of file
+return M
From da27d6edd8e9fa914ddd1be5d03ba48fd3e210a5 Mon Sep 17 00:00:00 2001
From: Insality
Date: Thu, 5 Dec 2019 22:05:17 +0300
Subject: [PATCH 4/4] Generate ldoc
---
docs/index.html | 103 +++++++-
docs/modules/back_handler.html | 155 +++++++++++
docs/modules/base.back_handler.html | 156 +++++++++++
docs/modules/base.blocker.html | 82 ++++++
docs/modules/base.button.html | 195 ++++++++++++++
docs/modules/base.checkbox.html | 82 ++++++
docs/modules/base.checkbox_group.html | 82 ++++++
docs/modules/base.grid.html | 82 ++++++
docs/modules/base.html | 155 +++++++++++
docs/modules/base.progress.html | 301 +++++++++++++++++++++
docs/modules/base.scroll.html | 278 +++++++++++++++++++
docs/modules/base.slider.html | 82 ++++++
docs/modules/base.text.html | 238 +++++++++++++++++
docs/modules/base.timer.html | 184 +++++++++++++
docs/modules/components.back_handler.html | 155 +++++++++++
docs/modules/constants.html | 111 ++++++++
docs/modules/druid.html | 309 ++++++++++++++++++++++
docs/modules/helper.animate.html | 82 ++++++
docs/modules/helper.formats.html | 191 +++++++++++++
docs/modules/helper.html | 153 +++++++++++
docs/modules/rich.progress_rich.html | 181 +++++++++++++
docs/modules/settings.html | 82 ++++++
22 files changed, 3438 insertions(+), 1 deletion(-)
create mode 100644 docs/modules/back_handler.html
create mode 100644 docs/modules/base.back_handler.html
create mode 100644 docs/modules/base.blocker.html
create mode 100644 docs/modules/base.button.html
create mode 100644 docs/modules/base.checkbox.html
create mode 100644 docs/modules/base.checkbox_group.html
create mode 100644 docs/modules/base.grid.html
create mode 100644 docs/modules/base.html
create mode 100644 docs/modules/base.progress.html
create mode 100644 docs/modules/base.scroll.html
create mode 100644 docs/modules/base.slider.html
create mode 100644 docs/modules/base.text.html
create mode 100644 docs/modules/base.timer.html
create mode 100644 docs/modules/components.back_handler.html
create mode 100644 docs/modules/constants.html
create mode 100644 docs/modules/druid.html
create mode 100644 docs/modules/helper.animate.html
create mode 100644 docs/modules/helper.formats.html
create mode 100644 docs/modules/helper.html
create mode 100644 docs/modules/rich.progress_rich.html
create mode 100644 docs/modules/settings.html
diff --git a/docs/index.html b/docs/index.html
index a695fc9..59a5bb7 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -29,6 +29,28 @@
+Modules
+
@@ -37,12 +59,91 @@
Documentation for Druid Library
+Modules
+
generated by LDoc 1.4.6
-
Last updated 2019-09-25 19:57:43
+
Last updated 2019-12-05 22:04:11
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Druid
+
+
+
+
Contents
+
+
+
+
Modules
+
+
+
+
+
+
+
Module back_handler
+
Component to handle back key
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+ init(self, callback[, Callback])
+
+ -
+ Component init function
+
+
+
Parameters:
+
+ - self
+ table
+ Component instance
+
+ - callback
+ callback
+ On back button
+
+ - Callback
+ params
+ argument
+ (optional)
+
+
+
+
+
+
+
+
+ -
+
+ on_input(action_id, action)
+
+ -
+ Input handler for component
+
+
+
Parameters:
+
+ - action_id
+ string
+ on_input action id
+
+ - action
+ table
+ on_input action
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
generated by LDoc 1.4.6
+
Last updated 2019-12-05 21:37:51
+
+
+
diff --git a/docs/modules/back_handler.html b/docs/modules/back_handler.html
new file mode 100644
index 0000000..0a7f657
--- /dev/null
+++ b/docs/modules/back_handler.html
@@ -0,0 +1,155 @@
+
+
+
+