From c9f862ac0328cbca0c3cfefcecfae12700dddb2a Mon Sep 17 00:00:00 2001 From: Insality Date: Wed, 15 Jun 2022 10:34:19 +0500 Subject: [PATCH] Solve #188 Add drag component total_x/total_y --- druid/base/drag.lua | 14 +++++++------- druid/helper.lua | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/druid/base/drag.lua b/druid/base/drag.lua index 71281bd..0e8b018 100644 --- a/druid/base/drag.lua +++ b/druid/base/drag.lua @@ -17,10 +17,10 @@ --- Event on drag start callback(self) -- @tfield DruidEvent on_drag_start @{DruidEvent} ---- on drag progress callback(self, dx, dy) +--- on drag progress callback(self, dx, dy, total_x, total_y) -- @tfield DruidEvent on_drag Event @{DruidEvent} ---- Event on drag end callback(self) +--- Event on drag end callback(self, total_x, total_y) -- @tfield DruidEvent on_drag_end @{DruidEvent} --- Is component now touching @@ -70,7 +70,7 @@ end local function end_touch(self) if self.is_drag then - self.on_drag_end:trigger(self:get_context()) + self.on_drag_end:trigger(self:get_context(), self.x - self.touch_start_pos.x, self.y - self.touch_start_pos.y) end self.is_drag = false @@ -96,7 +96,7 @@ local function process_touch(self, touch) if not self.is_drag and distance >= self.style.DRAG_DEADZONE then self.is_drag = true self.on_drag_start:trigger(self:get_context()) - self:set_input_priority(const.PRIORITY_INPUT_MAX) + self:set_input_priority(const.PRIORITY_INPUT_MAX, true) end end @@ -267,8 +267,8 @@ function Drag.on_input(self, action_id, action) local touch_modified = find_touch(action_id, action, self.touch_id) if touch_modified and self.is_drag then - self.dx = (touch_modified.x - self.x) * self._x_koef - self.dy = (touch_modified.y - self.y) * self._y_koef + self.dx = touch_modified.x - self.x + self.dy = touch_modified.y - self.y end if touch_modified then @@ -277,7 +277,7 @@ function Drag.on_input(self, action_id, action) end if self.is_drag then - self.on_drag:trigger(self:get_context(), self.dx, self.dy) + self.on_drag:trigger(self:get_context(), self.dx, self.dy, self.x - self.touch_start_pos.x, self.y - self.touch_start_pos.y) end return self.is_drag diff --git a/druid/helper.lua b/druid/helper.lua index 74eda23..c7849d1 100644 --- a/druid/helper.lua +++ b/druid/helper.lua @@ -8,6 +8,7 @@ local const = require("druid.const") local M = {} + --- Text node or icon node can be nil local function get_text_width(text_node) if text_node then