From 3339b000712bdf5bbe931b7e93937761a92b972f Mon Sep 17 00:00:00 2001 From: Insality Date: Fri, 17 Apr 2020 20:04:45 +0300 Subject: [PATCH 1/4] Add simple swipe component --- druid/base/hover.lua | 2 +- druid/base/swipe.lua | 129 +++++++++++++++++++++++++++++++ druid/const.lua | 9 ++- druid/styles/default/style.lua | 7 ++ druid/system/druid_instance.lua | 11 +++ example/gui/main/main.gui | 6 +- example/gui/main/main.gui_script | 13 ++++ example/page/main.lua | 1 - 8 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 druid/base/swipe.lua diff --git a/druid/base/hover.lua b/druid/base/hover.lua index 0fb916a..2a831a7 100644 --- a/druid/base/hover.lua +++ b/druid/base/hover.lua @@ -70,7 +70,7 @@ function M.set_hover(self, state) end ---- Strict button click area. Useful for +--- Strict hover click area. Useful for -- no click events outside stencil node -- @function hover:set_click_zone -- @tparam node zone Gui node diff --git a/druid/base/swipe.lua b/druid/base/swipe.lua new file mode 100644 index 0000000..e9fbf31 --- /dev/null +++ b/druid/base/swipe.lua @@ -0,0 +1,129 @@ +--- Component to handle swipe gestures on node. +-- Swipe will be triggered, if swipe was started and +-- ended on one node +-- @module druid.swipe + +--- Component events +-- @table Events +-- @tfield druid_event on_swipe Trigger on swipe event + +--- Component style params +-- @table Style +-- @tfield number SWIPE_TIME Maximum time for swipe trigger +-- @tfield number SWIPE_THRESHOLD Minimum distance for swipe trigger +-- @tfield bool SWIPE_TRIGGER_ON_MOVE If true, trigger on swipe moving, not only release action + +local Event = require("druid.event") +local const = require("druid.const") +local helper = require("druid.helper") +local component = require("druid.component") + +local M = component.create("swipe", { const.ON_INPUT }) + + +local function start_swipe(self, action) + self._swipe_start_time = socket.gettime() + self.start_pos.x = action.x + self.start_pos.y = action.y +end + + +local function reset_swipe(self, action) + self._swipe_start_time = false +end + + +local function check_swipe(self, action) + local dx = action.x - self.start_pos.x + local dy = action.y - self.start_pos.y + local dist = helper.distance(self.start_pos.x, self.start_pos.y, action.x, action.y) + local delta_time = socket.gettime() - self._swipe_start_time + local is_swipe = self.style.SWIPE_THRESHOLD <= dist and delta_time <= self.style.SWIPE_TIME + + if is_swipe then + local is_x_swipe = math.abs(dx) >= math.abs(dy) + local swipe_side = false + if is_x_swipe and dx > 0 then + swipe_side = const.SWIPE.RIGHT + end + if is_x_swipe and dx < 0 then + swipe_side = const.SWIPE.LEFT + end + if not is_x_swipe and dy > 0 then + swipe_side = const.SWIPE.UP + end + if not is_x_swipe and dy < 0 then + swipe_side = const.SWIPE.DOWN + end + + self.on_swipe:trigger(self:get_context(), swipe_side, dist, delta_time) + reset_swipe(self) + end +end + + +--- Component init function +-- @function swipe:init +-- @tparam node node Gui node +-- @tparam function on_swipe_callback Swipe callback for on_swipe_end event +function M.init(self, node, on_swipe_callback) + self.style = self:get_style() + self._trigger_on_move = self.style.SWIPE_TRIGGER_ON_MOVE + self.node = self:get_node(node) + + self._swipe_start_time = false + self.start_pos = vmath.vector3(0) + + self.click_zone = nil + self.on_swipe = Event(on_swipe_callback) +end + + +function M.on_input(self, action_id, action) + if action_id ~= const.ACTION_TOUCH then + return + end + + if not helper.is_enabled(self.node) then + return false + end + + local is_pick = gui.pick_node(self.node, action.x, action.y) + if self.click_zone then + is_pick = is_pick and gui.pick_node(self.click_zone, action.x, action.y) + end + + if not is_pick then + reset_swipe(self, action) + return false + end + + if self._swipe_start_time and (self._trigger_on_move or action.released) then + check_swipe(self, action) + end + + if action.pressed then + start_swipe(self, action) + end + + if action.released then + reset_swipe(self, action) + end +end + + +function M.on_input_interrupt(self) + reset_swipe(self) +end + + +--- Strict swipe click area. Useful for +-- restrict events outside stencil node +-- @function swipe:set_click_zone +-- @tparam node zone Gui node +function M.set_click_zone(self, zone) + self.click_zone = self:get_node(zone) +end + + +return M diff --git a/druid/const.lua b/druid/const.lua index fd2c121..7d1dcf0 100644 --- a/druid/const.lua +++ b/druid/const.lua @@ -58,10 +58,17 @@ M.SIDE = { Y = "y" } +M.SWIPE = { + UP = "up", + DOWN = "down", + LEFT = "left", + RIGHT = "right", +} + M.EMPTY_FUNCTION = function() end M.EMPTY_STRING = "" M.EMPTY_TABLE = {} -return M \ No newline at end of file +return M diff --git a/druid/styles/default/style.lua b/druid/styles/default/style.lua index eaddd9d..12164e3 100644 --- a/druid/styles/default/style.lua +++ b/druid/styles/default/style.lua @@ -75,4 +75,11 @@ M["checkbox"] = { } +M["swipe"] = { + SWIPE_THRESHOLD = 50, + SWIPE_TIME = 0.4, + SWIPE_TRIGGER_ON_MOVE = true +} + + return M diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 9739803..f071608 100644 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -15,6 +15,7 @@ -- @see druid.checkbox -- @see druid.checkbox_group -- @see druid.radio_group +-- @see druid.swipe local const = require("druid.const") local druid_input = require("druid.helper.druid_input") @@ -36,6 +37,7 @@ local checkbox = require("druid.base.checkbox") local checkbox_group = require("druid.base.checkbox_group") local radio_group = require("druid.base.radio_group") local input = require("druid.base.input") +local swipe = require("druid.base.swipe") -- local infinity_scroll = require("druid.base.infinity_scroll") -- @classmod Druid @@ -364,4 +366,13 @@ function Druid.new_radio_group(self, ...) end +--- Create swipe basic component +-- @function druid:new_swipe +-- @tparam args ... swipe init args +-- @treturn Component swipe component +function Druid.new_swipe(self, ...) + return Druid.create(self, swipe, ...) +end + + return Druid diff --git a/example/gui/main/main.gui b/example/gui/main/main.gui index 91ec206..5f58f85 100644 --- a/example/gui/main/main.gui +++ b/example/gui/main/main.gui @@ -33,8 +33,8 @@ nodes { w: 1.0 } size { - x: 1.0 - y: 1.0 + x: 600.0 + y: 900.0 z: 0.0 w: 1.0 } @@ -65,7 +65,7 @@ nodes { clipping_inverted: false alpha: 1.0 template_node_child: false - size_mode: SIZE_MODE_AUTO + size_mode: SIZE_MODE_MANUAL } nodes { position { diff --git a/example/gui/main/main.gui_script b/example/gui/main/main.gui_script index e9a0106..c08c365 100644 --- a/example/gui/main/main.gui_script +++ b/example/gui/main/main.gui_script @@ -39,11 +39,24 @@ local function init_top_panel(self) end +local function init_swipe_control(self) + self.druid:new_swipe("root", function(_, side) + if side == "left" then + on_control_button(self, 1) + end + if side == "right" then + on_control_button(self, -1) + end + end) +end + + function init(self) druid.set_default_style(default_style) self.druid = druid.new(self) init_top_panel(self) + init_swipe_control(self) self.page = 1 main_page.setup_page(self) text_page.setup_page(self) diff --git a/example/page/main.lua b/example/page/main.lua index 3252792..2da7d7f 100644 --- a/example/page/main.lua +++ b/example/page/main.lua @@ -106,7 +106,6 @@ local function setup_back_handler(self) end - function M.setup_page(self) setup_texts(self) From fbfd18547a52ac0127dc5d14384d39b75660d25c Mon Sep 17 00:00:00 2001 From: Insality Date: Fri, 17 Apr 2020 20:13:49 +0300 Subject: [PATCH 2/4] Update swipe docs --- README.md | 2 ++ docs_md/01-components.md | 27 ++++++++++++++++++++++++--- druid/styles/empty/style.lua | 7 +++++++ druid/styles/sprites/style.lua | 7 +++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 90dc26e..8fc8c8b 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,8 @@ druid.set_default_style(your_style) - **[Hover](https://github.com/Insality/druid/blob/master/docs_md/01-components.md#hover)** - System Druid component, handle hover node state +- **[Swipe](https://github.com/Insality/druid/blob/master/docs_md/01-components.md#swipe)** - System Druid component, handle swipe gestures on node + Full info see on _[components.md](https://github.com/Insality/druid/blob/master/docs_md/01-components.md)_ diff --git a/docs_md/01-components.md b/docs_md/01-components.md index 25aafcb..e4c79b5 100644 --- a/docs_md/01-components.md +++ b/docs_md/01-components.md @@ -243,9 +243,30 @@ Create grid component with druid: `grid = druid:new_grid(parent_node, prefab_nod [Hover API here](https://insality.github.io/druid/modules/druid.hover.html) ### Overview -System Druid component, handle hover node state +System Druid component, handle hover node state. ### Setup -Create grid component with druid: `hover = druid:new_hover(node, callback)` +Create hover component with druid: `hover = druid:new_hover(node, callback)` -### Notes \ No newline at end of file +### Notes + + +## Swipe +[Swipe API here](https://insality.github.io/druid/modules/druid.swipe.html) + +### Overview +System Druid component, handle swipe actions on node + +### Setup +Create hover component with druid: `hover = druid:new_swipe(node, swipe_callback)` + +### Notes +- Swipe callback have next params: (self, swipe_side, distance, time) + - **self** - Druid self context + - **swipe_side**: *string* - values from ["up", "down", "left", "right"] + - **distance**: *number* - in pixels, distance of swipe + - **time**: *number* - in seconds, time of swiping +- Swipe trigger only, if all input actions was on swipe node. If action will be outside of node, swipe status will be reseted +- In swipe style table you can adjust minimal distance and maximum time to trigger swipe +- In swipe style table you can toggle type of swipe triggering. if SWIPE_TRIGGER_ON_MOVE setup to true - swipe will trigger as swipe can be triggered. If setup to false - swipe will trigger only on released action +- If you have stencil on swipe node and you don't want trigger it outside of stencil node, you can use `swipe:set_click_zone` to restrict swipe zone \ No newline at end of file diff --git a/druid/styles/empty/style.lua b/druid/styles/empty/style.lua index 27a9a43..3ede1b5 100644 --- a/druid/styles/empty/style.lua +++ b/druid/styles/empty/style.lua @@ -42,4 +42,11 @@ M["checkbox"] = { } +M["swipe"] = { + SWIPE_THRESHOLD = 50, + SWIPE_TIME = 0.4, + SWIPE_TRIGGER_ON_MOVE = false +} + + return M diff --git a/druid/styles/sprites/style.lua b/druid/styles/sprites/style.lua index b99409d..7d0d8be 100644 --- a/druid/styles/sprites/style.lua +++ b/druid/styles/sprites/style.lua @@ -49,4 +49,11 @@ M["checkbox"] = { } +M["swipe"] = { + SWIPE_THRESHOLD = 50, + SWIPE_TIME = 0.4, + SWIPE_TRIGGER_ON_MOVE = false +} + + return M From 48aa2b3d716e7ab8108e54ed92b8f22903c4af2d Mon Sep 17 00:00:00 2001 From: Insality Date: Fri, 17 Apr 2020 20:14:06 +0300 Subject: [PATCH 3/4] Update ldoc --- docs/index.html | 7 +- docs/modules/component.html | 3 +- docs/modules/druid.back_handler.html | 3 +- docs/modules/druid.blocker.html | 3 +- docs/modules/druid.button.html | 3 +- docs/modules/druid.checkbox.html | 3 +- docs/modules/druid.checkbox_group.html | 3 +- docs/modules/druid.grid.html | 3 +- docs/modules/druid.helper.html | 3 +- docs/modules/druid.hover.html | 7 +- docs/modules/druid.html | 3 +- docs/modules/druid.input.html | 3 +- docs/modules/druid.lang_text.html | 3 +- docs/modules/druid.progress.html | 3 +- docs/modules/druid.radio_group.html | 3 +- docs/modules/druid.scroll.html | 3 +- docs/modules/druid.slider.html | 3 +- docs/modules/druid.swipe.html | 226 ++++++++++++++++++ docs/modules/druid.text.html | 3 +- docs/modules/druid.timer.html | 3 +- docs/modules/druid_event.html | 3 +- docs/modules/druid_instance.html | 35 ++- docs/topics/01-components.md.html | 34 ++- .../02-creating_custom_components.md.html | 3 +- docs/topics/03-styles.md.html | 3 +- docs/topics/04-druid_assets.md.html | 3 +- docs/topics/05-examples.md.html | 3 +- docs/topics/README.md.html | 4 +- 28 files changed, 348 insertions(+), 31 deletions(-) create mode 100644 docs/modules/druid.swipe.html diff --git a/docs/index.html b/docs/index.html index 87c1f53..639dc54 100644 --- a/docs/index.html +++ b/docs/index.html @@ -44,6 +44,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -124,6 +125,10 @@ druid.slider Druid slider component + + druid.swipe + Component to handle swipe gestures on node. + druid.text Component to handle all GUI texts. @@ -185,7 +190,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/component.html b/docs/modules/component.html index 4e3c79a..1748f3a 100644 --- a/docs/modules/component.html +++ b/docs/modules/component.html @@ -51,6 +51,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -440,7 +441,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.back_handler.html b/docs/modules/druid.back_handler.html index 31faacf..dae7f4a 100644 --- a/docs/modules/druid.back_handler.html +++ b/docs/modules/druid.back_handler.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -215,7 +216,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.blocker.html b/docs/modules/druid.blocker.html index 792519a..4f6e257 100644 --- a/docs/modules/druid.blocker.html +++ b/docs/modules/druid.blocker.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -234,7 +235,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.button.html b/docs/modules/druid.button.html index 956c98c..9865e31 100644 --- a/docs/modules/druid.button.html +++ b/docs/modules/druid.button.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -404,7 +405,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.checkbox.html b/docs/modules/druid.checkbox.html index 013ee8a..7081605 100644 --- a/docs/modules/druid.checkbox.html +++ b/docs/modules/druid.checkbox.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -277,7 +278,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.checkbox_group.html b/docs/modules/druid.checkbox_group.html index bf11124..df09ed2 100644 --- a/docs/modules/druid.checkbox_group.html +++ b/docs/modules/druid.checkbox_group.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -239,7 +240,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.grid.html b/docs/modules/druid.grid.html index 9bec5e2..f6c4c58 100644 --- a/docs/modules/druid.grid.html +++ b/docs/modules/druid.grid.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -370,7 +371,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.helper.html b/docs/modules/druid.helper.html index 9ddb960..f4c3af0 100644 --- a/docs/modules/druid.helper.html +++ b/docs/modules/druid.helper.html @@ -51,6 +51,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -236,7 +237,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.hover.html b/docs/modules/druid.hover.html index f2b29ac..3135adf 100644 --- a/docs/modules/druid.hover.html +++ b/docs/modules/druid.hover.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -93,7 +94,7 @@ set_click_zone(zone) - Strict button click area. + Strict hover click area.

    Tables

    @@ -162,7 +163,7 @@ set_click_zone(zone)
    - Strict button click area. Useful for + Strict hover click area. Useful for no click events outside stencil node @@ -211,7 +212,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.html b/docs/modules/druid.html index 3bb74e7..076a530 100644 --- a/docs/modules/druid.html +++ b/docs/modules/druid.html @@ -51,6 +51,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -181,7 +182,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.input.html b/docs/modules/druid.input.html index 0334fd1..e603bae 100644 --- a/docs/modules/druid.input.html +++ b/docs/modules/druid.input.html @@ -47,6 +47,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -86,7 +87,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.lang_text.html b/docs/modules/druid.lang_text.html index ba2169c..31b46a3 100644 --- a/docs/modules/druid.lang_text.html +++ b/docs/modules/druid.lang_text.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -240,7 +241,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.progress.html b/docs/modules/druid.progress.html index 841692c..f6d2790 100644 --- a/docs/modules/druid.progress.html +++ b/docs/modules/druid.progress.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -379,7 +380,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.radio_group.html b/docs/modules/druid.radio_group.html index 6fb9890..91cb3f1 100644 --- a/docs/modules/druid.radio_group.html +++ b/docs/modules/druid.radio_group.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -239,7 +240,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.scroll.html b/docs/modules/druid.scroll.html index 0b34dc6..c35e602 100644 --- a/docs/modules/druid.scroll.html +++ b/docs/modules/druid.scroll.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -507,7 +508,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.slider.html b/docs/modules/druid.slider.html index 077bdb9..9ffc418 100644 --- a/docs/modules/druid.slider.html +++ b/docs/modules/druid.slider.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -278,7 +279,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.swipe.html b/docs/modules/druid.swipe.html new file mode 100644 index 0000000..212bbc9 --- /dev/null +++ b/docs/modules/druid.swipe.html @@ -0,0 +1,226 @@ + + + + + Defold Druid UI Library + + + + +
    + +
    + +
    +
    +
    + + +
    + + + + + + +
    + +

    Module druid.swipe

    +

    Component to handle swipe gestures on node.

    +

    Swipe will be triggered, if swipe was started and + ended on one node

    + + +

    Functions

    + + + + + + + + + +
    init(node, on_swipe_callback)Component init function
    set_click_zone(zone)Strict swipe click area.
    +

    Tables

    + + + + + + + + + +
    EventsComponent events
    StyleComponent style params
    + +
    +
    + + +

    Functions

    + +
    +
    + + init(node, on_swipe_callback) +
    +
    + Component init function + + +

    Parameters:

    +
      +
    • node + node + Gui node +
    • +
    • on_swipe_callback + function + Swipe callback for onswipeend event +
    • +
    + + + + + +
    +
    + + set_click_zone(zone) +
    +
    + Strict swipe click area. Useful for + restrict events outside stencil node + + +

    Parameters:

    +
      +
    • zone + node + Gui node +
    • +
    + + + + + +
    +
    +

    Tables

    + +
    +
    + + Events +
    +
    + Component events + + +

    Fields:

    +
      +
    • on_swipe + druid_event + Trigger on swipe event +
    • +
    + + + + + +
    +
    + + Style +
    +
    + Component style params + + +

    Fields:

    +
      +
    • SWIPE_TIME + number + Maximum time for swipe trigger +
    • +
    • SWIPE_THRESHOLD + number + Minimum distance for swipe trigger +
    • +
    • SWIPE_TRIGGER_ON_MOVE + bool + If true, trigger on swipe moving, not only release action +
    • +
    + + + + + +
    +
    + + +
    +
    +
    +generated by LDoc 1.4.6 +Last updated 2020-04-17 20:13:54 +
    +
    + + diff --git a/docs/modules/druid.text.html b/docs/modules/druid.text.html index 32ed971..74b2de3 100644 --- a/docs/modules/druid.text.html +++ b/docs/modules/druid.text.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -352,7 +353,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid.timer.html b/docs/modules/druid.timer.html index 1c73f4b..97fd71e 100644 --- a/docs/modules/druid.timer.html +++ b/docs/modules/druid.timer.html @@ -52,6 +52,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -293,7 +294,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid_event.html b/docs/modules/druid_event.html index 25f3c52..81ef363 100644 --- a/docs/modules/druid_event.html +++ b/docs/modules/druid_event.html @@ -51,6 +51,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -239,7 +240,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/modules/druid_instance.html b/docs/modules/druid_instance.html index d08a246..5a9f0fb 100644 --- a/docs/modules/druid_instance.html +++ b/docs/modules/druid_instance.html @@ -51,6 +51,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -93,6 +94,7 @@
  • druid.checkbox
  • druid.checkbox_group
  • druid.radio_group
  • +
  • druid.swipe
  • @@ -186,6 +188,10 @@ druid:new_radio_group(...) Create radio_group basic component + + druid:new_swipe(...) + Create swipe basic component +
    @@ -761,6 +767,33 @@ +
    +
    + + druid:new_swipe(...) +
    +
    + Create swipe basic component + + +

    Parameters:

    +
      +
    • ... + args + swipe init args +
    • +
    + +

    Returns:

    +
      + + Component + swipe component +
    + + + +
    @@ -769,7 +802,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/topics/01-components.md.html b/docs/topics/01-components.md.html index 3fdaf17..ac1bf54 100644 --- a/docs/topics/01-components.md.html +++ b/docs/topics/01-components.md.html @@ -47,6 +47,7 @@
  • Timer
  • Grid
  • Hover
  • +
  • Swipe
  • @@ -74,6 +75,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -362,19 +364,45 @@ Key is value from druid const: const.SIDE.X (or just "x") or const.SIDE.Y (or ju

    Hover API here

    Overview

    -

    System Druid component, handle hover node state

    +

    System Druid component, handle hover node state.

    Setup

    -

    Create grid component with druid: hover = druid:new_hover(node, callback)

    +

    Create hover component with druid: hover = druid:new_hover(node, callback)

    Notes

    +

    +

    Swipe

    +

    Swipe API here

    + +

    Overview

    +

    System Druid component, handle swipe actions on node

    + +

    Setup

    +

    Create hover component with druid: hover = druid:new_swipe(node, swipe_callback)

    + +

    Notes

    +

    - Swipe callback have next params: (self, swipe_side, distance, time)

    + +
    +- **self** - Druid self context
    +- **swipe_side**: *string* - values from ["up", "down", "left", "right"]
    +- **distance**: *number* - in pixels, distance of swipe
    +- **time**: *number* - in seconds, time of swiping
    +
    + +

    - Swipe trigger only, if all input actions was on swipe node. If action will be outside of node, swipe status will be reseted +- In swipe style table you can adjust minimal distance and maximum time to trigger swipe +- In swipe style table you can toggle type of swipe triggering. if SWIPETRIGGERON_MOVE setup to true - swipe will trigger as swipe can be triggered. If setup to false - swipe will trigger only on released action +- If you have stencil on swipe node and you don't want trigger it outside of stencil node, you can use swipe:set_click_zone to restrict swipe zone

    + +
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/topics/02-creating_custom_components.md.html b/docs/topics/02-creating_custom_components.md.html index 6880c7f..478ff31 100644 --- a/docs/topics/02-creating_custom_components.md.html +++ b/docs/topics/02-creating_custom_components.md.html @@ -63,6 +63,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -233,7 +234,7 @@ There is next interests in druid:
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/topics/03-styles.md.html b/docs/topics/03-styles.md.html index d632be3..b3e69bd 100644 --- a/docs/topics/03-styles.md.html +++ b/docs/topics/03-styles.md.html @@ -62,6 +62,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -138,7 +139,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/topics/04-druid_assets.md.html b/docs/topics/04-druid_assets.md.html index 3d87441..f1c4cd7 100644 --- a/docs/topics/04-druid_assets.md.html +++ b/docs/topics/04-druid_assets.md.html @@ -60,6 +60,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -89,7 +90,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/topics/05-examples.md.html b/docs/topics/05-examples.md.html index 5531e13..12b20c5 100644 --- a/docs/topics/05-examples.md.html +++ b/docs/topics/05-examples.md.html @@ -60,6 +60,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -87,7 +88,7 @@
    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    diff --git a/docs/topics/README.md.html b/docs/topics/README.md.html index 197a296..d993a24 100644 --- a/docs/topics/README.md.html +++ b/docs/topics/README.md.html @@ -70,6 +70,7 @@
  • druid.radio_group
  • druid.scroll
  • druid.slider
  • +
  • druid.swipe
  • druid.text
  • druid.timer
  • component
  • @@ -168,6 +169,7 @@
  • Timer - Handle timer work on gui text node

  • Grid - Component for manage node positions

  • Hover - System Druid component, handle hover node state

  • +
  • Swipe - System Druid component, handle swipe gestures on node

  • Full info see on components.md

    @@ -314,7 +316,7 @@ https://insality.github.io/druid/

    generated by LDoc 1.4.6 -Last updated 2020-04-13 19:36:00 +Last updated 2020-04-17 20:13:54
    From 8f2faa715638fe5dda79869f63b4e858de2c1fda Mon Sep 17 00:00:00 2001 From: Insality Date: Fri, 17 Apr 2020 20:17:33 +0300 Subject: [PATCH 4/4] Correct swipe fields --- druid/base/swipe.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/druid/base/swipe.lua b/druid/base/swipe.lua index e9fbf31..f725c28 100644 --- a/druid/base/swipe.lua +++ b/druid/base/swipe.lua @@ -3,6 +3,11 @@ -- ended on one node -- @module druid.swipe +--- Components fields +-- @table Fields +-- @tparam node node Swipe node +-- @tparam[opt] node click_zone Restriction zone + --- Component events -- @table Events -- @tfield druid_event on_swipe Trigger on swipe event @@ -23,8 +28,8 @@ local M = component.create("swipe", { const.ON_INPUT }) local function start_swipe(self, action) self._swipe_start_time = socket.gettime() - self.start_pos.x = action.x - self.start_pos.y = action.y + self._start_pos.x = action.x + self._start_pos.y = action.y end @@ -34,9 +39,9 @@ end local function check_swipe(self, action) - local dx = action.x - self.start_pos.x - local dy = action.y - self.start_pos.y - local dist = helper.distance(self.start_pos.x, self.start_pos.y, action.x, action.y) + local dx = action.x - self._start_pos.x + local dy = action.y - self._start_pos.y + local dist = helper.distance(self._start_pos.x, self._start_pos.y, action.x, action.y) local delta_time = socket.gettime() - self._swipe_start_time local is_swipe = self.style.SWIPE_THRESHOLD <= dist and delta_time <= self.style.SWIPE_TIME @@ -72,7 +77,7 @@ function M.init(self, node, on_swipe_callback) self.node = self:get_node(node) self._swipe_start_time = false - self.start_pos = vmath.vector3(0) + self._start_pos = vmath.vector3(0) self.click_zone = nil self.on_swipe = Event(on_swipe_callback)