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

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
base.back_handlerComponent to handle back key (android, backspace)
base.blockerComponent to block input on specify zone (node)
base.buttonComponent to handle basic GUI button
base.checkboxDruid checkbox component
base.checkbox_groupCheckboux group module
base.gridComponent to handle placing components by row and columns.
base.progressBasic progress bar component
base.checkbox_groupRadio group module
base.scrollComponent to handle scroll content
base.sliderDruid slider component
base.textComponent to handle all GUI texts Good working with localization system
base.timerComponent to handle GUI timers
constantsDruid constants
druidDruid UI Library.
helperDruid helper module
helper.animateDruid helper module for animating GUI nodes
helper.formatsDruid module with utils on string formats
rich.progress_richComponent for rich progress component
settingsDruid settings file
generated by LDoc 1.4.6 -Last updated 2019-09-25 19:57:43 +Last updated 2019-12-05 22:04:11
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 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module back_handler

+

Component to handle back key

+

+ + +

Functions

+ + + + + + + + + +
init(self, callback[, Callback])Component init function
on_input(action_id, action)Input handler for component
+ +
+
+ + +

Functions

+ +
+
+ + 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/base.back_handler.html b/docs/modules/base.back_handler.html new file mode 100644 index 0000000..5d11f6e --- /dev/null +++ b/docs/modules/base.back_handler.html @@ -0,0 +1,156 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.back_handler

+

Component to handle back key (android, backspace)

+

+ + +

Functions

+ + + + + + + + + +
init(self, callback[, Callback])Component init function
on_input(action_id, action)Input handler for component
+ +
+
+ + +

Functions

+ +
+
+ + 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 22:04:11 +
+
+ + diff --git a/docs/modules/base.blocker.html b/docs/modules/base.blocker.html new file mode 100644 index 0000000..9d0f4a5 --- /dev/null +++ b/docs/modules/base.blocker.html @@ -0,0 +1,82 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.blocker

+

Component to block input on specify zone (node)

+

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/base.button.html b/docs/modules/base.button.html new file mode 100644 index 0000000..f99cfcd --- /dev/null +++ b/docs/modules/base.button.html @@ -0,0 +1,195 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.button

+

Component to handle basic GUI button

+

+ + +

Functions

+ + + + + + + + + + + + + +
init(self, node, callback[, params[, anim_node[, event]]])Component init function
disable_animation(self)Disable all button animations
set_click_zone(self, zone)Strict button click area.
+ +
+
+ + +

Functions

+ +
+
+ + init(self, node, callback[, params[, anim_node[, event]]]) +
+
+ Component init function + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • node + node + Gui node +
  • +
  • callback + function + Button callback +
  • +
  • params + table + Button callback params + (optional) +
  • +
  • anim_node + node + Button anim node (node, if not provided) + (optional) +
  • +
  • event + string + Button react event, const.ACTION_TOUCH by default + (optional) +
  • +
+ + + + + +
+
+ + disable_animation(self) +
+
+ Disable all button animations + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
+ + + + + +
+
+ + set_click_zone(self, zone) +
+
+ Strict button click area. Useful for no click events outside stencil node + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • zone + node + Gui node +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/base.checkbox.html b/docs/modules/base.checkbox.html new file mode 100644 index 0000000..cc3dce8 --- /dev/null +++ b/docs/modules/base.checkbox.html @@ -0,0 +1,82 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.checkbox

+

Druid checkbox component

+

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/base.checkbox_group.html b/docs/modules/base.checkbox_group.html new file mode 100644 index 0000000..2c8f1d9 --- /dev/null +++ b/docs/modules/base.checkbox_group.html @@ -0,0 +1,82 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.checkbox_group

+

Radio group module

+

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/base.grid.html b/docs/modules/base.grid.html new file mode 100644 index 0000000..c8e0f78 --- /dev/null +++ b/docs/modules/base.grid.html @@ -0,0 +1,82 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.grid

+

Component to handle placing components by row and columns.

+

Grid can anchor your elements, get content size and other

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/base.html b/docs/modules/base.html new file mode 100644 index 0000000..6e44f09 --- /dev/null +++ b/docs/modules/base.html @@ -0,0 +1,155 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base

+

Component to handle back key

+

+ + +

Functions

+ + + + + + + + + +
back_handler:init(self, callback[, Callback])Component init function
back_handler:on_input(action_id, action)Input handler for component
+ +
+
+ + +

Functions

+ +
+
+ + back_handler:init(self, callback[, Callback]) +
+
+ Component init function + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • callback + callback + On back button +
  • +
  • Callback + params + argument + (optional) +
  • +
+ + + + + +
+
+ + back_handler: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:36:59 +
+
+ + diff --git a/docs/modules/base.progress.html b/docs/modules/base.progress.html new file mode 100644 index 0000000..ba8e905 --- /dev/null +++ b/docs/modules/base.progress.html @@ -0,0 +1,301 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.progress

+

Basic progress bar component

+

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
init(self, node, key, init_value)Component init function
empty(self)Fill a progress bar and stop progress animation
empty(self)Empty a progress bar
set_to(self, to)Instant fill progress bar to value
get(self)Return current progress bar value
set_steps(self, steps, callback)Set points on progress bar to fire the callback
to(self, to[, callback])Start animation of a progress bar
+ +
+
+ + +

Functions

+ +
+
+ + init(self, node, key, init_value) +
+
+ Component init function + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • node + string or node + Progress bar fill node or node name +
  • +
  • key + string + Progress bar direction (x or y) +
  • +
  • init_value + number + Initial value of progress bar +
  • +
+ + + + + +
+
+ + empty(self) +
+
+ Fill a progress bar and stop progress animation + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
+ + + + + +
+
+ + empty(self) +
+
+ Empty a progress bar + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
+ + + + + +
+
+ + set_to(self, to) +
+
+ Instant fill progress bar to value + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • to + number + Progress bar value, from 0 to 1 +
  • +
+ + + + + +
+
+ + get(self) +
+
+ Return current progress bar value + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
+ + + + + +
+
+ + set_steps(self, steps, callback) +
+
+ Set points on progress bar to fire the callback + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • steps + table + Array of progress bar values +
  • +
  • callback + function + Callback on intersect step value +
  • +
+ + + + + +
+
+ + to(self, to[, callback]) +
+
+ Start animation of a progress bar + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • to + number + value between 0..1 +
  • +
  • callback + function + Callback on animation ends + (optional) +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/base.scroll.html b/docs/modules/base.scroll.html new file mode 100644 index 0000000..dabe409 --- /dev/null +++ b/docs/modules/base.scroll.html @@ -0,0 +1,278 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.scroll

+

Component to handle scroll content

+

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + +
scroll_to(vector3[, is_instant])Start scroll to target point
init(self, index[, skip_cb])Scroll to item in scroll by point index
set_points(self, points)Set points of interest.
set_inert(self, state)Enable or disable scroll inert.
on_point_move(self, callback)Set the callback on scrolling to point (if exist)
set_border(self, border)Set the scroll possibly area
+ +
+
+ + +

Functions

+ +
+
+ + scroll_to(vector3[, is_instant]) +
+
+ Start scroll to target point + + +

Parameters:

+
    +
  • vector3 + point + target point +
  • +
  • is_instant + bool + instant scroll flag + (optional) +
  • +
+ + + + +

Usage:

+
    +
  • scroll:scroll_to(vmath.vector3(0, 50, 0))
  • +
  • scroll:scroll_to(vmath.vector3(0), true)
  • +
+ +
+
+ + init(self, index[, skip_cb]) +
+
+ Scroll to item in scroll by point index + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • index + number + Point index +
  • +
  • skip_cb + boolean + If true, skip the point callback + (optional) +
  • +
+ + + + + +
+
+ + set_points(self, points) +
+
+ Set points of interest. Scroll will always centered on closer points + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • points + table + Array of vector3 points +
  • +
+ + + + + +
+
+ + set_inert(self, state) +
+
+ Enable or disable scroll inert. If disabled, scroll through points (if exist) If no points, just simple drag without inertion + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • state + boolean + Inert scroll state +
  • +
+ + + + + +
+
+ + on_point_move(self, callback) +
+
+ Set the callback on scrolling to point (if exist) + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • callback + function + Callback on scroll to point of interest +
  • +
+ + + + + +
+
+ + set_border(self, border) +
+
+ Set the scroll possibly area + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • border + vmath.vector3 + Size of scrolling area +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/base.slider.html b/docs/modules/base.slider.html new file mode 100644 index 0000000..14f8f6e --- /dev/null +++ b/docs/modules/base.slider.html @@ -0,0 +1,82 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.slider

+

Druid slider component

+

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/base.text.html b/docs/modules/base.text.html new file mode 100644 index 0000000..26e0f16 --- /dev/null +++ b/docs/modules/base.text.html @@ -0,0 +1,238 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.text

+

Component to handle all GUI texts Good working with localization system

+

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + +
translate(self, locale_id)Translate the text by locale_id
set_to(self, set_to)Set text to text field
set_color(self, color)Set color
set_alpha(self, alpha)Set alpha
set_scale(self, scale)Set scale
+ +
+
+ + +

Functions

+ +
+
+ + translate(self, locale_id) +
+
+ Translate the text by locale_id + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • locale_id + string + Locale id +
  • +
+ + + + + +
+
+ + set_to(self, set_to) +
+
+ Set text to text field + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • set_to + string + Text for node +
  • +
+ + + + + +
+
+ + set_color(self, color) +
+
+ Set color + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • color + vmath.vector4 + Color for node +
  • +
+ + + + + +
+
+ + set_alpha(self, alpha) +
+
+ Set alpha + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • alpha + number + Alpha for node +
  • +
+ + + + + +
+
+ + set_scale(self, scale) +
+
+ Set scale + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • scale + vmath.vector3 + Scale for node +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/base.timer.html b/docs/modules/base.timer.html new file mode 100644 index 0000000..dc66bfb --- /dev/null +++ b/docs/modules/base.timer.html @@ -0,0 +1,184 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module base.timer

+

Component to handle GUI timers

+

+ + +

Functions

+ + + + + + + + + + + + + +
set_to(self, set_to)Set text to text field
set_state(self, is_on)Called when update
set_interval(self, from, to)Set time interval
+ +
+
+ + +

Functions

+ +
+
+ + set_to(self, set_to) +
+
+ Set text to text field + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • set_to + number + Value in seconds +
  • +
+ + + + + +
+
+ + set_state(self, is_on) +
+
+ Called when update + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • is_on + boolean + Timer enable state +
  • +
+ + + + + +
+
+ + set_interval(self, from, to) +
+
+ Set time interval + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • from + number + Start time in seconds +
  • +
  • to + number + Target time in seconds +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/components.back_handler.html b/docs/modules/components.back_handler.html new file mode 100644 index 0000000..6e25bbe --- /dev/null +++ b/docs/modules/components.back_handler.html @@ -0,0 +1,155 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module components.back_handler

+

Component to handle back key

+

+ + +

Functions

+ + + + + + + + + +
init(self, callback[, Callback])Component init function
on_input(action_id, action)Input handler for component
+ +
+
+ + +

Functions

+ +
+
+ + 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:38:00 +
+
+ + diff --git a/docs/modules/constants.html b/docs/modules/constants.html new file mode 100644 index 0000000..5cd9b0b --- /dev/null +++ b/docs/modules/constants.html @@ -0,0 +1,111 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module constants

+

Druid constants

+

+ + +

Fields

+ + + + + +
ON_MESSAGEInterests
+ +
+
+ + +

Fields

+ +
+
+ + ON_MESSAGE +
+
+ Interests + + + + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/druid.html b/docs/modules/druid.html new file mode 100644 index 0000000..f7b1a7a --- /dev/null +++ b/docs/modules/druid.html @@ -0,0 +1,309 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module druid

+

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.

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + +
register(name, module)Register external module
new(component_script)Create UI instance for ui elements
_fct_metatable.on_message(self, message_id, message, sender)Called on_message
_fct_metatable.on_input(self, action_id, action)Called ON_INPUT
_fct_metatable.update(self, dt)Called on_update
+

Tables

+ + + + + +
compsBasic components
+ +
+
+ + +

Functions

+ +
+
+ + register(name, module) +
+
+ Register external module + + +

Parameters:

+
    +
  • name + string + module name +
  • +
  • module + table + lua table with module +
  • +
+ + + + + +
+
+ + new(component_script) +
+
+ Create UI instance for ui elements + + +

Parameters:

+
    +
  • component_script + +
  • +
+ +

Returns:

+
    + + instance with all ui components +
+ + + + +
+
+ + _fct_metatable.on_message(self, message_id, message, sender) +
+
+ Called on_message + + +

Parameters:

+
    +
  • self + +
  • +
  • message_id + +
  • +
  • message + +
  • +
  • sender + +
  • +
+ + + + + +
+
+ + _fct_metatable.on_input(self, action_id, action) +
+
+ Called ON_INPUT + + +

Parameters:

+
    +
  • self + +
  • +
  • action_id + +
  • +
  • action + +
  • +
+ + + + + +
+
+ + _fct_metatable.update(self, dt) +
+
+ Called on_update + + +

Parameters:

+
    +
  • self + +
  • +
  • dt + +
  • +
+ + + + + +
+
+

Tables

+ +
+
+ + comps +
+
+ Basic components + + +

Fields:

+
    +
  • button + +
  • +
  • blocker + +
  • +
  • back_handler + +
  • +
  • text + +
  • +
  • timer + +
  • +
  • progress + +
  • +
  • grid + +
  • +
  • scroll + +
  • +
  • slider + +
  • +
  • checkbox + +
  • +
  • checkbox_group + +
  • +
  • radio_group + +
  • +
  • progress_rich + +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/helper.animate.html b/docs/modules/helper.animate.html new file mode 100644 index 0000000..63f59ee --- /dev/null +++ b/docs/modules/helper.animate.html @@ -0,0 +1,82 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module helper.animate

+

Druid helper module for animating GUI nodes

+

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/helper.formats.html b/docs/modules/helper.formats.html new file mode 100644 index 0000000..6cf1ce1 --- /dev/null +++ b/docs/modules/helper.formats.html @@ -0,0 +1,191 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module helper.formats

+

Druid module with utils on string formats

+

+ + +

Functions

+ + + + + + + + + + + + + +
add_prefix_zeros(num, count)Return number with zero number prefix
second_string_min(sec)Convert seconds to string minutes:seconds
second_string_min(s, tab)Interpolate string with named Parameters in Table
+ +
+
+ + +

Functions

+ +
+
+ + add_prefix_zeros(num, count) +
+
+ Return number with zero number prefix + + +

Parameters:

+
    +
  • num + number + Number for conversion +
  • +
  • count + number + Count of numerals +
  • +
+ +

Returns:

+
    + + string with need count of zero (1,3) -> 001 +
+ + + + +
+
+ + second_string_min(sec) +
+
+ Convert seconds to string minutes:seconds + + +

Parameters:

+
    +
  • sec + number + Seconds +
  • +
+ +

Returns:

+
    + + string minutes:seconds +
+ + + + +
+
+ + second_string_min(s, tab) +
+
+ Interpolate string with named Parameters in Table + + +

Parameters:

+
    +
  • s + string + Target string +
  • +
  • tab + table + Table with parameters +
  • +
+ +

Returns:

+
    + + string with replaced parameters +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/helper.html b/docs/modules/helper.html new file mode 100644 index 0000000..e7ecf16 --- /dev/null +++ b/docs/modules/helper.html @@ -0,0 +1,153 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module helper

+

Druid helper module

+

+ + +

Functions

+ + + + + + + + + +
centrate_text_with_icon(text_node, icon_node, margin)Text node or icon node can be nil
centrate_icon_with_text(icon_node, text_node, margin)Icon node or text node can be nil
+ +
+
+ + +

Functions

+ +
+
+ + centrate_text_with_icon(text_node, icon_node, margin) +
+
+ Text node or icon node can be nil + + +

Parameters:

+
    +
  • text_node + +
  • +
  • icon_node + +
  • +
  • margin + +
  • +
+ + + + + +
+
+ + centrate_icon_with_text(icon_node, text_node, margin) +
+
+ Icon node or text node can be nil + + +

Parameters:

+
    +
  • icon_node + +
  • +
  • text_node + +
  • +
  • margin + +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/rich.progress_rich.html b/docs/modules/rich.progress_rich.html new file mode 100644 index 0000000..0ce5b2e --- /dev/null +++ b/docs/modules/rich.progress_rich.html @@ -0,0 +1,181 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module rich.progress_rich

+

Component for rich progress component

+

+ + +

Functions

+ + + + + + + + + + + + + +
set_to(self, value)Instant fill progress bar to value
empty(self)Empty a progress bar
to(self, to[, callback])Start animation of a progress bar
+ +
+
+ + +

Functions

+ +
+
+ + set_to(self, value) +
+
+ Instant fill progress bar to value + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • value + number + Progress bar value, from 0 to 1 +
  • +
+ + + + + +
+
+ + empty(self) +
+
+ Empty a progress bar + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
+ + + + + +
+
+ + to(self, to[, callback]) +
+
+ Start animation of a progress bar + + +

Parameters:

+
    +
  • self + table + Component instance +
  • +
  • to + number + value between 0..1 +
  • +
  • callback + function + Callback on animation ends + (optional) +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + diff --git a/docs/modules/settings.html b/docs/modules/settings.html new file mode 100644 index 0000000..205e608 --- /dev/null +++ b/docs/modules/settings.html @@ -0,0 +1,82 @@ + + + + + Defold Druid UI Library + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module settings

+

Druid settings file

+

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.4.6 +Last updated 2019-12-05 22:04:11 +
+
+ + 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/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..dd80aec 100644 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -22,10 +22,18 @@ 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.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 @@ -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,10 +212,13 @@ 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.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..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.get_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 622b18d..2fbd8bc 100644 --- a/druid/base/scroll.lua +++ b/druid/base/scroll.lua @@ -7,21 +7,19 @@ 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 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 @@ -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/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..f04bbf7 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) @@ -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 2ab6cb7..af22d1f 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 @@ -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 eb870dd..e199b59 100644 --- a/druid/const.lua +++ b/druid/const.lua @@ -12,6 +12,8 @@ M.ACTION_BACK = hash("back") M.RELEASED = "released" M.PRESSED = "pressed" +M.STRING = "string" +M.ZERO = "0" --- Interests M.ON_MESSAGE = hash("on_message") @@ -21,7 +23,24 @@ M.ON_UPDATE = hash("on_update") M.ON_SWIPE = hash("on_swipe") M.ON_INPUT = hash("on_input") -M.ui_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.SIDE = { + X = "x", + Y = "y" +} + +M.UI_INPUT = { [M.ON_SWIPE] = true, [M.ON_INPUT] = true } @@ -30,7 +49,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 1ef342f..c7c7a36 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 @@ -79,9 +81,8 @@ function M.after(count, callback) 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 @@ -142,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 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