mirror of
https://github.com/Insality/druid
synced 2025-09-27 10:02:19 +02:00
Solve #73 fix scroll drag on stretch/zoom nodes
This commit is contained in:
@@ -186,6 +186,8 @@ function Drag.init(self, node, on_drag_callback)
|
||||
self.on_drag_start = Event()
|
||||
self.on_drag = Event(on_drag_callback)
|
||||
self.on_drag_end = Event()
|
||||
|
||||
self:on_window_resized()
|
||||
end
|
||||
|
||||
|
||||
@@ -199,6 +201,13 @@ function Drag.on_late_init(self)
|
||||
end
|
||||
|
||||
|
||||
function Drag.on_window_resized(self)
|
||||
local x_koef, y_koef = helper.get_screen_aspect_koef()
|
||||
self._x_koef = x_koef
|
||||
self._y_koef = y_koef
|
||||
end
|
||||
|
||||
|
||||
function Drag.on_input_interrupt(self)
|
||||
if self.is_drag or self.is_touch then
|
||||
end_touch(self)
|
||||
@@ -258,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.dy = touch_modified.y - self.y
|
||||
self.dx = (touch_modified.x - self.x) * self._x_koef
|
||||
self.dy = (touch_modified.y - self.y) * self._y_koef
|
||||
end
|
||||
|
||||
if touch_modified then
|
||||
|
@@ -30,7 +30,6 @@ function Layout:init(node, mode, on_size_changed_callback)
|
||||
self._min_size = nil
|
||||
self._max_size = nil
|
||||
|
||||
self.window_size = vmath.vector3(gui.get_width(), gui.get_height(), 0)
|
||||
self.mode = mode or const.LAYOUT_MODE.FIT
|
||||
|
||||
self.on_size_changed = Event(on_size_changed_callback)
|
||||
@@ -40,12 +39,7 @@ end
|
||||
|
||||
|
||||
function Layout:on_window_resized()
|
||||
local window_x, window_y = window.get_size()
|
||||
local stretch_x = window_x / self.window_size.x
|
||||
local stretch_y = window_y / self.window_size.y
|
||||
|
||||
local x_koef = stretch_x / math.min(stretch_x, stretch_y)
|
||||
local y_koef = stretch_y / math.min(stretch_x, stretch_y)
|
||||
local x_koef, y_koef = helper.get_screen_aspect_koef()
|
||||
|
||||
local new_size = vmath.vector3(self.origin_size)
|
||||
if self.mode == const.LAYOUT_MODE.STRETCH_X or self.mode == const.LAYOUT_MODE.STRETCH then
|
||||
@@ -65,8 +59,8 @@ function Layout:on_window_resized()
|
||||
|
||||
gui.set_size(self.node, new_size)
|
||||
|
||||
self.position.x = self.origin_position.x * x_koef + self.origin_position.x * (1 - x_koef) * self.pivot.x * 2
|
||||
self.position.y = self.origin_position.y * y_koef + self.origin_position.y * (1 - y_koef) * self.pivot.y * 2
|
||||
self.position.x = self.origin_position.x + self.origin_position.x * (1 - x_koef) * self.pivot.x * 2
|
||||
self.position.y = self.origin_position.y + self.origin_position.y * (1 - y_koef) * self.pivot.y * 2
|
||||
gui.set_position(self.node, self.position)
|
||||
|
||||
self.on_size_changed:trigger(self:get_context(), new_size)
|
||||
|
@@ -97,6 +97,15 @@ function M.centrate_nodes(margin, ...)
|
||||
end
|
||||
|
||||
|
||||
function M.get_screen_aspect_koef()
|
||||
local window_x, window_y = window.get_size()
|
||||
local stretch_x = window_x / gui.get_width()
|
||||
local stretch_y = window_y / gui.get_height()
|
||||
return stretch_x / math.min(stretch_x, stretch_y),
|
||||
stretch_y / math.min(stretch_x, stretch_y)
|
||||
end
|
||||
|
||||
|
||||
function M.step(current, target, step)
|
||||
if current < target then
|
||||
return math.min(current + step, target)
|
||||
|
Reference in New Issue
Block a user