From 05af3801d73934ae240a4d64c4a2b086367db286 Mon Sep 17 00:00:00 2001 From: Insality Date: Sun, 22 Mar 2020 00:37:28 +0300 Subject: [PATCH 1/2] Add set_steps to the slider component --- druid/base/slider.lua | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/druid/base/slider.lua b/druid/base/slider.lua index f5b8f13..e995e42 100644 --- a/druid/base/slider.lua +++ b/druid/base/slider.lua @@ -30,6 +30,12 @@ local function on_change_value(self) end +local function set_position(self, value) + value = helper.clamp(value, 0, 1) + gui.set_position(self.node, self.start_pos + self.dist * value) +end + + --- Component init function -- @function slider:init -- @tparam node node Gui pin node @@ -76,9 +82,8 @@ function M.on_input(self, action_id, action) self.target_pos.x = helper.clamp(self.pos.x, self.start_pos.x, self.end_pos.x) self.target_pos.y = helper.clamp(self.pos.y, self.start_pos.y, self.end_pos.y) - gui.set_position(self.node, self.target_pos) - if prev_x ~= self.target_pos.x or prev_y ~= self.target_pos.y then + local prev_value = self.value if self.dist.x > 0 then self.value = (self.target_pos.x - self.start_pos.x) / self.dist.x @@ -88,8 +93,27 @@ function M.on_input(self, action_id, action) self.value = (self.target_pos.y - self.start_pos.y) / self.dist.y end - on_change_value(self) + if self.steps then + local closest_dist = 1000 + local closest = nil + for i = 1, #self.steps do + local dist = math.abs(self.value - self.steps[i]) + if dist < closest_dist then + closest = self.steps[i] + closest_dist = dist + end + end + if closest then + self.value = closest + end + end + + if prev_value ~= self.value then + on_change_value(self) + end end + + set_position(self, self.value) end if action.released then @@ -106,8 +130,7 @@ end -- @tparam[opt] bool is_silent Don't trigger event if true function M.set(self, value, is_silent) value = helper.clamp(value, 0, 1) - - gui.set_position(self.node, self.start_pos + self.dist * value) + set_position(self, value) self.value = value if not is_silent then on_change_value(self) @@ -115,4 +138,14 @@ function M.set(self, value, is_silent) end +--- Set slider steps. Pin node will +-- apply closest step position +-- @function slider:set_steps +-- @tparam number[] steps Array of steps +-- @usage slider:set_steps({0, 0.2, 0.6, 1}) +function M.set_steps(self, steps) + self.steps = steps +end + + return M From 21d61a60e037414081b95db5a79fb14b9af38223 Mon Sep 17 00:00:00 2001 From: Insality Date: Sun, 22 Mar 2020 02:24:10 +0300 Subject: [PATCH 2/2] Update docs --- README.md | 2 +- docs/index.html | 2 +- docs/modules/component.html | 2 +- docs/modules/druid.back_handler.html | 2 +- docs/modules/druid.blocker.html | 2 +- docs/modules/druid.button.html | 2 +- docs/modules/druid.checkbox.html | 2 +- docs/modules/druid.checkbox_group.html | 2 +- docs/modules/druid.grid.html | 2 +- docs/modules/druid.helper.html | 2 +- docs/modules/druid.hover.html | 2 +- docs/modules/druid.html | 2 +- docs/modules/druid.input.html | 2 +- docs/modules/druid.lang_text.html | 2 +- docs/modules/druid.progress.html | 2 +- docs/modules/druid.radio_group.html | 2 +- docs/modules/druid.scroll.html | 2 +- docs/modules/druid.slider.html | 32 ++++++++++++++++++- docs/modules/druid.text.html | 2 +- docs/modules/druid.timer.html | 2 +- docs/modules/druid_event.html | 2 +- docs/modules/druid_instance.html | 2 +- docs/topics/01-components.md.html | 2 +- .../02-creating_custom_components.md.html | 2 +- docs/topics/03-styles.md.html | 2 +- docs/topics/04-druid_assets.md.html | 2 +- docs/topics/05-examples.md.html | 4 +-- docs/topics/README.md.html | 10 +++--- 28 files changed, 64 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 095ac5c..23f3ed8 100644 --- a/README.md +++ b/README.md @@ -145,4 +145,4 @@ MIT License ## Issues and suggestions -If you have any issues, questions or suggestions please [create an issue](https://github.com/Insality/druid/issues) or contact me: [insality@gmail.com](mailto:insality@gmail.com) +If you have any issues, questions or suggestions please [create an issue](https://github.com/Insality/druid/issues) or contact me: [insality@gmail.com](mailto:insality@gmail.com) diff --git a/docs/index.html b/docs/index.html index f7def12..0b8f119 100644 --- a/docs/index.html +++ b/docs/index.html @@ -185,7 +185,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/component.html b/docs/modules/component.html index e9f0b71..f3a81e9 100644 --- a/docs/modules/component.html +++ b/docs/modules/component.html @@ -406,7 +406,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.back_handler.html b/docs/modules/druid.back_handler.html index b487db4..eaa9c22 100644 --- a/docs/modules/druid.back_handler.html +++ b/docs/modules/druid.back_handler.html @@ -215,7 +215,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.blocker.html b/docs/modules/druid.blocker.html index c8bd528..d821b0d 100644 --- a/docs/modules/druid.blocker.html +++ b/docs/modules/druid.blocker.html @@ -234,7 +234,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.button.html b/docs/modules/druid.button.html index 6d560f4..33d7a61 100644 --- a/docs/modules/druid.button.html +++ b/docs/modules/druid.button.html @@ -405,7 +405,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.checkbox.html b/docs/modules/druid.checkbox.html index 8caabca..eb4d359 100644 --- a/docs/modules/druid.checkbox.html +++ b/docs/modules/druid.checkbox.html @@ -277,7 +277,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.checkbox_group.html b/docs/modules/druid.checkbox_group.html index da08531..f546f95 100644 --- a/docs/modules/druid.checkbox_group.html +++ b/docs/modules/druid.checkbox_group.html @@ -239,7 +239,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.grid.html b/docs/modules/druid.grid.html index a094522..026b001 100644 --- a/docs/modules/druid.grid.html +++ b/docs/modules/druid.grid.html @@ -370,7 +370,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.helper.html b/docs/modules/druid.helper.html index 3134d44..f89fcdb 100644 --- a/docs/modules/druid.helper.html +++ b/docs/modules/druid.helper.html @@ -236,7 +236,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.hover.html b/docs/modules/druid.hover.html index d69f516..7114a9a 100644 --- a/docs/modules/druid.hover.html +++ b/docs/modules/druid.hover.html @@ -211,7 +211,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.html b/docs/modules/druid.html index 9129bfd..e1661a0 100644 --- a/docs/modules/druid.html +++ b/docs/modules/druid.html @@ -181,7 +181,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.input.html b/docs/modules/druid.input.html index db50406..d44bd0b 100644 --- a/docs/modules/druid.input.html +++ b/docs/modules/druid.input.html @@ -86,7 +86,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.lang_text.html b/docs/modules/druid.lang_text.html index 590e5a0..19324ec 100644 --- a/docs/modules/druid.lang_text.html +++ b/docs/modules/druid.lang_text.html @@ -240,7 +240,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.progress.html b/docs/modules/druid.progress.html index afb9377..98444fd 100644 --- a/docs/modules/druid.progress.html +++ b/docs/modules/druid.progress.html @@ -378,7 +378,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.radio_group.html b/docs/modules/druid.radio_group.html index 266bc39..7daa804 100644 --- a/docs/modules/druid.radio_group.html +++ b/docs/modules/druid.radio_group.html @@ -239,7 +239,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.scroll.html b/docs/modules/druid.scroll.html index e77c055..83bf1f9 100644 --- a/docs/modules/druid.scroll.html +++ b/docs/modules/druid.scroll.html @@ -507,7 +507,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.slider.html b/docs/modules/druid.slider.html index 93d3935..e1ee7ff 100644 --- a/docs/modules/druid.slider.html +++ b/docs/modules/druid.slider.html @@ -91,6 +91,10 @@ set(value[, is_silent]) Set value for slider + + set_steps(steps) + Set slider steps. +

Tables

@@ -166,6 +170,32 @@ + +
+ + set_steps(steps) +
+
+ Set slider steps. Pin node will + apply closest step position + + +

Parameters:

+
    +
  • steps + number[] + Array of steps +
  • +
+ + + + +

Usage:

+
    +
    slider:set_steps({0, 0.2, 0.6, 1})
    +
+

Tables

@@ -248,7 +278,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.text.html b/docs/modules/druid.text.html index 7c5064a..78ac2f2 100644 --- a/docs/modules/druid.text.html +++ b/docs/modules/druid.text.html @@ -352,7 +352,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid.timer.html b/docs/modules/druid.timer.html index eb6a6bd..ce0ba1d 100644 --- a/docs/modules/druid.timer.html +++ b/docs/modules/druid.timer.html @@ -307,7 +307,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid_event.html b/docs/modules/druid_event.html index da1e7f0..2e568e6 100644 --- a/docs/modules/druid_event.html +++ b/docs/modules/druid_event.html @@ -239,7 +239,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/modules/druid_instance.html b/docs/modules/druid_instance.html index f727193..9f5def3 100644 --- a/docs/modules/druid_instance.html +++ b/docs/modules/druid_instance.html @@ -750,7 +750,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/topics/01-components.md.html b/docs/topics/01-components.md.html index abbd860..f0b9fbc 100644 --- a/docs/topics/01-components.md.html +++ b/docs/topics/01-components.md.html @@ -155,7 +155,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/topics/02-creating_custom_components.md.html b/docs/topics/02-creating_custom_components.md.html index 17e7286..ad82742 100644 --- a/docs/topics/02-creating_custom_components.md.html +++ b/docs/topics/02-creating_custom_components.md.html @@ -193,7 +193,7 @@ There is next interests in druid:
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/topics/03-styles.md.html b/docs/topics/03-styles.md.html index e8ad5fc..2cda9d2 100644 --- a/docs/topics/03-styles.md.html +++ b/docs/topics/03-styles.md.html @@ -138,7 +138,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/topics/04-druid_assets.md.html b/docs/topics/04-druid_assets.md.html index 7e13f65..d1b551b 100644 --- a/docs/topics/04-druid_assets.md.html +++ b/docs/topics/04-druid_assets.md.html @@ -89,7 +89,7 @@
generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/topics/05-examples.md.html b/docs/topics/05-examples.md.html index 96e1a7a..5c7839a 100644 --- a/docs/topics/05-examples.md.html +++ b/docs/topics/05-examples.md.html @@ -80,14 +80,14 @@

Overview

See the example folder for examples of how to use Druid

-

Try the HTML5 version of the example app

+

Try the HTML5 version of the example app

generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51
diff --git a/docs/topics/README.md.html b/docs/topics/README.md.html index 7682aa5..bb9eeb2 100644 --- a/docs/topics/README.md.html +++ b/docs/topics/README.md.html @@ -83,6 +83,8 @@

+

GitHub release (latest by date)

+

Druid - powerful defold component UI library. Use basic druid components or make your own game-specific components to make amazing GUI in your games.

@@ -181,7 +183,7 @@

See the druid-assets repository for examples of how to create custom components and styles

-

Try the HTML5 version of the example app

+

Try the HTML5 version of the example app

@@ -218,7 +220,7 @@ https://insality.github.io/druid/

License

-

Original idea by AGulev

+

Original created by AGulev

Developed and supporting by Insality

@@ -228,13 +230,13 @@ https://insality.github.io/druid/

Issues and suggestions

-

If you have any issues, questions or suggestions please create an issue or contact me: insality@gmail.com +

If you have any issues, questions or suggestions please create an issue or contact me: insality@gmail.com

generated by LDoc 1.4.6 -Last updated 2020-03-21 23:23:01 +Last updated 2020-03-22 02:23:51